Search in sources :

Example 21 with DeploymentArtifact

use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.

the class ToscaSerializerUtilsTest method testArtifactsAndRepositoriesExport.

@Test
public void testArtifactsAndRepositoriesExport() {
    Topology topology = new Topology();
    topology.setNodeTemplates(Maps.newHashMap());
    NodeTemplate node = new NodeTemplate();
    node.setArtifacts(Maps.newHashMap());
    topology.getNodeTemplates().put("Compute", node);
    // no repositories
    DeploymentArtifact deploymentArtifact = createArtifact();
    deploymentArtifact.setArtifactRef("aaa/bbb.zip");
    deploymentArtifact.setArtifactType("tosca.artifacts.File");
    node.getArtifacts().put("local_war", deploymentArtifact);
    Assert.assertFalse(ToscaSerializerUtils.hasRepositories("test", "1.0", topology));
    String deploymentArtifactExport = ToscaSerializerUtils.formatArtifact(deploymentArtifact, 2);
    Assert.assertEquals("    file: aaa/bbb.zip\n    type: tosca.artifacts.File", deploymentArtifactExport);
    // one repository should success
    DeploymentArtifact deploymentArtifact2 = createArtifact();
    deploymentArtifact2.setArtifactRef("aaa/bbb.zip");
    deploymentArtifact2.setArtifactType("tosca.artifacts.File");
    deploymentArtifact2.setRepositoryName("my_company");
    deploymentArtifact2.setRepositoryURL("http://my_company.org");
    deploymentArtifact2.setArtifactRepository("http");
    deploymentArtifact2.setRepositoryCredential(Maps.newHashMap());
    deploymentArtifact2.getRepositoryCredential().put("user", "my_user");
    deploymentArtifact2.getRepositoryCredential().put("token", "password");
    node.getArtifacts().put("http_war", deploymentArtifact2);
    Assert.assertTrue(ToscaSerializerUtils.hasRepositories("test", "1.0", topology));
    String deploymentArtifact2Export = ToscaSerializerUtils.formatArtifact(deploymentArtifact2, 1);
    String repositoriesExport = ToscaSerializerUtils.formatRepositories("test", "1.0", topology);
    Assert.assertEquals("  file: aaa/bbb.zip\n  type: tosca.artifacts.File\n  repository: my_company", deploymentArtifact2Export);
    Assert.assertEquals("  my_company:\n    url: http://my_company.org\n    type: http\n    credential:\n      token: password\n      user: my_user", repositoriesExport);
    // two repositories with different name
    DeploymentArtifact deploymentArtifact3 = createArtifact();
    deploymentArtifact3.setArtifactRef("aaa/ccc.zip");
    deploymentArtifact3.setArtifactType("tosca.artifacts.File");
    deploymentArtifact3.setRepositoryName("my_companyBis");
    deploymentArtifact3.setRepositoryURL("http://my_company.org");
    deploymentArtifact3.setArtifactRepository("maven");
    node.getArtifacts().put("http_war2", deploymentArtifact3);
    Assert.assertTrue(ToscaSerializerUtils.hasRepositories("test", "1.0", topology));
    repositoriesExport = ToscaSerializerUtils.formatRepositories("test", "1.0", topology);
    Assert.assertEquals("  my_company:\n    url: http://my_company.org\n    type: http\n    credential:\n      token: password\n      user: my_user\n  my_companyBis:\n    url: http://my_company.org\n    type: maven", repositoriesExport);
    // add a new artifact with an already existing repository, should not duplicate the repository
    DeploymentArtifact deploymentArtifact4 = createArtifact();
    deploymentArtifact4.setArtifactRef("aaa/ddd.zip");
    deploymentArtifact4.setArtifactType("tosca.artifacts.File");
    deploymentArtifact4.setRepositoryName("my_company");
    deploymentArtifact4.setRepositoryURL("http://my_company.org");
    deploymentArtifact4.setArtifactRepository("http");
    node.getArtifacts().put("http_war3", deploymentArtifact4);
    Assert.assertTrue(ToscaSerializerUtils.hasRepositories("test", "1.0", topology));
    repositoriesExport = ToscaSerializerUtils.formatRepositories("test", "1.0", topology);
    Assert.assertEquals("  my_company:\n    url: http://my_company.org\n    type: http\n    credential:\n      token: password\n      user: my_user\n  my_companyBis:\n    url: http://my_company.org\n    type: maven", repositoriesExport);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Topology(org.alien4cloud.tosca.model.templates.Topology) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) Test(org.junit.Test)

Example 22 with DeploymentArtifact

use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.

the class EditorRepositoryController method getAvailableRepositories.

/**
 * Get the available repositories regarding archive repositories and A4C repositories.
 */
@ApiOperation(value = "Get the available repositories regarding archive repositories and A4C repositories", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ]")
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public RestResponse<AvailableTopologyRepositories> getAvailableRepositories(@ApiParam(value = "The topology id.", required = true) @NotBlank @PathVariable final String topologyId) {
    try {
        editionContextManager.init(topologyId);
        Topology topology = EditionContextManager.getTopology();
        List<AvailableTopologyRepository> archiveRepositories = Lists.newArrayList();
        List<AvailableTopologyRepository> alienRepositories = Lists.newArrayList();
        List<String> repositoryTypes = Lists.newArrayList();
        AvailableTopologyRepositories result = new AvailableTopologyRepositories(archiveRepositories, alienRepositories, repositoryTypes);
        Set<String> repositoriesName = Sets.newHashSet();
        Set<String> repositoriesUrl = Sets.newHashSet();
        for (NodeTemplate node : topology.getNodeTemplates().values()) {
            if (node.getArtifacts() != null && CollectionUtils.isNotEmpty(node.getArtifacts().values())) {
                for (DeploymentArtifact artifact : node.getArtifacts().values()) {
                    if (artifact.getRepositoryURL() != null && !repositoriesName.contains(artifact.getRepositoryName())) {
                        AvailableTopologyRepository atr = new AvailableTopologyRepository(artifact.getRepositoryName(), artifact.getArtifactRepository(), artifact.getRepositoryURL());
                        archiveRepositories.add(atr);
                        repositoriesName.add(artifact.getRepositoryName());
                        repositoriesUrl.add(artifact.getRepositoryURL());
                    }
                }
            }
        }
        FilteredSearchRequest searchRequest = new FilteredSearchRequest();
        searchRequest.setFrom(0);
        searchRequest.setSize(Integer.MAX_VALUE);
        FacetedSearchResult<Repository> searchResult = repositoryService.search(searchRequest);
        for (Repository repository : searchResult.getData()) {
            String url = repositoryService.getRepositoryUrl(repository);
            if (!repositoriesUrl.contains(url)) {
                // only return this repository if it's url doesn't not match existing archive repository url
                AvailableTopologyRepository atr = new AvailableTopologyRepository(repository.getName(), repository.getRepositoryType(), url);
                alienRepositories.add(atr);
            }
        }
        List<RepositoryPluginComponent> plugins = repositoryService.listPluginComponents();
        for (RepositoryPluginComponent repositoryPluginComponent : plugins) {
            repositoryTypes.add(repositoryPluginComponent.getRepositoryType());
        }
        return RestResponseBuilder.<AvailableTopologyRepositories>builder().data(result).build();
    } finally {
        ToscaContext.destroy();
    }
}
Also used : RepositoryPluginComponent(alien4cloud.repository.model.RepositoryPluginComponent) AvailableTopologyRepositories(alien4cloud.repository.model.AvailableTopologyRepositories) Topology(org.alien4cloud.tosca.model.templates.Topology) FilteredSearchRequest(alien4cloud.rest.model.FilteredSearchRequest) Repository(alien4cloud.model.repository.Repository) AvailableTopologyRepository(alien4cloud.repository.model.AvailableTopologyRepository) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) AvailableTopologyRepository(alien4cloud.repository.model.AvailableTopologyRepository) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with DeploymentArtifact

use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.

the class ToscaParserSimpleProfileAlien130Test method validateMavenDeploymentArtifact.

private void validateMavenDeploymentArtifact(NodeType mavenComponent) {
    DeploymentArtifact artifact = getDeploymentArtifact(mavenComponent, "simple_war");
    validateSimpleWar(artifact);
    DeploymentArtifact repositoryArtifact = getDeploymentArtifact(mavenComponent, "remote_war");
    validateRemoteWar(repositoryArtifact);
}
Also used : DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact)

Example 24 with DeploymentArtifact

use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.

the class ToscaParserSimpleProfileAlien130Test method testParseDeploymentArtifactWithRepository.

@Test
public void testParseDeploymentArtifactWithRepository() throws ParsingException {
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "deployment_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(1, archiveRoot.getRepositories().size());
    Assert.assertEquals(2, archiveRoot.getArtifactTypes().size());
    Assert.assertEquals(3, archiveRoot.getNodeTypes().size());
    Assert.assertEquals(3, archiveRoot.getNodeTypes().size());
    Assert.assertEquals(3, archiveRoot.getRelationshipTypes().size());
    NodeType mavenComponent = archiveRoot.getNodeTypes().get("my.maven.component");
    validateMavenDeploymentArtifact(mavenComponent);
    NodeType mavenExtendedComponent = archiveRoot.getNodeTypes().get("my.maven.component.extended");
    validateMavenDeploymentArtifact(mavenExtendedComponent);
    DeploymentArtifact artifact = archiveRoot.getTopology().getInputArtifacts().get("simple_war");
    validateSimpleWar(artifact);
    DeploymentArtifact repositoryArtifact = archiveRoot.getTopology().getInputArtifacts().get("remote_war");
    validateRemoteWar(repositoryArtifact);
    artifact = archiveRoot.getTopology().getNodeTemplates().get("my_node").getArtifacts().get("simple_war");
    Assert.assertEquals("binary/myWar.war", artifact.getArtifactRef());
    Assert.assertEquals("tosca.artifacts.Deployment.War", artifact.getArtifactType());
    assertNull(artifact.getRepositoryCredential());
    assertNull(artifact.getRepositoryName());
    assertNull(artifact.getArtifactRepository());
    assertNull(artifact.getRepositoryURL());
    repositoryArtifact = archiveRoot.getTopology().getNodeTemplates().get("my_node").getArtifacts().get("remote_war");
    Assert.assertEquals("alien4cloud:alien4cloud-ui:1.3.0-SM3", repositoryArtifact.getArtifactRef());
    Assert.assertEquals("tosca.artifacts.Deployment.War", repositoryArtifact.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(), repositoryArtifact.getRepositoryCredential());
    Assert.assertEquals("maven_repo", repositoryArtifact.getRepositoryName());
    Assert.assertEquals("maven", repositoryArtifact.getArtifactRepository());
    Assert.assertEquals("https://fastconnect.org/maven/content/repositories/fastconnect", repositoryArtifact.getRepositoryURL());
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) Test(org.junit.Test)

Example 25 with DeploymentArtifact

use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.

the class ToscaSerializerUtils method formatRepositories.

public static String formatRepositories(String topologyArchiveName, String topologyArchiveVersion, Topology topology) {
    StringBuilder buffer = new StringBuilder();
    Set<String> repositoriesName = Sets.newHashSet();
    for (NodeTemplate node : safe(topology.getNodeTemplates()).values()) {
        for (DeploymentArtifact artifact : safe(node.getArtifacts()).values()) {
            // Only generate repositories for the current topology
            if (isInternalRepoArtifact(artifact, topologyArchiveName, topologyArchiveVersion)) {
                buffer.append("  ").append(artifact.getRepositoryName()).append(":");
                buffer.append("\n").append(formatRepository(artifact, 2)).append("\n");
            }
        }
        for (Interface anInterface : safe(node.getInterfaces()).values()) {
            for (Operation operation : safe(anInterface.getOperations()).values()) {
                if (operation.getImplementationArtifact() != null && isInternalRepoArtifact(operation.getImplementationArtifact(), topologyArchiveName, topologyArchiveVersion)) {
                    buffer.append("  ").append(operation.getImplementationArtifact().getRepositoryName()).append(":");
                    buffer.append("\n").append(formatRepository(operation.getImplementationArtifact(), 2)).append("\n");
                }
            }
        }
    }
    if (MapUtils.isNotEmpty(topology.getInputArtifacts())) {
        topology.getInputArtifacts().values().forEach(inputArtifact -> {
            if (StringUtils.isNotBlank(inputArtifact.getRepositoryURL()) && repositoriesName.add(inputArtifact.getRepositoryName())) {
                buffer.append("  ").append(inputArtifact.getRepositoryName()).append(":");
                buffer.append("\n").append(formatRepository(inputArtifact, 2)).append("\n");
            }
        });
    }
    buffer.setLength(buffer.length() - 1);
    return buffer.toString();
}
Also used : ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Operation(org.alien4cloud.tosca.model.definitions.Operation) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Aggregations

DeploymentArtifact (org.alien4cloud.tosca.model.definitions.DeploymentArtifact)25 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)10 NotFoundException (alien4cloud.exception.NotFoundException)6 Map (java.util.Map)5 DeploymentInputs (org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs)5 Topology (org.alien4cloud.tosca.model.templates.Topology)5 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 ArtifactRepositoryConstants (alien4cloud.component.repository.ArtifactRepositoryConstants)2 IFileRepository (alien4cloud.component.repository.IFileRepository)2 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)2 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)2 Path (java.nio.file.Path)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2 Resource (javax.annotation.Resource)2 Interface (org.alien4cloud.tosca.model.definitions.Interface)2