DeployBMCTask.java
5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.commons.io.FileUtils
* org.apache.commons.io.IOUtils
* org.apache.sling.installer.api.tasks.InstallTask
* org.apache.sling.installer.api.tasks.InstallationContext
* org.apache.sling.installer.api.tasks.ResourceState
* org.apache.sling.installer.api.tasks.TaskResource
* org.apache.sling.installer.api.tasks.TaskResourceGroup
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.bedrock.installer.internal;
import com.adobe.aemds.bedrock.installer.internal.ArtifactType;
import com.adobe.aemds.bedrock.installer.internal.BMCDeployer;
import com.adobe.aemds.bedrock.installer.internal.Utilities;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.sling.installer.api.tasks.InstallTask;
import org.apache.sling.installer.api.tasks.InstallationContext;
import org.apache.sling.installer.api.tasks.ResourceState;
import org.apache.sling.installer.api.tasks.TaskResource;
import org.apache.sling.installer.api.tasks.TaskResourceGroup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DeployBMCTask
extends InstallTask {
private static final String INSTALL_ORDER = "77-";
private final Logger logger;
private final BMCDeployer bmcDeployer;
private final ArtifactType type;
public DeployBMCTask(TaskResourceGroup erl, BMCDeployer bmcDeployer, ArtifactType type) {
super(erl);
this.logger = LoggerFactory.getLogger(this.getClass());
this.bmcDeployer = bmcDeployer;
this.type = type;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void execute(InstallationContext ctx) {
block13 : {
TaskResource tr = this.getResource();
String serviceName = (String)tr.getAttribute("Bedrock-Service-Name");
String osName = (String)tr.getAttribute("Bedrock-Operating-System");
if (serviceName == null) {
this.logger.error("Resource {} has no Bedrock Service name - ignoring.", (Object)tr);
this.getResourceGroup().setFinishState(ResourceState.IGNORED);
return;
}
if (osName != null) {
boolean isSameOS;
this.logger.info("Resource {} has specified OS {} which is " + ((isSameOS = this.bmcDeployer.isCurrentOS(osName)) ? "valid" : "not valid") + " for current OS " + (isSameOS ? "- installing." : "- ignoring."), (Object)tr, (Object)osName);
if (!isSameOS) {
this.getResourceGroup().setFinishState(ResourceState.IGNORED);
return;
}
} else {
this.logger.info("Resource {} does not have any OS specified.", (Object)tr);
}
String nativeDepsFileName = "com.adobe.service." + serviceName + ".nativedeps";
String nativeDepsFileContents = (String)tr.getAttribute("Bedrock-Native-Dependencies");
if (tr.getState() == ResourceState.INSTALL) {
InputStream is = null;
try {
is = tr.getInputStream();
if (is == null) {
this.logger.error("Resource {} does not provide an input stream!", (Object)tr);
this.getResourceGroup().setFinishState(ResourceState.IGNORED);
break block13;
}
this.bmcDeployer.installBMC(serviceName, is, this.type);
ctx.log("Installed BMC {} of type {}", new Object[]{serviceName, this.type});
this.getResourceGroup().setFinishState(ResourceState.INSTALLED);
this.exportNativeDependencies(this.bmcDeployer.getServiceDir(serviceName, ArtifactType.BMC_CONFIG), nativeDepsFileName, nativeDepsFileContents);
}
catch (IOException ioe) {
this.logger.error("Unable to install BMC " + serviceName + "from resource " + (Object)tr, (Throwable)ioe);
this.getResourceGroup().setFinishState(ResourceState.IGNORED);
}
finally {
IOUtils.closeQuietly((InputStream)is);
}
}
this.bmcDeployer.uninstall(serviceName, this.type);
this.getResourceGroup().setFinishState(ResourceState.UNINSTALLED);
try {
this.unexportNativeDependencies(this.bmcDeployer.getServiceDir(serviceName, ArtifactType.BMC_CONFIG), nativeDepsFileName);
}
catch (IOException ioe) {
this.logger.warn("Unable to delete configuration data for " + serviceName + ": " + nativeDepsFileName, (Throwable)ioe);
}
}
}
public String getSortKey() {
return "77-" + this.getResource().getURL();
}
private void exportNativeDependencies(File serviceDataDir, String fileName, String fileContents) throws IOException {
if (!serviceDataDir.exists()) {
FileUtils.forceMkdir((File)serviceDataDir);
}
File serviceConfigFile = new File(serviceDataDir, fileName);
FileUtils.writeStringToFile((File)serviceConfigFile, (String)fileContents);
}
private void unexportNativeDependencies(File serviceDataDir, String fileName) throws IOException {
File serviceConfigFile = new File(serviceDataDir, fileName);
if (serviceConfigFile.exists()) {
FileUtils.forceDelete((File)serviceConfigFile);
}
if (serviceDataDir.listFiles().length == 0) {
Utilities.deleteRecursive(serviceDataDir);
}
}
}