Skip to content

Commit

Permalink
Fix issues related to Docker container scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
wederbn committed Nov 15, 2024
1 parent 22fb003 commit 4e15df9
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN rm /dev/random && ln -s /dev/urandom /dev/random
WORKDIR /tmp/opentosca/container
COPY . /tmp/opentosca/container

RUN apt-get update && apt-get -y install --no-install-recommends unzip=6.0-26ubuntu3
RUN apt-get update && apt-get -y install --no-install-recommends unzip
RUN mvn package -DskipTests=true -Dmaven.javadoc.skip=true -B \
&& mkdir /tmp/build \
&& unzip /tmp/opentosca/container/org.opentosca.container.war/target/OpenTOSCA-container.war -d /tmp/build/container
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package org.opentosca.bus.management.deployment.plugin.tomcat;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -319,7 +327,22 @@ private File getWarFile(final URL warURL) {
// store WAR artifact as temporary file
final File tempFile = File.createTempFile("Artifact", ".war");
tempFile.deleteOnExit();
FileUtils.copyURLToFile(warURL, tempFile);

URLConnection urlConn = warURL.openConnection();
urlConn.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
urlConn.setRequestProperty("Accept-Encoding", "gzip, deflate");
urlConn.setRequestProperty("Accept-Language", "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7");
urlConn.setRequestProperty("Accept-Charset", "UTF-8");
InputStream stream = urlConn.getInputStream();
OutputStream os = new FileOutputStream(tempFile);
byte[] buffer = new byte[4096];
int len;
while ((len = stream.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
os.close();
stream.close();

return tempFile;
} catch (final IOException e) {
LOG.error("Failed to retrieve WAR-File: {}", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,17 @@ private String createArtifactTypeSpecificCommandString(final TArtifactType artif
if (commandsString.contains("{{") && commandsString.contains("}}")) {
LOG.debug("Replacing the placeholder of the generic command with properties data and/or provided input parameter...");

final Map<String, String> paramsMap;
Map<String, String> paramsMap;
if (params instanceof HashMap) {
paramsMap = (HashMap<String, String>) params;
} else if (params instanceof Document) {
final Document paramsDoc = (Document) params;
paramsMap = MBUtils.docToMap(paramsDoc, true);
paramsMap = new HashMap<>();
try {
paramsMap = MBUtils.docToMap(paramsDoc, true);
} catch (Exception e) {
LOG.error("Error while parsing doc to map!");
}
} else {
paramsMap = new HashMap<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
</packages>
<commands>
<command>chmod +x {TARGET_FILE_PATH}</command>
<command>CAN_SUDO=$(sudo -n uptime 2&gt;&amp;1|grep "load"|wc -l); if [ ${CAN_SUDO} -gt 0 ]; then sudo -E {DA_NAME_PATH_MAP}{INPUT_PARAMETER}{TARGET_FILE_PATH}; else {DA_NAME_PATH_MAP}{INPUT_PARAMETER}{TARGET_FILE_PATH}; fi</command>
<command>CAN_SUDO=$(sudo -n uptime 2&gt;&amp;1|grep "load"|wc -l); if [ ${CAN_SUDO} -gt 0 ]; then sudo -E {DA_NAME_PATH_MAP}{INPUT_PARAMETER} bash {TARGET_FILE_PATH}; else {DA_NAME_PATH_MAP}{INPUT_PARAMETER} bash {TARGET_FILE_PATH}; fi</command>
</commands>
</artifacttype>
</artifacttype>
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ public Exchange invoke(Exchange exchange) {
if (exchange.getIn().getHeader("ParamsMode") != null
&& exchange.getIn().getHeader("ParamsMode").equals("HashMap")) {
LOG.debug("Transforming Document to HashMap...");
final HashMap<String, String> responseMap = MBUtils.docToMap(response, false);
HashMap<String, String> responseMap = new HashMap<>();
try {
responseMap = MBUtils.docToMap(response, false);
} catch (Exception e) {
LOG.error("Error while parsing doc to map!");
}
exchange.getIn().setBody(responseMap);
} else {
exchange.getIn().setBody(response);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# Container Configuration
# Your external IP address, e.g. 192.168.0.131
org.opentosca.container.hostname=localhost
org.opentosca.container.hostname=10.1.42.80
org.opentosca.container.port=1337

# IA Engine Configuration (endpoint and credentials)
org.opentosca.container.engine.ia.plugin.tomcat.url=http://localhost:8090
org.opentosca.container.engine.ia.plugin.tomcat.url=http://10.1.42.80:8090
org.opentosca.container.engine.ia.plugin.tomcat.password=admin
org.opentosca.container.engine.ia.plugin.tomcat.username=admin
org.opentosca.container.engine.ia.plugin.tomcat.java17.url=http://localhost:8093
org.opentosca.container.engine.ia.plugin.tomcat.java17.url=http://10.1.42.80:8091
org.opentosca.container.engine.ia.plugin.tomcat.java17.password=admin
org.opentosca.container.engine.ia.plugin.tomcat.java17.username=admin

# BPEL Plan Engine Configuration (endpoint and credentials)
org.opentosca.container.engine.plan.plugin.bpel.engine=ODE
org.opentosca.container.engine.plan.plugin.bpel.url=http://localhost:9763/ode
org.opentosca.container.engine.plan.plugin.bpel.url=http://10.1.42.80:8092/ode
org.opentosca.container.engine.plan.plugin.bpel.password=
org.opentosca.container.engine.plan.plugin.bpel.username=
org.opentosca.container.engine.plan.plugin.bpel.services.url=http://localhost:9763/ode/processes
org.opentosca.container.engine.plan.plugin.bpel.services.url=http://10.1.42.80:8092/ode/processes

# BPMN Plan Engine Configuration (endpoint and credentials)
org.opentosca.container.engine.plan.plugin.bpmn.engine=Camunda
org.opentosca.container.engine.plan.plugin.bpmn.url=http://localhost:8092/engine-rest
org.opentosca.container.engine.plan.plugin.bpmn.url=http://10.1.42.80:8092/engine-rest
org.opentosca.container.engine.plan.plugin.bpmn.username=admin
org.opentosca.container.engine.plan.plugin.bpmn.password=admin

# Container Mode Repository (winery)
org.opentosca.container.connector.winery.url=http://localhost:8091/winery
org.opentosca.container.connector.winery.url=http://10.1.42.80:8091/winery

# Local MQTT broker
org.opentosca.container.broker.mqtt.port=1883
Expand Down
17 changes: 0 additions & 17 deletions org.opentosca.container.reporting/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -435,23 +435,6 @@
</exclusions>
</dependency>

<dependency>
<groupId>org.opentosca</groupId>
<artifactId>org.opentosca.broker.mqtt</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>


<dependency>
<groupId>org.opentosca</groupId>
<artifactId>org.opentosca.container.war</artifactId>
Expand Down
16 changes: 0 additions & 16 deletions org.opentosca.container.war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -459,22 +459,6 @@
</exclusions>
</dependency>

<dependency>
<groupId>org.opentosca</groupId>
<artifactId>org.opentosca.broker.mqtt</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.opentosca.broker.mqtt.BrokerSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.support.WebApplicationContextUtils;
Expand All @@ -17,18 +16,10 @@ public class Config implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent event) {
LOGGER.info("STARTING APPLICATION CONTEXT CONFIGURATION FOR OPENTOSCA CONTAINER API");
BrokerSupport mqttBroker = WebApplicationContextUtils
.getRequiredWebApplicationContext(event.getServletContext())
.getBean(BrokerSupport.class);
mqttBroker.start();
}

@Override
public void contextDestroyed(ServletContextEvent event) {
LOGGER.info("SHUTTING DOWN APPLICATION CONTEXT");
BrokerSupport mqttBroker = WebApplicationContextUtils
.getRequiredWebApplicationContext(event.getServletContext())
.getBean(BrokerSupport.class);
mqttBroker.stop();
}
}
2 changes: 1 addition & 1 deletion org.opentosca.container.war/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<logger name="org.opentosca" level="DEBUG"/>
<logger name="org.opentosca.container.api.config" level="INFO"/>
<logger name="org.opentosca.container.core.common.uri" level="INFO"/>
<logger name="org.opentosca.planbuilder" level="INFO"/>
<logger name="org.opentosca.planbuilder" level="DEBUG"/>
<logger name="org.opentosca.container.plan.deployment" level="INFO"/>
<logger name="org.opentosca.bus.management" level="DEBUG"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@
<import resource="classpath:/spring/context-control.xml"/>
<import resource="classpath:/spring/context-bus-management-service.xml"/>
<import resource="classpath:/spring/context-bus-application-service.xml"/>
<import resource="classpath:/spring/context-mqtt-broker.xml"/>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
import org.opentosca.container.core.model.ModelUtils;
import org.opentosca.container.core.model.csar.Csar;
import org.opentosca.planbuilder.core.bpel.context.BPELPlanContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;

public class LifecyclePatternBasedHandler extends PatternBasedHandler {
private final static Logger LOG = LoggerFactory.getLogger(LifecyclePatternBasedHandler.class);

public boolean handleCreate(final BPELPlanContext context, final TNodeTemplate nodeTemplate, Element elementToAppendTo) {

Expand Down Expand Up @@ -153,41 +156,54 @@ private Set<TNodeTemplate> filterForNodesInCreation(BPELPlanContext context, Set
}

public boolean isProvisionableByLifecyclePattern(final TNodeTemplate nodeTemplate, Csar csar) {

LOG.debug("Checking if nodeTemplate {} can be handled by lifecycle pattern", nodeTemplate.getId());
if (!hasLifecycleProvisioningMethods(nodeTemplate, csar)) {
LOG.debug("No lifecycle method available...");
return false;
}

Set<TNodeTemplate> nodesForMatching = this.getNodesForMatching(nodeTemplate, csar);
LOG.debug("Number of nodes for matching: {}", nodesForMatching.size());

// Small check if we have to find runScript and transferFile operations
boolean hasScriptImplementation;

// check if the lifecycle operations can be matched against the nodes
TOperation op;
TInterface iface = this.getLifecyclePatternInterface(nodeTemplate, csar);
if (((op = this.getLifecyclePatternInstallMethod(nodeTemplate, csar)) != null)
&& !hasCompleteMatching(nodesForMatching, iface, op)) {
return false;

TOperation op = this.getLifecyclePatternInstallMethod(nodeTemplate, csar);
if (op != null) {
LOG.debug("Found lifecycle install operation, searching for matching...");
if (!hasCompleteMatching(nodesForMatching, iface, op)) {
LOG.debug("No matching for lifecycle install operation...");
return false;
}
}

hasScriptImplementation = this.isImplementedAsScript(iface, nodeTemplate, csar);

if (((op = this.getLifecyclePatternConfigureMethod(nodeTemplate, csar)) != null)
&& !hasCompleteMatching(nodesForMatching, iface, op)) {
return false;
op = this.getLifecyclePatternConfigureMethod(nodeTemplate, csar);
if (op != null) {
LOG.debug("Found lifecycle configure operation, searching for matching...");
if (!hasCompleteMatching(nodesForMatching, iface, op)) {
LOG.debug("No matching for lifecycle configure operation...");
return false;
}
}

hasScriptImplementation |= this.isImplementedAsScript(iface, nodeTemplate, csar);

if (((op = this.getLifecyclePatternStartMethod(nodeTemplate, csar)) != null)
&& !hasCompleteMatching(nodesForMatching, iface, op)) {
LOG.debug("No matching for lifecycle start operation...");
return false;
}

hasScriptImplementation |= this.isImplementedAsScript(iface, nodeTemplate, csar);

LOG.debug("Checking availability of operations to handle scripts required: {}", hasScriptImplementation);
if (hasScriptImplementation) {
LOG.debug("Searching for run script and transfer file operations...");
return this.checkForRunScriptAndTransferFile(nodeTemplate, csar);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
import org.opentosca.planbuilder.core.plugins.context.PropertyVariable;
import org.opentosca.planbuilder.core.plugins.context.Variable;
import org.opentosca.planbuilder.provphase.plugin.invoker.bpel.BPELInvokerPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;

public abstract class PatternBasedHandler {
private final static Logger LOG = LoggerFactory.getLogger(PatternBasedHandler.class);

protected static final BPELInvokerPlugin invoker = new BPELInvokerPlugin();

Expand Down Expand Up @@ -142,15 +145,20 @@ protected boolean hasCompleteMatching(final Collection<TNodeTemplate> nodesForMa
final TInterface ifaceToMatch,
final TOperation operationToMatch) {

LOG.debug("Searching for matching for operation: {}", operationToMatch.getName());

final OperationMatching matching =
createPropertyToParameterMatching(nodesForMatching, ifaceToMatch, operationToMatch);

int inputParamSize = 0;

if (operationToMatch.getInputParameters() != null) {
inputParamSize = operationToMatch.getInputParameters().size();
inputParamSize = operationToMatch.getInputParameters().stream().filter(TParameter::getRequired).toList().size();
}

LOG.debug("Required input parameters: {}", inputParamSize);
LOG.debug("Matched input parameters: {}", matching.inputMatching.size());
LOG.debug("Matching? {}", matching.inputMatching.size() == inputParamSize);
return matching.inputMatching.size() == inputParamSize;
}

Expand Down
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>maven.restlet.org</id>
<name>maven.restlet.org</name>
<url>https://maven.restlet.talend.com</url>
</repository>
<repository>
<name>JCenter Public Repository</name>
<id>jcenter</id>
Expand All @@ -57,7 +62,6 @@
</repositories>

<modules>
<module>org.opentosca.broker.mqtt</module>
<module>org.opentosca.bus</module>
<module>org.opentosca.container.control</module>
<module>org.opentosca.container.core</module>
Expand Down

0 comments on commit 4e15df9

Please sign in to comment.