use of org.alien4cloud.tosca.model.definitions.ImplementationArtifact in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method validateHttpArtifact.
private void validateHttpArtifact(NodeType httpComponent) {
ImplementationArtifact httpComponentCreateArtifact = getImplementationArtifact(httpComponent, "create");
Assert.assertEquals("https://otherCompany/script/short_notation.sh", httpComponentCreateArtifact.getArtifactRef());
Assert.assertEquals("tosca.artifacts.Implementation.Bash", httpComponentCreateArtifact.getArtifactType());
assertNull(httpComponentCreateArtifact.getRepositoryCredential());
assertNull(httpComponentCreateArtifact.getRepositoryName());
assertNull(httpComponentCreateArtifact.getArtifactRepository());
assertNull(httpComponentCreateArtifact.getRepositoryURL());
ImplementationArtifact httpComponentStartArtifact = getImplementationArtifact(httpComponent, "start");
Assert.assertEquals("myScript.abc", httpComponentStartArtifact.getArtifactRef());
Assert.assertEquals("tosca.artifacts.Implementation.Bash", httpComponentStartArtifact.getArtifactType());
Assert.assertEquals(ImmutableMap.<String, Object>builder().put(NormativeCredentialConstant.USER_KEY, "good_user").put(NormativeCredentialConstant.TOKEN_KEY, "real_secured_password").put(NormativeCredentialConstant.TOKEN_TYPE, "password").build(), httpComponentStartArtifact.getRepositoryCredential());
Assert.assertEquals("script_repo", httpComponentStartArtifact.getRepositoryName());
assertNull(httpComponentStartArtifact.getArtifactRepository());
Assert.assertEquals("https://myCompany/script", httpComponentStartArtifact.getRepositoryURL());
}
use of org.alien4cloud.tosca.model.definitions.ImplementationArtifact in project alien4cloud by alien4cloud.
the class TopologyServiceInterfaceOverrideCheckerService method findWarnings.
public List<IllegalOperationWarning> findWarnings(Topology topology) {
Set<IllegalOperationWarning> warnings = Sets.newHashSet();
Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
for (Entry<String, NodeTemplate> nodeTempEntry : nodeTemplates.entrySet()) {
NodeTemplate nodeTemplate = nodeTempEntry.getValue();
Map<String, RelationshipTemplate> relationships = nodeTemplate.getRelationships();
if (relationships != null) {
for (Entry<String, RelationshipTemplate> entry : relationships.entrySet()) {
RelationshipTemplate relationshipTemplate = entry.getValue();
String target = relationshipTemplate.getTarget();
NodeTemplate targetNodeTemplate = nodeTemplates.get(target);
boolean serviceIsSource = isService(nodeTemplate);
boolean serviceIsTarget = isService(targetNodeTemplate);
if (serviceIsSource || serviceIsTarget) {
RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
if (relationshipType != null) {
Map<String, Interface> interfaces = relationshipType.getInterfaces();
if (interfaces != null) {
interfaces.forEach((relationshipName, relationshipInterface) -> {
Map<String, Operation> operations = relationshipInterface.getOperations();
if (operations != null) {
operations.forEach((operationName, operation) -> {
String serviceName;
if (serviceIsTarget) {
serviceName = nodeTemplate.getName();
switch(operationName.toLowerCase()) {
case "add_source":
case "remove_source":
case "source_changed":
case "post_configure_target":
case "pre_configure_target":
ImplementationArtifact artifact = operation.getImplementationArtifact();
boolean stepDoSomething = artifact != null;
if (stepDoSomething) {
addWarning(warnings, nodeTemplate, relationshipInterface, operationName, serviceName, relationshipTemplate.getType());
}
break;
}
}
if (serviceIsSource) {
serviceName = targetNodeTemplate.getName();
switch(operationName.toLowerCase()) {
case "add_target":
case "remove_target":
case "target_changed":
case "pre_configure_source":
case "post_configure_source":
ImplementationArtifact artifact = operation.getImplementationArtifact();
boolean stepDoSomething = artifact != null;
if (stepDoSomething) {
addWarning(warnings, nodeTemplate, relationshipInterface, operationName, serviceName, relationshipTemplate.getType());
}
break;
}
}
});
}
});
}
}
}
}
}
}
return warnings.isEmpty() ? null : new ArrayList<>(warnings);
}
use of org.alien4cloud.tosca.model.definitions.ImplementationArtifact 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.ImplementationArtifact in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method testParseImplementationArtifactWithRepository.
@Test
public void testParseImplementationArtifactWithRepository() throws ParsingException {
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "implementation_artifact.yml"));
ParserTestUtil.displayErrors(parsingResult);
assertTrue(parsingResult.getContext().getParsingErrors().isEmpty());
ArchiveRoot archiveRoot = parsingResult.getResult();
assertNotNull(archiveRoot.getArchive());
Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
Assert.assertEquals(2, archiveRoot.getArtifactTypes().size());
Assert.assertEquals(4, archiveRoot.getNodeTypes().size());
Assert.assertEquals(3, archiveRoot.getRepositories().size());
Assert.assertEquals(3, archiveRoot.getRelationshipTypes().size());
NodeType httpComponent = archiveRoot.getNodeTypes().get("my.http.component");
validateHttpArtifact(httpComponent);
NodeType httpComponentExtended = archiveRoot.getNodeTypes().get("my.http.component.extended");
validateHttpArtifact(httpComponentExtended);
NodeType gitComponent = archiveRoot.getNodeTypes().get("my.git.component");
ImplementationArtifact gitComponentCreateArtifact = getImplementationArtifact(gitComponent, "create");
Assert.assertEquals("master:myGitScript.xyz", gitComponentCreateArtifact.getArtifactRef());
Assert.assertEquals("tosca.artifacts.Implementation.Bash", gitComponentCreateArtifact.getArtifactType());
assertNull(gitComponentCreateArtifact.getRepositoryCredential());
Assert.assertEquals("git_repo", gitComponentCreateArtifact.getRepositoryName());
Assert.assertEquals("git", gitComponentCreateArtifact.getArtifactRepository());
Assert.assertEquals("https://github.com/myId/myRepo.git", gitComponentCreateArtifact.getRepositoryURL());
RelationshipType httpRelationship = archiveRoot.getRelationshipTypes().get("my.http.relationship");
ImplementationArtifact httpRelationshipCreateArtifact = getImplementationArtifact(httpRelationship, "create");
Assert.assertEquals("https://otherCompany/script/short_notation.sh", httpRelationshipCreateArtifact.getArtifactRef());
Assert.assertEquals("tosca.artifacts.Implementation.Bash", httpRelationshipCreateArtifact.getArtifactType());
assertNull(httpRelationshipCreateArtifact.getRepositoryCredential());
assertNull(httpRelationshipCreateArtifact.getRepositoryName());
assertNull(httpRelationshipCreateArtifact.getArtifactRepository());
assertNull(httpRelationshipCreateArtifact.getRepositoryURL());
ImplementationArtifact httpRelationshipStartArtifact = getImplementationArtifact(httpRelationship, "start");
Assert.assertEquals("myScript.abc", httpRelationshipStartArtifact.getArtifactRef());
Assert.assertEquals("tosca.artifacts.Implementation.Bash", httpRelationshipStartArtifact.getArtifactType());
Assert.assertEquals(ImmutableMap.<String, Object>builder().put(NormativeCredentialConstant.USER_KEY, "good_user").put(NormativeCredentialConstant.TOKEN_KEY, "real_secured_password").put(NormativeCredentialConstant.TOKEN_TYPE, "password").build(), httpRelationshipStartArtifact.getRepositoryCredential());
Assert.assertEquals("script_repo", httpRelationshipStartArtifact.getRepositoryName());
assertNull(httpRelationshipStartArtifact.getArtifactRepository());
Assert.assertEquals("https://myCompany/script", httpRelationshipStartArtifact.getRepositoryURL());
}
use of org.alien4cloud.tosca.model.definitions.ImplementationArtifact in project alien4cloud by alien4cloud.
the class ImplementationArtifactParser method parse.
@Override
public ImplementationArtifact parse(Node node, ParsingContextExecution context) {
if (node instanceof ScalarNode) {
String artifactReference = ((ScalarNode) node).getValue();
ImplementationArtifact artifact = new ImplementationArtifact();
artifact.setArtifactRef(artifactReference);
return artifact;
} else {
ParserUtils.addTypeError(node, context.getParsingErrors(), "Artifact definition");
}
return null;
}
Aggregations