BMCDeployer.java
5.06 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
128
129
130
131
132
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemds.bedrock.CoreConfigService
* com.adobe.aemds.bedrock.OS
* com.adobe.aemds.bedrock.internal.OSGiUtils
* com.adobe.aemds.bedrock.internal.Utilities
* com.adobe.service.ConnectionFactory
* javax.transaction.SystemException
* javax.transaction.Transaction
* org.apache.commons.io.FileUtils
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.bedrock.installer.internal;
import com.adobe.aemds.bedrock.CoreConfigService;
import com.adobe.aemds.bedrock.OS;
import com.adobe.aemds.bedrock.installer.internal.ArtifactType;
import com.adobe.aemds.bedrock.installer.internal.Utilities;
import com.adobe.aemds.bedrock.internal.OSGiUtils;
import com.adobe.service.ConnectionFactory;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import javax.naming.NameNotFoundException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BMCDeployer {
private final Logger logger;
private CoreConfigService configService;
public BMCDeployer() {
this.logger = LoggerFactory.getLogger(this.getClass());
}
public void installBMC(String serviceName, InputStream is, ArtifactType type) throws IOException {
this.uninstall(serviceName, type);
File dir = this.getServiceDir(serviceName, type);
if (!dir.exists()) {
FileUtils.forceMkdir((File)dir);
}
Utilities.unpackResources(is, dir, this.shouldSetSharedBit(type));
}
public void uninstall(String serviceName, ArtifactType type) {
this.stopService(serviceName);
File dir = this.getServiceDir(serviceName, type);
if (dir.exists()) {
Utilities.deleteRecursive(dir);
this.logger.debug("Deleted directory {} upon uninstallation of service {}", (Object)dir, (Object)serviceName);
}
}
public File getServiceDir(String serviceName, ArtifactType artifactType) {
switch (artifactType) {
case BMC_NATIVE: {
return new File(this.configService.getServerNativeDir(), serviceName);
}
case BMC_CONFIG: {
return new File(this.configService.getServerDataDir(), serviceName);
}
}
throw new IllegalArgumentException("ArtifactType " + (Object)((Object)artifactType) + " is not supported");
}
public boolean isCurrentOS(String osName) {
return OS.fromName((String)osName) == OS.getCurrent();
}
public void setConfigService(CoreConfigService configService) {
this.configService = configService;
}
private void stopService(String serviceName) {
this.logger.info("Stopping service {}", (Object)serviceName);
ConnectionFactory cf = null;
try {
cf = com.adobe.aemds.bedrock.internal.Utilities.serviceLookup((String)serviceName);
}
catch (NameNotFoundException nnfe) {
this.logger.info("Service {} not registered, nothing to stop.", (Object)serviceName);
this.logger.debug("Unable to look up connection factory for service {}, any running processes might not be terminated during uninstallation. Caused by:", (Object)serviceName, (Object)nnfe);
}
if (cf != null) {
this.logger.info("Found connection factory {} for service {}, shutting down any running processes", (Object)cf, (Object)serviceName);
Transaction tx = null;
try {
tx = OSGiUtils.getTransactionManager().getTransaction();
if (tx == null) {
OSGiUtils.getTransactionManager().begin();
}
try {
cf.resetProcesses();
}
catch (AssertionError ae) {
this.logger.debug("Ignoring an assertion error thrown by resetProcesses() while stopping service {}", (Object)serviceName, (Object)ae);
}
OSGiUtils.getTransactionManager().commit();
}
catch (Exception e) {
this.logger.warn("An exception occurred while stopping service {}, any running processes might not have been terminated", (Object)serviceName, (Object)e);
try {
if (tx != null) {
OSGiUtils.getTransactionManager().rollback();
}
}
catch (SystemException se) {
this.logger.debug("An exception occurred during transaction rollback while stopping service {}, any running processes might not have been terminated", (Object)serviceName, (Object)se);
}
}
}
}
private boolean isHP() {
return System.getProperty("os.name").toLowerCase().startsWith("hp");
}
private boolean shouldSetSharedBit(ArtifactType type) {
if (ArtifactType.BMC_NATIVE == type) {
return this.isHP();
}
return false;
}
}