use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.
the class TopologyTreeBuilderService method mergeInterfaces.
@SneakyThrows
private void mergeInterfaces(AbstractPaaSTemplate pasSTemplate, AbstractInstantiableTemplate abstractTemplate) {
AbstractToscaType type = pasSTemplate.getIndexedToscaElement();
Map<String, Interface> typeInterfaces = null;
if (type instanceof AbstractInstantiableToscaType) {
typeInterfaces = ((AbstractInstantiableToscaType) type).getInterfaces();
}
Map<String, Interface> templateInterfaces = abstractTemplate.getInterfaces();
// Here merge interfaces: the interface defined in the template should override those from type.
pasSTemplate.setInterfaces(IndexedModelUtils.mergeInterfaces(JsonUtil.toMap(JsonUtil.toString(typeInterfaces), String.class, Interface.class), templateInterfaces));
}
use of org.alien4cloud.tosca.model.definitions.Interface 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.Interface 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.Interface 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);
}
use of org.alien4cloud.tosca.model.definitions.Interface in project alien4cloud by alien4cloud.
the class IndexedModelTest method testMergeInterfaceOperationsKeepTo.
@Test
public void testMergeInterfaceOperationsKeepTo() {
// TO keeps it's own operation
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("o1", o2);
i2.setOperations(ios2);
to.put("i1", i2);
Map<String, Interface> merged = IndexedModelUtils.mergeInterfaces(from, to);
assertEquals(1, merged.size());
assertSame(merged.get("i1").getOperations().get("o1"), o2);
}
Aggregations