Search in sources :

Example 1 with ImplementationArtifact

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());
}
Also used : ImplementationArtifact(org.alien4cloud.tosca.model.definitions.ImplementationArtifact)

Example 2 with ImplementationArtifact

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);
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Operation(org.alien4cloud.tosca.model.definitions.Operation) IllegalOperationWarning(alien4cloud.topology.warning.IllegalOperationWarning) ImplementationArtifact(org.alien4cloud.tosca.model.definitions.ImplementationArtifact) ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 3 with ImplementationArtifact

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");
}
Also used : ImplementationArtifact(org.alien4cloud.tosca.model.definitions.ImplementationArtifact) NodeType(org.alien4cloud.tosca.model.types.NodeType) Operation(org.alien4cloud.tosca.model.definitions.Operation) UpdateDockerImageOperation(org.alien4cloud.tosca.editor.operations.nodetemplate.UpdateDockerImageOperation) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 4 with ImplementationArtifact

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());
}
Also used : ImplementationArtifact(org.alien4cloud.tosca.model.definitions.ImplementationArtifact) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Test(org.junit.Test)

Example 5 with ImplementationArtifact

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;
}
Also used : ImplementationArtifact(org.alien4cloud.tosca.model.definitions.ImplementationArtifact) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode)

Aggregations

ImplementationArtifact (org.alien4cloud.tosca.model.definitions.ImplementationArtifact)5 Interface (org.alien4cloud.tosca.model.definitions.Interface)2 Operation (org.alien4cloud.tosca.model.definitions.Operation)2 NodeType (org.alien4cloud.tosca.model.types.NodeType)2 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)2 IllegalOperationWarning (alien4cloud.topology.warning.IllegalOperationWarning)1 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)1 UpdateDockerImageOperation (org.alien4cloud.tosca.editor.operations.nodetemplate.UpdateDockerImageOperation)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)1 ServiceNodeTemplate (org.alien4cloud.tosca.model.templates.ServiceNodeTemplate)1 Test (org.junit.Test)1 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)1