use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.
the class ResetNodeDeploymentArtifactProcessor method process.
@Override
public void process(Csar csar, Topology topology, ResetNodeDeploymentArtifactOperation operation) {
// Get the node template's artifacts to reset
Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology.getId(), operation.getNodeName(), nodeTemplates);
DeploymentArtifact currentArtifact = nodeTemplate.getArtifacts() == null ? null : nodeTemplate.getArtifacts().get(operation.getArtifactName());
if (currentArtifact == null) {
throw new NotFoundException("Artifact with key [" + operation.getArtifactName() + "] do not exist in node template [" + nodeTemplate.getName() + "].");
}
// Get the node type's artifact
Map<String, NodeType> nodeTypes = topologyServiceCore.getIndexedNodeTypesFromTopology(topology, false, false, true);
NodeType nodeType = nodeTypes.get(nodeTemplate.getType());
DeploymentArtifact artifactFromNodeType = nodeType.getArtifacts() == null ? null : nodeType.getArtifacts().get(operation.getArtifactName());
if (artifactFromNodeType == null) {
throw new NotFoundException("Artifact with key [" + operation.getArtifactName() + "] do not exist in node type [" + nodeType.getId() + "].");
}
currentArtifact.setArtifactRef(artifactFromNodeType.getArtifactRef());
currentArtifact.setArtifactName(artifactFromNodeType.getArtifactName());
currentArtifact.setArtifactType(artifactFromNodeType.getArtifactType());
currentArtifact.setArtifactRepository(artifactFromNodeType.getArtifactRepository());
currentArtifact.setRepositoryName(artifactFromNodeType.getRepositoryName());
currentArtifact.setRepositoryURL(artifactFromNodeType.getRepositoryURL());
currentArtifact.setRepositoryCredential(artifactFromNodeType.getRepositoryCredential());
}
use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.
the class DeploymentTopologyStepDefinitions method iSelectTheFileFromTheCurrentTopologyArchiveForTheInputArtifact.
@When("^I select the file \"([^\"]*)\" from the current topology archive for the input artifact \"([^\"]*)\"$")
public void iSelectTheFileFromTheCurrentTopologyArchiveForTheInputArtifact(String fileRef, String inputArtifactName) throws Throwable {
Application application = Context.getInstance().getApplication();
String envId = Context.getInstance().getDefaultApplicationEnvironmentId(application.getName());
String url = String.format("/rest/applications/%s/environments/%s/deployment-topology/inputArtifacts/%s/update", application.getId(), envId, inputArtifactName);
DeploymentArtifact inputArtifact = new DeploymentArtifact();
inputArtifact.setArchiveName(application.getId());
inputArtifact.setArchiveVersion(TestUtils.getVersionFromId(Context.getInstance().getTopologyId()));
inputArtifact.setArtifactRef(fileRef);
inputArtifact.setArtifactRepository(ArtifactRepositoryConstants.ALIEN_TOPOLOGY_REPOSITORY);
Context.getInstance().registerRestResponse(Context.getRestClientInstance().postJSon(url, JsonUtil.toString(inputArtifact)));
}
use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.
the class InputArtifactsModifier method processInputArtifactForTemplate.
/**
* Map the template's artifacts associated with an input to into the given artifactMap.
*
* @param artifactMap The map of inputArtifactId -> List of associated artifacts into which to map the given template's artifacts.
* @param template The template for which to map artifact.
*/
private static void processInputArtifactForTemplate(Map<String, List<DeploymentArtifact>> artifactMap, AbstractInstantiableTemplate template) {
for (DeploymentArtifact da : template.getArtifacts().values()) {
String inputArtifactId = InputArtifactUtil.getInputArtifactId(da);
if (inputArtifactId != null) {
List<DeploymentArtifact> das = artifactMap.get(inputArtifactId);
if (das == null) {
das = Lists.newArrayList();
artifactMap.put(inputArtifactId, das);
}
das.add(da);
}
}
}
use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.
the class InputArtifactsModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
ApplicationEnvironment environment = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Input modifier requires an environment context.")).getEnvironment();
DeploymentInputs deploymentInputs = context.getConfiguration(DeploymentInputs.class, InputsModifier.class.getSimpleName()).orElse(new DeploymentInputs(environment.getTopologyVersion(), environment.getId()));
if (deploymentInputs.getInputArtifacts() == null) {
deploymentInputs.setInputArtifacts(Maps.newHashMap());
}
boolean updated = false;
// Cleanup inputs artifacts that does not exists anymore
Iterator<Entry<String, DeploymentArtifact>> inputArtifactsIterator = safe(deploymentInputs.getInputArtifacts()).entrySet().iterator();
while (inputArtifactsIterator.hasNext()) {
Entry<String, DeploymentArtifact> inputArtifactEntry = inputArtifactsIterator.next();
if (!topology.getInputArtifacts().containsKey(inputArtifactEntry.getKey())) {
inputArtifactsIterator.remove();
updated = true;
}
}
processInputArtifacts(topology, deploymentInputs.getInputArtifacts());
// should save if deploymentInput updated
if (updated) {
context.saveConfiguration(deploymentInputs);
}
}
use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.
the class InputArtifactsModifier method processInputArtifacts.
/**
* Inject input artifacts in the corresponding nodes.
*
* @param topology The topology in which to inject input artifacts.
* @param inputArtifacts The input artifacts to inject in the topology.
*/
private void processInputArtifacts(Topology topology, Map<String, DeploymentArtifact> inputArtifacts) {
if (topology.getInputArtifacts() != null && !topology.getInputArtifacts().isEmpty()) {
// we'll build a map inputArtifactId -> List<DeploymentArtifact>
Map<String, List<DeploymentArtifact>> artifactMap = Maps.newHashMap();
// iterate over nodes in order to remember all nodes referencing an input artifact
for (NodeTemplate nodeTemplate : topology.getNodeTemplates().values()) {
if (MapUtils.isNotEmpty(nodeTemplate.getArtifacts())) {
processInputArtifactForTemplate(artifactMap, nodeTemplate);
}
if (MapUtils.isNotEmpty(nodeTemplate.getRelationships())) {
nodeTemplate.getRelationships().entrySet().stream().filter(relationshipTemplateEntry -> MapUtils.isNotEmpty(relationshipTemplateEntry.getValue().getArtifacts())).forEach(relationshipTemplateEntry -> processInputArtifactForTemplate(artifactMap, relationshipTemplateEntry.getValue()));
}
}
// Override the artifacts definition in the topology with the input artifact data.
Map<String, DeploymentArtifact> allInputArtifact = new HashMap<>();
allInputArtifact.putAll(topology.getInputArtifacts());
if (MapUtils.isNotEmpty(inputArtifacts)) {
allInputArtifact.putAll(inputArtifacts);
}
for (Map.Entry<String, DeploymentArtifact> inputArtifact : allInputArtifact.entrySet()) {
List<DeploymentArtifact> nodeArtifacts = artifactMap.get(inputArtifact.getKey());
if (nodeArtifacts != null) {
for (DeploymentArtifact nodeArtifact : nodeArtifacts) {
nodeArtifact.setArtifactRef(inputArtifact.getValue().getArtifactRef());
nodeArtifact.setArtifactName(inputArtifact.getValue().getArtifactName());
nodeArtifact.setArtifactRepository(inputArtifact.getValue().getArtifactRepository());
nodeArtifact.setRepositoryName(inputArtifact.getValue().getRepositoryName());
nodeArtifact.setRepositoryCredential(inputArtifact.getValue().getRepositoryCredential());
nodeArtifact.setRepositoryURL(inputArtifact.getValue().getRepositoryURL());
nodeArtifact.setArchiveName(inputArtifact.getValue().getArchiveName());
nodeArtifact.setArchiveVersion(inputArtifact.getValue().getArchiveVersion());
}
}
}
}
}
Aggregations