use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project winery by eclipse.
the class DriverInjection method injectDriver.
public static TTopologyTemplate injectDriver(TTopologyTemplate topologyTemplate) throws Exception {
List<TNodeTemplate> nodeTemplatesWithAbstractDA = DASpecification.getNodeTemplatesWithAbstractDAs(topologyTemplate);
for (TNodeTemplate nodeTemplateWithAbstractDA : nodeTemplatesWithAbstractDA) {
if (nodeTemplateWithAbstractDA.getDeploymentArtifacts() != null) {
List<TDeploymentArtifact> abstractDAsAttachedToNodeTemplate = nodeTemplateWithAbstractDA.getDeploymentArtifacts().stream().filter(da -> DASpecification.getArtifactTypeOfDA(da).getAbstract()).collect(Collectors.toList());
for (TDeploymentArtifact abstractDA : abstractDAsAttachedToNodeTemplate) {
Set<Pair<TRelationshipTemplate, TNodeTemplate>> nodeTemplatesWithConcreteDA = DASpecification.getNodesWithSuitableConcreteDAAndTheDirectlyConnectedNode(nodeTemplateWithAbstractDA, abstractDA, topologyTemplate);
for (Pair<TRelationshipTemplate, TNodeTemplate> pair : nodeTemplatesWithConcreteDA) {
TRelationshipTemplate relationshipTemplate = pair.getLeft();
TNodeTemplate nodeTemplate = pair.getRight();
TDeploymentArtifact concreteDeploymentArtifact = DASpecification.getSuitableConcreteDA(abstractDA, nodeTemplate);
if (concreteDeploymentArtifact != null) {
nodeTemplateWithAbstractDA.getDeploymentArtifacts().add(concreteDeploymentArtifact);
setDriverProperty(relationshipTemplate, concreteDeploymentArtifact);
}
}
// concrete DAs from the delivering Node Template must not be deleted. They are uploaded by the OpenTOSCA Container but not used.
nodeTemplateWithAbstractDA.getDeploymentArtifacts().remove(abstractDA);
}
}
}
return topologyTemplate;
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project container by OpenTOSCA.
the class BPELDockerContainerTypePluginHandler method handleCreate.
@Override
public boolean handleCreate(final BPELPlanContext templateContext) {
if (templateContext.getNodeTemplate() == null) {
BPELDockerContainerTypePluginHandler.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 PropertyVariable containerPortVar = templateContext.getPropertyVariable(nodeTemplate, "ContainerPort");
final PropertyVariable portVar = templateContext.getPropertyVariable(nodeTemplate, "Port");
if (containerPortVar == null | portVar == null) {
BPELDockerContainerTypePluginHandler.LOG.error("Couldn't fetch Property variables ContainerPort or Port");
return false;
}
final Variable portMappingVar = templateContext.createGlobalStringVariable("dockerContainerPortMappings" + System.currentTimeMillis(), "");
try {
Node assignContainerPortsNode = this.planBuilderFragments.createAssignXpathQueryToStringVarFragmentAsNode("assignPortMapping", "concat($" + containerPortVar.getVariableName() + ",',',$" + portVar.getVariableName() + ")", portMappingVar.getVariableName());
assignContainerPortsNode = templateContext.importNode(assignContainerPortsNode);
templateContext.getProvisioningPhaseElement().appendChild(assignContainerPortsNode);
} catch (final IOException | SAXException e) {
LOG.error("Error while assigning container 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 = DockerContainerTypePlugin.getDockerEngineNode(nodeTemplate, templateContext.getCsar());
if (dockerEngineNode == null) {
BPELDockerContainerTypePluginHandler.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");
/* volume data handling */
// <ContainerMountPath>/etc/openmtc/certs</ContainerMountPath>
// <HostMountFiles>/home/ubuntu/ca-smartorchestra.crt</HostMountFiles>
final PropertyVariable containerMountPath = templateContext.getPropertyVariable(nodeTemplate, "ContainerMountPath");
Variable remoteVolumeDataVariable = null;
PropertyVariable hostVolumeDataVariable = null;
Variable vmIpVariable = null;
Variable vmPrivateKeyVariable = null;
if (containerMountPath != null && !PluginUtils.isVariableValueEmpty(containerMountPath)) {
final List<TDeploymentArtifact> volumeDas = fetchVolumeDeploymentArtifacts(nodeTemplate, templateContext.getCsar());
if (!volumeDas.isEmpty()) {
remoteVolumeDataVariable = createRemoteVolumeDataInputVariable(volumeDas, templateContext);
}
hostVolumeDataVariable = templateContext.getPropertyVariable(nodeTemplate, "HostMountFiles");
if (hostVolumeDataVariable != null && !PluginUtils.isVariableValueEmpty(hostVolumeDataVariable)) {
final TNodeTemplate infraNode = findInfrastructureTemplate(templateContext, dockerEngineNode);
vmIpVariable = findVMIP(templateContext, infraNode);
vmPrivateKeyVariable = findPrivateKey(templateContext, infraNode);
}
}
if ((containerImageVar == null || PluginUtils.isVariableValueEmpty(containerImageVar)) && (nodeTemplate.getDeploymentArtifacts() != null && !nodeTemplate.getDeploymentArtifacts().isEmpty())) {
// handle with DA -> construct URL to the DockerImage .zip
final TDeploymentArtifact da = fetchFirstDockerContainerDA(nodeTemplate, templateContext.getCsar());
return handleWithDA(templateContext, dockerEngineNode, da, portMappingVar, dockerEngineUrlVar, sshPortVar, containerIpVar, containerIdVar, fetchEnvironmentVariables(templateContext, nodeTemplate), null, null, containerMountPath, remoteVolumeDataVariable, hostVolumeDataVariable, vmIpVariable, vmPrivateKeyVariable, privilegedModeVar);
} else {
// handle with imageId
return handleWithImageId(templateContext, dockerEngineNode, containerImageVar, portMappingVar, dockerEngineUrlVar, sshPortVar, containerIpVar, containerIdVar, fetchEnvironmentVariables(templateContext, nodeTemplate), containerMountPath, remoteVolumeDataVariable, hostVolumeDataVariable, vmIpVariable, vmPrivateKeyVariable, privilegedModeVar);
}
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project container by OpenTOSCA.
the class ContainerProxy method getPropertiesNode.
/**
* Searches for NodeTypeImplementations and their DeploymentArtifacts as well as their ArtifactTemplates of the
* specified NodeType. If the needed properties are found, they are returned.
*
* @return specified properties as Node
*/
@Nullable
public Node getPropertiesNode(final CsarId csarId, final QName nodeTypeName, final String interfaceName) {
LOG.trace("Searching ArtifactTemplate defining needed properties for Interface [{}] of NodeType [{}] inside Csar {}", interfaceName, nodeTypeName, csarId);
final Csar csar = storageService.findById(csarId);
// FIXME not sure whether that's equivalent!
final TNodeType nodeType;
try {
nodeType = ToscaEngine.resolveNodeTypeReference(csar, nodeTypeName);
} catch (NotFoundException missing) {
LOG.warn("Did not find NodeType requested with csarId {}, nodeTypeName: {}", csarId, nodeTypeName);
return null;
}
final List<TNodeTypeImplementation> nodeTypeImplementations = ToscaEngine.nodeTypeImplementations(csar, nodeType);
LOG.trace("The NodeType [{}] has {} NodeTypeImplementations.", nodeTypeName, nodeTypeImplementations.size());
for (final TNodeTypeImplementation nodeTypeImplementation : nodeTypeImplementations) {
// if there are DAs
final List<TDeploymentArtifact> deploymentArtifacts = nodeTypeImplementation.getDeploymentArtifacts();
if (deploymentArtifacts == null) {
LOG.warn("The NodeTypeImplementation {} has no DeploymentArtifacts.", nodeTypeImplementation.getName());
return null;
}
LOG.trace("The NodeTypeImplementation [{}] has {} DeploymentArtifacts.", nodeTypeImplementation.getName(), deploymentArtifacts.size());
for (final TDeploymentArtifact da : deploymentArtifacts) {
LOG.trace("- {}", da.getName());
LOG.trace("Searching for ArtifactTemplates.");
final QName artifactRef = da.getArtifactRef();
if (artifactRef == null) {
LOG.debug("No ArtifactTemplate for DA: {} found. Skipping DA.", da.getName());
continue;
}
LOG.trace("ArtifactTemplate for DA [{}] found: {}. Getting the properties of it.", da.getName(), artifactRef);
final Document properties = ToscaEngine.getArtifactTemplateProperties(csar, artifactRef);
if (properties == null) {
LOG.debug("ArtifactTemplate : {} has no specified properties. Skipping DA", artifactRef);
continue;
}
LOG.trace("Properties of ArtifactTemplate: {} found.", artifactRef);
LOG.trace("Getting the {} elements if existing.", INTERFACES_PROPERTIES_NAME);
// get ApplicationInterfacesProperties
final NodeList appPropsList = properties.getElementsByTagNameNS(NAMESPACE, INTERFACES_PROPERTIES_NAME);
LOG.trace("{} {} elements found.", appPropsList.getLength(), INTERFACES_PROPERTIES_NAME);
boolean hostEndpointSpecified = false;
boolean portSpecified = false;
boolean invocationTypeSpecified = false;
boolean interfaceFound = false;
Node propNode = null;
for (int i = 0; i < appPropsList.getLength(); i++) {
hostEndpointSpecified = false;
portSpecified = false;
invocationTypeSpecified = false;
interfaceFound = false;
LOG.debug("Check if information are specified for the correct Interface.");
propNode = appPropsList.item(i);
// get properties like endpoint or invocationType
final NodeList appProps = propNode.getChildNodes();
for (int i2 = 0; i2 < appProps.getLength(); i2++) {
final Node addProp = appProps.item(i2);
if (addProp.getNodeType() == Node.ELEMENT_NODE) {
if (addProp.getLocalName().equals(RELATIVE_ENDPOINT)) {
LOG.trace("Endpoint property found.");
hostEndpointSpecified = true;
} else if (addProp.getLocalName().equals(PORT)) {
LOG.trace("Port property found.");
portSpecified = true;
} else if (addProp.getLocalName().equals(INVOCATION_TYPE)) {
LOG.trace("InvocationType property found.");
invocationTypeSpecified = true;
} else if (addProp.getLocalName().equals(INTERFACE_INFORMATIONS)) {
// check if interface matches
final NodeList appInvInterfaceInfo = ((Element) addProp).getElementsByTagNameNS(NAMESPACE, INTERFACE_INFORMATION);
LOG.trace("{} for {} Interfaces found.", INTERFACE_INFORMATION, appInvInterfaceInfo.getLength());
for (int i3 = 0; i3 < appInvInterfaceInfo.getLength(); i3++) {
final String interfName = appInvInterfaceInfo.item(i3).getAttributes().getNamedItem("name").getNodeValue();
if (interfName.equals(interfaceName)) {
interfaceFound = true;
LOG.trace("Properties for interface: {} found.", interfaceName);
}
}
}
}
}
}
if (hostEndpointSpecified && portSpecified && invocationTypeSpecified && interfaceFound) {
LOG.debug("Properties with all needed information(Endpoint & InvocationType) for interface: " + interfaceName + " of NodeType: " + nodeTypeName + " inside CSAR: " + csarId + " found!");
return propNode;
}
}
}
LOG.debug("No ArtifactTemplate with needed properties for interface: " + interfaceName + " of NodeType: " + nodeTypeName + " inside CSAR: " + csarId + " found!");
return null;
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project container by OpenTOSCA.
the class BPELScopeBuilder method createOperationChain.
/**
* Creates a complete ProvisioningChain for the given NodeTemplate
*
* @param nodeTemplate an TNodeTemplate to create a ProvisioningChain for
* @return a complete ProvisioningChain
*/
public OperationChain createOperationChain(BPELPlanContext context, final TNodeTemplate nodeTemplate, final List<String> operationNames) {
// get nodetype implementations
final Collection<TNodeTypeImplementation> nodeTypeImpls = ModelUtils.findNodeTypeImplementation(nodeTemplate, context.getCsar());
if (nodeTypeImpls.isEmpty()) {
LOG.warn("No implementations available for NodeTemplate {} , can't generate Provisioning logic", nodeTemplate.getId());
return null;
}
final OperationChain chain = new OperationChain(nodeTemplate);
// calculate infrastructure nodes
final List<TNodeTemplate> infraNodes = new ArrayList<>();
ModelUtils.getInfrastructureNodes(nodeTemplate, infraNodes, context.getCsar());
// we'll add here a dummy infra node, representing the management
// infrastructure of the tosca engine (WAR IA's implementing tosca
// operation,..)
infraNodes.add(new TOSCAManagementInfrastructureNodeTemplate());
// check for IA Plugins
final List<IPlanBuilderPrePhaseIAPlugin<?>> iaPlugins = pluginRegistry.getIaPlugins();
final List<IPlanBuilderPrePhaseIAPlugin<BPELPlanContext>> iaPlugins2 = Lists.newArrayList();
iaPlugins.forEach(x -> iaPlugins2.add((IPlanBuilderPrePhaseIAPlugin<BPELPlanContext>) x));
LOG.debug("Calculating best IA candidates for nodeTemplate {} ", nodeTemplate.getId());
// calculate nodeImpl candidates where all IAs of each can be
// provisioned
calculateBestImplementationIACandidates(context, nodeTypeImpls, iaPlugins2, infraNodes, chain);
for (final IANodeTypeImplCandidate wrapper : chain.iaCandidates) {
final int length = wrapper.ias.size();
for (int i = 0; i < length; i++) {
final TImplementationArtifact ia = wrapper.ias.get(i);
final TNodeTemplate infraNode = wrapper.infraNodes.get(i);
final IPlanBuilderPlugin plugin = wrapper.plugins.get(i);
LOG.debug("Found IA {} for deployment on the InfraNode {} with the Plugin {}", ia.getName(), infraNode.getId(), plugin.getID());
}
}
// check for DA Plugins
final List<IPlanBuilderPrePhaseDAPlugin<?>> daPlugins = pluginRegistry.getDaPlugins();
final List<IPlanBuilderPrePhaseDAPlugin<BPELPlanContext>> daPlugins2 = Lists.newArrayList();
daPlugins.forEach(x -> daPlugins2.add((IPlanBuilderPrePhaseDAPlugin<BPELPlanContext>) x));
// calculate nodeImpl candidates where all DAs of each can be
// provisioned
calculateBestImplementationDACandidates(context, nodeTemplate, nodeTypeImpls, daPlugins2, infraNodes, chain);
for (final DANodeTypeImplCandidate wrapper : chain.daCandidates) {
final int length = wrapper.das.size();
for (int i = 0; i < length; i++) {
final TDeploymentArtifact da = wrapper.das.get(i);
final TNodeTemplate infraNode = wrapper.infraNodes.get(i);
final IPlanBuilderPlugin plugin = wrapper.plugins.get(i);
LOG.debug("Found DA {} for deployment on the InfraNode {} with the Plugin {}", da.getName(), infraNode.getId(), plugin.getID());
}
}
// filter for nodeTypeImpl Candidates where both DAs and IAs can
// be provisioned
filterIncompatibleIADACandidates(chain);
// check for prov plugins
final List<IPlanBuilderProvPhaseOperationPlugin<?>> provPlugins = pluginRegistry.getProvPlugins();
// search for prov plugins according to the chosen IA provisionings in
// the chain
calculateProvPlugins(chain, provPlugins, context.getCsar());
// filter ia and da candidates where the operations can't be executed
filterIADACandidates(chain);
// order provisioning candidates
reorderProvCandidates(chain);
// TODO consistency plugins
// select provisioning
selectProvisioning(chain, operationNames);
return chain;
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project container by OpenTOSCA.
the class BPELScopeBuilder method calculateBestImplementationDACandidates.
/**
* Calculates correct mappings of the given NodeTypeImplementations, PrePhaseDAPlugins and InfrastructureNodes for
* the given ProvisioningChain
*
* @param impls a List of NodeTypeImplementations
* @param plugins a List of PrePhaseDAPlugins
* @param infraNodes a List of InfrastructureNode of the NodeTemplate the NodeTypeImplementations belong to
* @param chain a ProvisioningChain where the candidates are added to
*/
private void calculateBestImplementationDACandidates(BPELPlanContext context, final TNodeTemplate nodeTemplate, final Collection<TNodeTypeImplementation> impls, final Collection<IPlanBuilderPrePhaseDAPlugin<BPELPlanContext>> plugins, final Collection<TNodeTemplate> infraNodes, final OperationChain chain) {
final List<DANodeTypeImplCandidate> candidates = new ArrayList<>();
for (final TNodeTypeImplementation impl : impls) {
LOG.debug("Checking DAs of NodeTypeImpl {} and NodeTemplate {}", impl.getName(), nodeTemplate.getId());
final DANodeTypeImplCandidate candidate = new DANodeTypeImplCandidate(nodeTemplate, impl, context.getCsar());
final List<TDeploymentArtifact> effectiveDAs = ModelUtils.calculateEffectiveDAs(nodeTemplate, impl, context.getCsar());
for (final TDeploymentArtifact da : effectiveDAs) {
LOG.debug("Checking whether DA {} can be deployed", da.getName());
for (final TNodeTemplate infraNode : infraNodes) {
LOG.debug("Checking if DA {} can be deployed on InfraNode {}", da.getName(), infraNode.getId());
for (final IPlanBuilderPrePhaseDAPlugin<BPELPlanContext> plugin : plugins) {
LOG.debug("Checking with Plugin {}", plugin.getID());
if (plugin.canHandle(context, da, ModelUtils.findNodeType(infraNode, context.getCsar()))) {
LOG.debug("Adding Plugin, can handle DA on InfraNode");
candidate.add(da, infraNode, plugin);
}
}
}
}
if (candidate.isValid()) {
LOG.debug("Generated Candidate was valid, adding to all Candidates");
candidates.add(candidate);
} else {
LOG.debug("Generated Candidate was invalid, don't add to all Candidates");
}
}
chain.daCandidates = candidates;
}
Aggregations