use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.
the class InterfaceParser method parseInterfaceDefinition.
private Interface parseInterfaceDefinition(MappingNode node, ParsingContextExecution context) {
Interface interfaz = new Interface();
Map<String, Operation> operations = Maps.newHashMap();
interfaz.setOperations(operations);
Map<String, IValue> interfaceInputs = null;
for (NodeTuple entry : node.getValue()) {
String key = scalarParser.parse(entry.getKeyNode(), context);
if (INPUTS_KEY.equals(key)) {
interfaceInputs = inputsParser.parse(entry.getValueNode(), context);
} else if (DESCRIPTION_KEY.equals(key)) {
interfaz.setDescription(scalarParser.parse(entry.getValueNode(), context));
} else if (TYPE_KEY.equals(key)) {
interfaz.setType(getInterfaceType(scalarParser.parse(entry.getValueNode(), context)));
} else {
if (entry.getValueNode() instanceof ScalarNode) {
Operation operation = new Operation();
// implementation artifact parsing should be done using a deferred parser as we need to look for artifact types.
operation.setImplementationArtifact(implementationArtifactParser.parse(entry.getValueNode(), context));
operations.put(key, operation);
} else {
operations.put(key, operationParser.parse(entry.getValueNode(), context));
}
}
}
if (interfaceInputs != null) {
for (Operation operation : operations.values()) {
if (operation.getInputParameters() == null) {
operation.setInputParameters(Maps.newHashMap());
}
for (Entry<String, IValue> inputEntry : interfaceInputs.entrySet()) {
if (!operation.getInputParameters().containsKey(inputEntry.getKey())) {
operation.getInputParameters().put(inputEntry.getKey(), inputEntry.getValue());
}
}
}
}
return interfaz;
}
use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.
the class LocationMatchNodesArtifactsElector method isEligible.
private boolean isEligible(AbstractInstantiableTemplate template, LocationMatchNodeFilter.NodeMatchContext matchContext) {
if (template == null) {
return true;
}
ArtifactSupport artifactSupport = matchContext.getArtifactSupport();
// if no supported artifact defined, then return true
if (artifactSupport == null || ArrayUtils.isEmpty(artifactSupport.getTypes())) {
return true;
}
String[] supportedArtifacts = artifactSupport.getTypes();
AbstractInstantiableToscaType indexedArtifactToscaElement = matchContext.getElement(AbstractInstantiableToscaType.class, template.getType());
if (MapUtils.isNotEmpty(indexedArtifactToscaElement.getInterfaces())) {
for (Interface interfaz : indexedArtifactToscaElement.getInterfaces().values()) {
for (Operation operation : interfaz.getOperations().values()) {
if (operation.getImplementationArtifact() != null) {
String artifactTypeString = operation.getImplementationArtifact().getArtifactType();
ArtifactType artifactType = matchContext.getElement(ArtifactType.class, artifactTypeString);
// stop the checking once one artifactType is not supported
if (!isFromOneOfTypes(supportedArtifacts, artifactType)) {
return false;
}
}
}
}
}
return true;
}
use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.
the class UpdateDockerImageProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, UpdateDockerImageOperation operation, NodeTemplate nodeTemplate) {
NodeType nodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
if (!ToscaTypeUtils.isOfType(nodeType, NormativeNodeTypesConstants.DOCKER_TYPE)) {
throw new IllegalArgumentException("Updating docker image can only be done on docker nodes. [" + nodeTemplate.getName() + "] does not inherit from [" + NormativeNodeTypesConstants.DOCKER_TYPE + "].");
}
Interface standard = safe(nodeTemplate.getInterfaces()).get(ToscaNodeLifecycleConstants.STANDARD);
if (standard == null) {
standard = new Interface(ToscaNodeLifecycleConstants.STANDARD);
if (nodeTemplate.getInterfaces() == null) {
nodeTemplate.setInterfaces(Maps.newHashMap());
}
nodeTemplate.getInterfaces().put(ToscaNodeLifecycleConstants.STANDARD, standard);
}
Operation create = safe(standard.getOperations()).get(ToscaNodeLifecycleConstants.CREATE);
if (create == null) {
create = getCreateOperation(nodeType.getInterfaces());
if (create == null) {
create = new Operation();
} else {
create = CloneUtil.clone(create);
}
if (standard.getOperations() == null) {
standard.setOperations(Maps.newHashMap());
}
standard.getOperations().put(ToscaNodeLifecycleConstants.CREATE, create);
if (create.getImplementationArtifact() == null) {
ImplementationArtifact createIA = new ImplementationArtifact();
createIA.setArtifactType(NormativeArtifactTypes.DOCKER);
createIA.setRepositoryName("docker");
create.setImplementationArtifact(createIA);
}
}
create.getImplementationArtifact().setArchiveName(csar.getName());
create.getImplementationArtifact().setArchiveVersion(csar.getVersion());
create.getImplementationArtifact().setArtifactRef(operation.getDockerImage());
create.getImplementationArtifact().setArtifactRepository("a4c_ignore");
}
use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.
the class IndexedModelTest method testMergeInterfaceOperationsMerge.
@Test
public void testMergeInterfaceOperationsMerge() {
// both are merged
Map<String, Interface> from = Maps.newHashMap();
Interface i1 = new Interface();
Map<String, Operation> ios1 = Maps.newHashMap();
Operation o1 = new Operation();
ios1.put("o1", o1);
i1.setOperations(ios1);
from.put("i1", i1);
Map<String, Interface> to = Maps.newHashMap();
Interface i2 = new Interface();
Map<String, Operation> ios2 = Maps.newHashMap();
Operation o2 = new Operation();
ios2.put("o2", o2);
i2.setOperations(ios2);
to.put("i1", i2);
Map<String, Interface> merged = IndexedModelUtils.mergeInterfaces(from, to);
assertEquals(1, merged.size());
assertEquals(2, merged.get("i1").getOperations().size());
assertSame(merged.get("i1").getOperations().get("o1"), o1);
assertSame(merged.get("i1").getOperations().get("o2"), o2);
}
use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.
the class IndexedModelTest method testMergeInterfaceOperationsToNull.
@Test
public void testMergeInterfaceOperationsToNull() {
// TO's operation is null
Map<String, Interface> from = Maps.newHashMap();
Interface i1 = new Interface();
Map<String, Operation> ios1 = Maps.newHashMap();
Operation o1 = new Operation();
ios1.put("o1", o1);
i1.setOperations(ios1);
from.put("i1", i1);
Map<String, Interface> to = Maps.newHashMap();
Interface i2 = new Interface();
to.put("i1", i2);
Map<String, Interface> merged = IndexedModelUtils.mergeInterfaces(from, to);
assertEquals(1, merged.size());
assertSame(merged.get("i1").getOperations().get("o1"), o1);
}
Aggregations