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);
}
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();
}
}
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);
}
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());
}
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();
}
Aggregations