use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project container by OpenTOSCA.
the class BPELPrePhasePlugin method handleCreate.
@Override
public boolean handleCreate(final BPELPlanContext context, final TNodeTemplate nodeTemplate) {
boolean handle = true;
List<TNodeTypeImplementation> nodeTypeImplementations = context.getCsar().nodeTypeImplementations().stream().filter(implementation -> implementation.getNodeType().equals(nodeTemplate.getType())).collect(Collectors.toList());
for (TNodeTypeImplementation nodeTypeImplementation : nodeTypeImplementations) {
for (final TDeploymentArtifact da : ModelUtils.calculateEffectiveDAs(nodeTemplate, nodeTypeImplementation, context.getCsar())) {
final TNodeTemplate infraNode = getDeployableInfrastructureNode(nodeTemplate, da, context.getCsar());
handle &= this.handler.handle(context, da, infraNode);
}
}
return handle;
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project container by OpenTOSCA.
the class BPELDockerContainerTypePluginHandler method createRemoteVolumeDataInputVariable.
private Variable createRemoteVolumeDataInputVariable(final List<TDeploymentArtifact> das, final BPELPlanContext context) {
final Variable remoteVolumeDataVariable = context.createGlobalStringVariable("remoteVolumeData" + System.currentTimeMillis(), "");
StringBuilder remoteVolumeDataVarAssignQuery = new StringBuilder("concat(");
for (final TDeploymentArtifact da : das) {
for (final TArtifactReference ref : ModelUtils.findArtifactTemplate(da.getArtifactRef(), context.getCsar()).getArtifactReferences()) {
// $input.payload//*[local-name()='instanceDataAPIUrl']
remoteVolumeDataVarAssignQuery.append("$input.payload//*[local-name()='csarEntrypoint'],'/Content/").append(ref.getReference()).append(";',");
}
}
remoteVolumeDataVarAssignQuery = new StringBuilder(remoteVolumeDataVarAssignQuery.substring(0, remoteVolumeDataVarAssignQuery.length() - 1));
remoteVolumeDataVarAssignQuery.append(")");
try {
Node assignContainerEnvNode = this.planBuilderFragments.createAssignXpathQueryToStringVarFragmentAsNode("assignVolumeDataVariable", remoteVolumeDataVarAssignQuery.toString(), remoteVolumeDataVariable.getVariableName());
assignContainerEnvNode = context.importNode(assignContainerEnvNode);
context.getProvisioningPhaseElement().appendChild(assignContainerEnvNode);
} catch (final IOException | SAXException e) {
LOG.error("Error assigning container environment node", e);
}
return remoteVolumeDataVariable;
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project container by OpenTOSCA.
the class BPELOpenMTCDockerContainerTypePluginHandler method handleOpenMTCProtocolAdapter.
public boolean handleOpenMTCProtocolAdapter(final BPELPlanContext templateContext, final TNodeTemplate openMtcGateway, final TNodeTemplate protocolAdapterDeviceNodeTemplate) {
if (templateContext.getNodeTemplate() == null) {
BPELOpenMTCDockerContainerTypePluginHandler.LOG.warn("Appending logic to relationshipTemplate plan is not possible by this plugin");
return false;
}
final TNodeTemplate nodeTemplate = templateContext.getNodeTemplate();
// fetch port binding variables (ContainerPort, Port)
final Variable containerPortVar = templateContext.getPropertyVariable(nodeTemplate, "ContainerPort");
final Variable portVar = templateContext.getPropertyVariable(nodeTemplate, "Port");
if (containerPortVar == null | portVar == null) {
BPELOpenMTCDockerContainerTypePluginHandler.LOG.error("Couldn't fetch Property variables ContainerPort or Port");
return false;
}
/*
* Find Tenant and Instance id properties to be set as ONEM2M_CSE_ID="TenantID~InstanceID" for
* OpenMTC Adapter
*
*/
final Variable tenantIdVar = templateContext.getPropertyVariable(openMtcGateway, "TenantID");
final Variable instanceIdVar = templateContext.getPropertyVariable(openMtcGateway, "InstanceID");
final Variable gatewayContainerIdsVar = templateContext.getPropertyVariable(openMtcGateway, "ContainerID");
final Variable gatewayContainerPortVar = templateContext.getPropertyVariable(openMtcGateway, "Port");
final Variable gatewayContainerIpVar = templateContext.getPropertyVariable(openMtcGateway, "ContainerIP");
final PropertyVariable sensorDeviceId = templateContext.getPropertyVariable(protocolAdapterDeviceNodeTemplate, "DeviceID");
final List<TNodeTemplate> dataChannels = fetchDataChannels(templateContext, protocolAdapterDeviceNodeTemplate);
if (dataChannels.isEmpty()) {
LOG.debug("No Data Channels found");
}
final List<Variable> resourceNames = new ArrayList<>();
for (final TNodeTemplate dataChannel : dataChannels) {
if (templateContext.getPropertyVariable(dataChannel, "ResourceName") != null) {
resourceNames.add(templateContext.getPropertyVariable(dataChannel, "ResourceName"));
}
}
if (tenantIdVar == null | instanceIdVar == null | gatewayContainerIdsVar == null | gatewayContainerPortVar == null | gatewayContainerIpVar == null) {
return false;
}
final Variable portMappingVar = templateContext.createGlobalStringVariable("dockerContainerPortMappings" + System.currentTimeMillis(), "");
final Variable envMappingVar = templateContext.createGlobalStringVariable("dockerContainerEnvironmentMappings" + System.currentTimeMillis(), "");
final Variable deviceMappingVar = templateContext.createGlobalStringVariable("dockerContainerDeviceMappings" + System.currentTimeMillis(), "");
final Variable linksVar = templateContext.createGlobalStringVariable("dockerContainerLinks" + System.currentTimeMillis(), "");
final Variable gatewayContainerIdVar = templateContext.createGlobalStringVariable("dockerContainerIdForLinking" + System.currentTimeMillis(), "");
try {
// assign portmappings
Node assignContainerPortsNode = this.planBuilderFragments.createAssignXpathQueryToStringVarFragmentAsNode("assignPortMapping", "concat($" + containerPortVar.getVariableName() + ",',',$" + portVar.getVariableName() + ")", portMappingVar.getVariableName());
assignContainerPortsNode = templateContext.importNode(assignContainerPortsNode);
templateContext.getProvisioningPhaseElement().appendChild(assignContainerPortsNode);
// read the container ID from within properties
final String queryContainerIdXpath = "substring-before($" + gatewayContainerIdsVar.getVariableName() + ", ';')";
assignContainerPortsNode = this.planBuilderFragments.createAssignXpathQueryToStringVarFragmentAsNode("assignContainerIdForLinking", queryContainerIdXpath, gatewayContainerIdVar.getVariableName());
assignContainerPortsNode = templateContext.importNode(assignContainerPortsNode);
templateContext.getProvisioningPhaseElement().appendChild(assignContainerPortsNode);
String envVarConcatXpathQuery = "concat('EP=http://',$" + gatewayContainerIpVar.getVariableName() + ",':',$" + gatewayContainerPortVar.getVariableName() + ",';','ORIGINATOR_PRE=//smartorchestra.de/',$" + tenantIdVar.getVariableName() + ",'~',$" + instanceIdVar.getVariableName() + ",';LOGGING_LEVEL=INFO;DEVICES=[];SIM=false;";
if (resourceNames.isEmpty()) {
envVarConcatXpathQuery += "')";
} else {
envVarConcatXpathQuery += createDeviceMapping(sensorDeviceId, resourceNames) + "')";
}
// assign environment variable mappings
assignContainerPortsNode = this.planBuilderFragments.createAssignXpathQueryToStringVarFragmentAsNode("assignEnvironmentVariables", envVarConcatXpathQuery, envMappingVar.getVariableName());
assignContainerPortsNode = templateContext.importNode(assignContainerPortsNode);
templateContext.getProvisioningPhaseElement().appendChild(assignContainerPortsNode);
final String deviceMappingConcatXpathQuery = "concat('/dev/ttyACM0','=/dev/ttyAMA0')";
assignContainerPortsNode = this.planBuilderFragments.createAssignXpathQueryToStringVarFragmentAsNode("assignDevices", deviceMappingConcatXpathQuery, deviceMappingVar.getVariableName());
assignContainerPortsNode = templateContext.importNode(assignContainerPortsNode);
templateContext.getProvisioningPhaseElement().appendChild(assignContainerPortsNode);
final String linksConcatXpathQuery = "concat($" + gatewayContainerIdVar.getVariableName() + ",'')";
assignContainerPortsNode = this.planBuilderFragments.createAssignXpathQueryToStringVarFragmentAsNode("assignLinks", linksConcatXpathQuery, linksVar.getVariableName());
assignContainerPortsNode = templateContext.importNode(assignContainerPortsNode);
templateContext.getProvisioningPhaseElement().appendChild(assignContainerPortsNode);
} catch (final IOException | SAXException e) {
LOG.error("Error while assigning links.", e);
}
// fetch (optional) SSHPort variable
final Variable sshPortVar = templateContext.getPropertyVariable(nodeTemplate, "SSHPort");
// fetch (optional) ContainerIP variable
final Variable containerIpVar = templateContext.getPropertyVariable(nodeTemplate, "ContainerIP");
// fetch (optional) ContainerID variable
final Variable containerIdVar = templateContext.getPropertyVariable(nodeTemplate, "ContainerID");
// fetch (optional) PrivilegedMode variable
final PropertyVariable privilegedModeVar = templateContext.getPropertyVariable(nodeTemplate, "PrivilegedMode");
// fetch DockerEngine
final TNodeTemplate dockerEngineNode = BPELDockerContainerTypePlugin.getDockerEngineNode(nodeTemplate, templateContext.getCsar());
if (dockerEngineNode == null) {
BPELOpenMTCDockerContainerTypePluginHandler.LOG.error("Couldn't fetch DockerEngineNode to install given DockerContainer NodeTemplate");
return false;
}
// fetch the DockerIp
final Variable dockerEngineUrlVar = templateContext.getPropertyVariable(dockerEngineNode, "DockerEngineURL");
// determine whether we work with an ImageId or a zipped DockerContainer
final PropertyVariable containerImageVar = templateContext.getPropertyVariable(nodeTemplate, "ImageID");
if (containerImageVar == null || PluginUtils.isVariableValueEmpty(containerImageVar)) {
// handle with DA -> construct URL to the DockerImage .zip
final TDeploymentArtifact da = BPELDockerContainerTypePlugin.fetchFirstDockerContainerDA(nodeTemplate, templateContext.getCsar());
return handleWithDA(templateContext, dockerEngineNode, da, portMappingVar, dockerEngineUrlVar, sshPortVar, containerIpVar, containerIdVar, envMappingVar, linksVar, deviceMappingVar, privilegedModeVar);
}
return false;
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project container by OpenTOSCA.
the class BPELOpenMTCDockerContainerTypePluginHandler method handleOpenMTCGateway.
public boolean handleOpenMTCGateway(final BPELPlanContext templateContext, final TNodeTemplate backendNodeTemplate) {
if (templateContext.getNodeTemplate() == null) {
BPELOpenMTCDockerContainerTypePluginHandler.LOG.warn("Appending logic to relationshipTemplate plan is not possible by this plugin");
return false;
}
final TNodeTemplate nodeTemplate = templateContext.getNodeTemplate();
// fetch port binding variables (ContainerPort, Port)
final Variable containerPortVar = templateContext.getPropertyVariable(nodeTemplate, "ContainerPort");
final Variable portVar = templateContext.getPropertyVariable(nodeTemplate, "Port");
if (containerPortVar == null | portVar == null) {
BPELOpenMTCDockerContainerTypePluginHandler.LOG.error("Couldn't fetch Property variables ContainerPort or Port");
return false;
}
/*
* Find Tenant and Instance id properties to be set as ONEM2M_CSE_ID="TenantID~InstanceID" for
* OpenMTC Gateway
*
*/
final Variable tenantIdVar = templateContext.getPropertyVariable(nodeTemplate, "TenantID");
final Variable instanceIdVar = templateContext.getPropertyVariable(nodeTemplate, "InstanceID");
final Variable onem2mspIdVar = templateContext.getPropertyVariable(nodeTemplate, "ONEM2MSPID");
if (tenantIdVar == null | instanceIdVar == null | onem2mspIdVar == null) {
return false;
}
/*
* Fetch own external IP
*/
Variable ownIp = null;
for (final TNodeTemplate infraNode : templateContext.getInfrastructureNodes()) {
for (final String serverIpName : org.opentosca.container.core.convention.Utils.getSupportedVirtualMachineIPPropertyNames()) {
ownIp = templateContext.getPropertyVariable(infraNode, serverIpName);
if (ownIp != null) {
break;
}
}
}
// check if there is a backend
Variable backendIpVar = null;
Variable backendCSEIdVar = null;
if (backendNodeTemplate != null) {
backendIpVar = templateContext.getPropertyVariable(backendNodeTemplate, "Endpoint") != null ? templateContext.getPropertyVariable(backendNodeTemplate, "Endpoint") : templateContext.getPropertyVariable(backendNodeTemplate, "IP");
backendCSEIdVar = templateContext.getPropertyVariable(backendNodeTemplate, "ONEM2MCSEID");
}
final Variable portMappingVar = templateContext.createGlobalStringVariable("dockerContainerPortMappings" + System.currentTimeMillis(), "");
final Variable envMappingVar = templateContext.createGlobalStringVariable("dockerContainerEnvironmentMappings" + System.currentTimeMillis(), "");
try {
// assign portmappings
Node assignContainerPortsNode = this.planBuilderFragments.createAssignXpathQueryToStringVarFragmentAsNode("assignPortMapping", "concat($" + containerPortVar.getVariableName() + ",',',$" + portVar.getVariableName() + ")", portMappingVar.getVariableName());
assignContainerPortsNode = templateContext.importNode(assignContainerPortsNode);
templateContext.getProvisioningPhaseElement().appendChild(assignContainerPortsNode);
String envVarXpathQuery = "concat('ONEM2M_CSE_ID=',$" + tenantIdVar.getVariableName() + ",'~',$" + instanceIdVar.getVariableName() + ",';LOGGING_LEVEL=INFO;ONEM2M_REGISTRATION_DISABLED=false;ONEM2M_SSL_CRT=;ONEM2M_NOTIFICATION_DISABLED=false;ONEM2M_SP_ID=',$" + onem2mspIdVar.getVariableName() + ",';EXTERNAL_IP=',$" + ownIp.getVariableName() + ")";
if (backendNodeTemplate != null) {
envVarXpathQuery = envVarXpathQuery.substring(0, envVarXpathQuery.length() - 1);
envVarXpathQuery += ",';ONEM2M_REMOTE_CSE_POA=',$" + backendIpVar.getVariableName();
envVarXpathQuery += ",';ONEM2M_REMOTE_CSE_ID=',$" + backendCSEIdVar.getVariableName() + ")";
}
// assign environment variable mappings
assignContainerPortsNode = this.planBuilderFragments.createAssignXpathQueryToStringVarFragmentAsNode("assignEnvironmentVariables", envVarXpathQuery, envMappingVar.getVariableName());
assignContainerPortsNode = templateContext.importNode(assignContainerPortsNode);
templateContext.getProvisioningPhaseElement().appendChild(assignContainerPortsNode);
} catch (final IOException | SAXException e) {
LOG.error("Error while assigning ports.", e);
}
// fetch (optional) SSHPort variable
final Variable sshPortVar = templateContext.getPropertyVariable(nodeTemplate, "SSHPort");
// fetch (optional) ContainerIP variable
final Variable containerIpVar = templateContext.getPropertyVariable(nodeTemplate, "ContainerIP");
// fetch (optional) ContainerID variable
final Variable containerIdVar = templateContext.getPropertyVariable(nodeTemplate, "ContainerID");
// fetch (optional) PrivilegedMode variable
final PropertyVariable privilegedModeVar = templateContext.getPropertyVariable(nodeTemplate, "PrivilegedMode");
// fetch DockerEngine
final TNodeTemplate dockerEngineNode = BPELDockerContainerTypePlugin.getDockerEngineNode(nodeTemplate, templateContext.getCsar());
if (dockerEngineNode == null) {
BPELOpenMTCDockerContainerTypePluginHandler.LOG.error("Couldn't fetch DockerEngineNode to install given DockerContainer NodeTemplate");
return false;
}
// fetch the DockerIp
final Variable dockerEngineUrlVar = templateContext.getPropertyVariable(dockerEngineNode, "DockerEngineURL");
// determine whether we work with an ImageId or a zipped DockerContainer
final PropertyVariable containerImageVar = templateContext.getPropertyVariable(nodeTemplate, "ImageID");
if (containerImageVar == null || PluginUtils.isVariableValueEmpty(containerImageVar)) {
// handle with DA -> construct URL to the DockerImage .zip
final TDeploymentArtifact da = BPELDockerContainerTypePlugin.fetchFirstDockerContainerDA(nodeTemplate, templateContext.getCsar());
return handleWithDA(templateContext, dockerEngineNode, da, portMappingVar, dockerEngineUrlVar, sshPortVar, containerIpVar, containerIdVar, envMappingVar, null, null, privilegedModeVar);
}
return false;
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project container by OpenTOSCA.
the class OperationChain method executeDAProvisioning.
/**
* <p>
* Executes the first found DACandidate to provision DA's with the appropiate plugins set in the candidate
* </p>
*
* @param context a TemplatePlanContext which is initialized for either a NodeTemplate or RelationshipTemplate this
* ProvisioningChain belongs to
* @return returns false only when execution of a plugin inside the DACandidate failed, else true. There may be no
* DACandidate available, because there is no need for DA's to provision. In this case true is also returned.
*/
public boolean executeDAProvisioning(final BPELPlanContext context) {
boolean check = true;
if (!this.daCandidates.isEmpty()) {
final DANodeTypeImplCandidate daCandidate = this.daCandidates.get(this.selectedCandidateSet);
for (int index = 0; index < daCandidate.das.size(); index++) {
final TDeploymentArtifact da = daCandidate.das.get(index);
final TNodeTemplate infraNode = daCandidate.infraNodes.get(index);
final IPlanBuilderPrePhaseDAPlugin plugin = daCandidate.plugins.get(index);
check &= plugin.handle(context, da, infraNode);
}
}
return check;
}
Aggregations