use of org.opentosca.planbuilder.core.plugins.context.Variable in project container by OpenTOSCA.
the class BPELInvokerPluginHandler method handleArtifactReferenceUpload.
public boolean handleArtifactReferenceUpload(final TArtifactReference ref, final BPELPlanContext templateContext, final PropertyVariable serverIp, final PropertyVariable sshUser, final PropertyVariable sshKey, final TNodeTemplate infraTemplate, final Element elementToAppendTo) throws Exception {
LOG.debug("Handling DA " + ref.getReference());
if (Objects.isNull(serverIp)) {
LOG.error("Unable to upload artifact with server IP equal to null.");
return false;
}
/*
* Construct all needed data (paths, url, scripts)
*/
// TODO /home/ec2-user/ or ~ is a huge assumption
// the path to the file on the ubuntu vm being uploaded
final String ubuntuFilePath = "~/" + templateContext.getCSARFileName() + "/" + ref.getReference();
final String ubuntuFilePathVarName = "ubuntuFilePathVar" + templateContext.getIdForNames();
final Variable ubuntuFilePathVar = templateContext.createGlobalStringVariable(ubuntuFilePathVarName, ubuntuFilePath);
// the folder which has to be created on the ubuntu vm
final String ubuntuFolderPathScript = "sleep 1 && mkdir -p " + fileReferenceToFolder(ubuntuFilePath);
final String containerAPIAbsoluteURIXPathQuery = this.bpelFrags.createXPathQueryForURLRemoteFilePath(ref.getReference());
final String containerAPIAbsoluteURIVarName = "containerApiFileURL" + templateContext.getIdForNames();
/*
* create a string variable with a complete URL to the file we want to upload
*/
final Variable containerAPIAbsoluteURIVar = templateContext.createGlobalStringVariable(containerAPIAbsoluteURIVarName, "");
try {
Node assignNode = loadAssignXpathQueryToStringVarFragmentAsNode("assign" + templateContext.getIdForNames(), containerAPIAbsoluteURIXPathQuery, containerAPIAbsoluteURIVar.getVariableName());
assignNode = templateContext.importNode(assignNode);
elementToAppendTo.appendChild(assignNode);
} catch (final IOException e) {
LOG.error("Couldn't read internal file", e);
return false;
} catch (final SAXException e) {
LOG.error("Couldn't parse internal xml file");
return false;
}
// create the folder the file must be uploaded into and upload the file afterwards
final String mkdirScriptVarName = "mkdirScript" + templateContext.getIdForNames();
final Variable mkdirScriptVar = templateContext.createGlobalStringVariable(mkdirScriptVarName, ubuntuFolderPathScript);
final Map<String, Variable> runScriptRequestInputParams = new HashMap<>();
runScriptRequestInputParams.put("Script", mkdirScriptVar);
final List<String> runScriptInputParams = getRunScriptParams(infraTemplate, templateContext.getCsar());
final Map<String, Variable> transferFileRequestInputParams = new HashMap<>();
transferFileRequestInputParams.put("TargetAbsolutePath", ubuntuFilePathVar);
transferFileRequestInputParams.put("SourceURLorLocalPath", containerAPIAbsoluteURIVar);
final List<String> transferFileInputParams = getTransferFileParams(infraTemplate, templateContext.getCsar());
switch(serverIp.getPropertyName()) {
case Properties.OPENTOSCA_DECLARATIVE_PROPERTYNAME_CONTAINERIP:
// create the folder
if (runScriptInputParams.contains(serverIp.getPropertyName())) {
runScriptRequestInputParams.put(serverIp.getPropertyName(), serverIp);
}
this.handle(templateContext, infraTemplate.getId(), true, "runScript", "ContainerManagementInterface", runScriptRequestInputParams, new HashMap<String, Variable>(), elementToAppendTo);
// transfer the file
if (transferFileInputParams.contains(serverIp.getPropertyName())) {
transferFileRequestInputParams.put(serverIp.getPropertyName(), serverIp);
}
this.handle(templateContext, infraTemplate.getId(), true, Interfaces.OPENTOSCA_DECLARATIVE_INTERFACE_OPERATINGSYSTEM_TRANSFERFILE, "ContainerManagementInterface", transferFileRequestInputParams, new HashMap<>(), elementToAppendTo);
break;
case Properties.OPENTOSCA_DECLARATIVE_PROPERTYNAME_VMIP:
case Properties.OPENTOSCA_DECLARATIVE_PROPERTYNAME_RASPBIANIP:
// create the folder
if (runScriptInputParams.contains(Properties.OPENTOSCA_DECLARATIVE_PROPERTYNAME_VMIP)) {
runScriptRequestInputParams.put(Properties.OPENTOSCA_DECLARATIVE_PROPERTYNAME_VMIP, serverIp);
}
if (sshUser != null && runScriptInputParams.contains("VMUserName")) {
runScriptRequestInputParams.put("VMUserName", sshUser);
}
if (sshKey != null && runScriptInputParams.contains("VMPrivateKey")) {
runScriptRequestInputParams.put("VMPrivateKey", sshKey);
}
this.handle(templateContext, infraTemplate.getId(), true, "runScript", Interfaces.OPENTOSCA_DECLARATIVE_INTERFACE_OPERATINGSYSTEM, runScriptRequestInputParams, new HashMap<>(), elementToAppendTo);
// transfer the file
if (transferFileInputParams.contains(Properties.OPENTOSCA_DECLARATIVE_PROPERTYNAME_VMIP)) {
transferFileRequestInputParams.put(Properties.OPENTOSCA_DECLARATIVE_PROPERTYNAME_VMIP, serverIp);
}
if (sshUser != null && transferFileInputParams.contains("VMUserName")) {
transferFileRequestInputParams.put("VMUserName", sshUser);
}
if (sshKey != null && transferFileInputParams.contains("VMPrivateKey")) {
transferFileRequestInputParams.put("VMPrivateKey", sshKey);
}
this.handle(templateContext, infraTemplate.getId(), true, Interfaces.OPENTOSCA_DECLARATIVE_INTERFACE_OPERATINGSYSTEM_TRANSFERFILE, Interfaces.OPENTOSCA_DECLARATIVE_INTERFACE_OPERATINGSYSTEM, transferFileRequestInputParams, new HashMap<>(), elementToAppendTo);
break;
default:
return false;
}
return true;
}
use of org.opentosca.planbuilder.core.plugins.context.Variable in project container by OpenTOSCA.
the class BPELNotifyHandler method handleNotifyPartners.
public boolean handleNotifyPartners(final BPELPlanContext context) throws SAXException, IOException {
final Path xsdFile = this.resHandler.getServiceInvokerXSDFile(context.getIdForNames());
final Path wsdlFile = this.resHandler.getServiceInvokerWSDLFile(xsdFile, context.getIdForNames());
// register wsdls and xsd
final QName invokerPortType = context.registerPortType(this.resHandler.getServiceInvokerPortType(), wsdlFile);
final QName invokerCallbackPortType = context.registerPortType(this.resHandler.getServiceInvokerCallbackPortType(), wsdlFile);
// atleast the xsd should be imported now in the plan
context.registerType(this.resHandler.getServiceInvokerNotifyPartnersMessageXSDType(), xsdFile);
final QName InputMessageId = context.importQName(this.resHandler.getServiceInvokerNotifyPartnersMessageXSDType());
final String InputMessagePartName = this.resHandler.getServiceInvokerNotifyPartnersMessagePart();
// generate partnerlink from the two porttypes
final String partnerLinkTypeName = invokerPortType.getLocalPart() + "PLT" + context.getIdForNames();
context.addPartnerLinkType(partnerLinkTypeName, "Requester", invokerCallbackPortType, "Requestee", invokerPortType);
final String partnerLinkName = invokerPortType.getLocalPart() + "PL" + context.getIdForNames();
context.addPartnerLinkToTemplateScope(partnerLinkName, partnerLinkTypeName, "Requester", "Requestee", true);
final Map<String, Variable> params = new HashMap<>();
final String myPartnerId = getMyPartnerId(context);
final Variable myPartnerIdVar = context.createGlobalStringVariable("myPartnerId", myPartnerId);
params.put("SendingPartner", myPartnerIdVar);
// register request and response message
final String requestVariableName = invokerPortType.getLocalPart() + InputMessageId.getLocalPart() + "Request" + context.getIdForNames();
context.addVariable(requestVariableName, BPELPlan.VariableType.MESSAGE, InputMessageId);
// setup a correlation set for the messages
String correlationSetName = null;
String correlationPropertyName = null;
if (isNotifcationCorrelationSet(context)) {
correlationPropertyName = getNotifcationProperty(context);
correlationSetName = getGloblaNotifyCorrelationSetName(context);
} else {
correlationPropertyName = addNotifyCorrelationProperty(context);
Collection<String> propertyNames = Lists.newArrayList();
propertyNames.add(correlationPropertyName);
correlationSetName = addNotifyCorrelationSet(context, propertyNames);
}
final String query = "//*[local-name()=\"PlanCorrelationID\" and namespace-uri()=\"http://siserver.org/schema\"]";
// "/" + InputMessageId.getPrefix() + ":" + "MessageID"
context.addPropertyAlias(correlationPropertyName, InputMessageId, InputMessagePartName, query);
// register correlationsets
// fetch serviceInstanceId
final String serviceInstanceIdVarName = context.getServiceInstanceURLVarName();
if (serviceInstanceIdVarName == null) {
return false;
}
// add request message assign to prov phase scope
Node assignNode = null;
// if (context.getPlanType().equals(PlanType.TERMINATE)) {
// TODO FIXME, right now the termination plans are able to call operations of node Instances for
// that the instanceID can be null at runtime e.g. when removing a DockerContainer the operation
// removeContainer of the DockerEngine is called for that the nodeInstanceId is not fetched at the
// time
// of removal
// TIP this issue theoretically happens only with the "container deployment pattern" were a hosting
// node has the operations needed to manage a component => different termination handling for such
// components is needed
assignNode = this.resHandler.generateNotifyPlanRequestMessageInitAssignTemplate(context.getCSARFileName(), context.getServiceTemplateId(), String.valueOf(System.currentTimeMillis()), requestVariableName, InputMessagePartName, params);
assignNode = context.importNode(assignNode);
Node addressingCopyInit = this.resHandler.generateAddressingInitAsNode(requestVariableName);
addressingCopyInit = context.importNode(addressingCopyInit);
assignNode.appendChild(addressingCopyInit);
Node addressingCopyNode = this.resHandler.generateAddressingCopyAsNode(partnerLinkName, requestVariableName);
addressingCopyNode = context.importNode(addressingCopyNode);
assignNode.appendChild(addressingCopyNode);
Node messageIdInit = this.resHandler.generateMessageIdInitAsNode(requestVariableName, InputMessagePartName, "notifyPartners_" + context.getServiceTemplateId().getLocalPart());
messageIdInit = context.importNode(messageIdInit);
assignNode.appendChild(messageIdInit);
context.getProvisioningPhaseElement().appendChild(assignNode);
this.appendLOGMessageActivity(context, "Executing notify all partners", context.getProvisioningPhaseElement());
// invoke service invoker
// add invoke
Node invokeNode = this.resHandler.generateInvokeAsNode("sendNotifyPartners_" + requestVariableName, partnerLinkName, "notifyPartners", invokerPortType, requestVariableName);
BPELInvokeOperationHandler.LOG.debug("Trying to ImportNode: " + invokeNode.toString());
invokeNode = context.importNode(invokeNode);
Node correlationSetsNode = this.resHandler.generateCorrelationSetsAsNode(correlationSetName, true);
correlationSetsNode = context.importNode(correlationSetsNode);
invokeNode.appendChild(correlationSetsNode);
context.getProvisioningPhaseElement().appendChild(invokeNode);
return true;
}
use of org.opentosca.planbuilder.core.plugins.context.Variable in project container by OpenTOSCA.
the class SituationPluginUtils method appendCompensationWCETCalculation.
public static Variable appendCompensationWCETCalculation(BPELPlanContext context, TNodeTemplate nodeTemplate, Collection<TNodeTemplate> usedNodes) {
Collection<TPolicy> operationExecutionTimePolicies = SituationPluginUtils.getOperationExecutionTimePolicies(usedNodes);
Map<TOperation, TOperation> usedOperations = context.getUsedOperations();
// we sum up the compensation operations' wcet, as if something happens we should be able to
// compensate in time and we assume that scope only have sequences of operations
int wcet = 0;
for (TOperation op : usedOperations.values()) {
if (op != null) {
for (TPolicy pol : operationExecutionTimePolicies) {
// &&
if (ModelUtils.asMap(pol.getProperties()).get("OperationName").equals(op.getName())) {
String wcetProp = ModelUtils.asMap(pol.getProperties()).get("WorstCaseExecutionTime");
if (wcetProp != null) {
wcet += Integer.valueOf(wcetProp);
}
}
}
}
}
Variable wcetVariable = context.createGlobalStringVariable(nodeTemplate.getId() + "_WCET_" + System.currentTimeMillis(), String.valueOf(wcet));
return wcetVariable;
}
use of org.opentosca.planbuilder.core.plugins.context.Variable in project container by OpenTOSCA.
the class SituationPluginUtils method getSituationMinActiveTimeEvaluationQuery.
public static String getSituationMinActiveTimeEvaluationQuery(Map<TPolicy, Variable> situationPolicies2DataVariables) {
StringBuilder xpathQuery = new StringBuilder("min((");
for (Variable situationDataVar : situationPolicies2DataVariables.values()) {
xpathQuery.append("number($").append(situationDataVar.getVariableName()).append("/*[local-name()='EventTime']), ");
}
xpathQuery = new StringBuilder(xpathQuery.substring(0, xpathQuery.length() - ", ".length()));
xpathQuery.append("))");
return xpathQuery.toString();
}
use of org.opentosca.planbuilder.core.plugins.context.Variable in project container by OpenTOSCA.
the class SituationPluginUtils method getSituationDataEvaluationQuery.
public static String getSituationDataEvaluationQuery(Map<TPolicy, Variable> situationPolicies2DataVariables) {
StringBuilder xpathQuery = new StringBuilder();
for (Variable situationDataVar : situationPolicies2DataVariables.values()) {
xpathQuery.append("count($").append(situationDataVar.getVariableName()).append("/*[local-name()='Active' and text()='true']) = 1 and ");
}
xpathQuery = new StringBuilder(xpathQuery.substring(0, xpathQuery.length() - " and ".length()));
return xpathQuery.toString();
}
Aggregations