Skip to content

Commit

Permalink
[WIP] Add basic support for Chronos jobs submission from TOSCA
Browse files Browse the repository at this point in the history
Beware that a lot of thing are hard-coded (e.g. the jobs dependencies)
and stubs for prototyping purpose.

See #34
  • Loading branch information
lorenzo-biava committed May 18, 2016
1 parent 09da211 commit 7201b70
Show file tree
Hide file tree
Showing 27 changed files with 2,652 additions and 391 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@
<artifactId>chronos-client</artifactId>
<version>${chronos-client.version}</version>
</dependency>

<!-- Graph library -->
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-core</artifactId>
<version>0.9.2</version>
</dependency>

<!-- test -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface ResourceRepository extends PagingAndSortingRepository<Resource,
public Page<Resource> findByDeployment_id(String deploymentId, Pageable pageable);

public Resource findByIdAndDeployment_id(String uuid, String deploymentId);

public Resource findByToscaNodeNameAndDeployment_id(String toscaNodeName, String deploymentId);
}
15 changes: 10 additions & 5 deletions src/main/java/it/reply/orchestrator/service/DeploymentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@

public interface DeploymentService {

public Page<Deployment> getDeployments(Pageable pageable);
public static final String WF_PARAM_DEPLOYMENT_ID = "DEPLOYMENT_ID";
public static final String WF_PARAM_DEPLOYMENT_TYPE = "DEPLOYMENT_TYPE";
public static final String DEPLOYMENT_TYPE_CHRONOS = "CHRONOS";
public static final String DEPLOYMENT_TYPE_TOSCA = "TOSCA";

public Deployment getDeployment(String id);
public Page<Deployment> getDeployments(Pageable pageable);

public Deployment createDeployment(DeploymentRequest request);
public Deployment getDeployment(String id);

public void updateDeployment(String id, DeploymentRequest request);
public Deployment createDeployment(DeploymentRequest request);

public void deleteDeployment(String id);
public void updateDeployment(String id, DeploymentRequest request);

public void deleteDeployment(String id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,32 @@ public Deployment createDeployment(DeploymentRequest request) {
}

deployment = deploymentRepository.save(deployment);
Map<String, NodeTemplate> nodes = null;
boolean isChronosDeployment = false;
try {
String template = toscaService.customizeTemplate(request.getTemplate(), deployment.getId());
deployment.setTemplate(template);
// Parse once
ArchiveRoot parsingResult = toscaService.parseTemplate(request.getTemplate());

Map<String, NodeTemplate> nodes = toscaService.getArchiveRootFromTemplate(template)
.getResult().getTopology().getNodeTemplates();
nodes = parsingResult.getTopology().getNodeTemplates();

// FIXME: Temporary - just for test
isChronosDeployment = isChronosDeployment(nodes);

if (!isChronosDeployment) {
// FIXME (BAD HACK) IM templates need some parameters to be added, but regenerating the
// template string with the current library is risky (loses some information!!)
// Re-parse and customize
String template = toscaService.customizeTemplate(request.getTemplate(), deployment.getId());
deployment.setTemplate(template);

// Re-parse with the updated nodes
nodes = toscaService.getArchiveRootFromTemplate(template).getResult().getTopology()
.getNodeTemplates();
} else {
deployment.setTemplate(request.getTemplate());
}

// Create internal resources representation (to store in DB)
createResources(deployment, nodes);

} catch (IOException | ParsingException ex) {
Expand All @@ -96,6 +116,11 @@ public Deployment createDeployment(DeploymentRequest request) {

Map<String, Object> params = new HashMap<>();
params.put("DEPLOYMENT_ID", deployment.getId());

// FIXME: Temporary - just for test
params.put(WF_PARAM_DEPLOYMENT_TYPE,
(isChronosDeployment ? DEPLOYMENT_TYPE_CHRONOS : DEPLOYMENT_TYPE_TOSCA));

ProcessInstance pi = null;
try {
pi = wfService.startProcess(WorkflowConfigProducerBean.DEPLOY.getProcessId(), params,
Expand All @@ -110,6 +135,25 @@ public Deployment createDeployment(DeploymentRequest request) {

}

/**
* Temporary method to decide whether a given deployment has to be deployed using Chronos (<b>just
* for experiments</b>). <br/>
* Currently, if there is at least one node whose name contains 'Chronos', the deployment is done
* with Chronos.
*
* @param nodes
* the template nodes.
* @return <tt>true</tt> if Chronos, <tt>false</tt> otherwise.
*/
private static boolean isChronosDeployment(Map<String, NodeTemplate> nodes) {
for (Map.Entry<String, NodeTemplate> node : nodes.entrySet()) {
if (node.getValue().getType().contains("Chronos")) {
return true;
}
}
return false;
}

@Override
@Transactional
public void deleteDeployment(String uuid) {
Expand All @@ -120,19 +164,26 @@ public void deleteDeployment(String uuid) {
throw new ConflictException(
String.format("Deployment already in %s state.", deployment.getStatus().toString()));
} else {
// Update deployment status
deployment.setStatus(Status.DELETE_IN_PROGRESS);
deployment.setStatusReason("");
deployment.setTask(Task.NONE);
deployment = deploymentRepository.save(deployment);

// Abort all WF currently active on this deployment
Iterator<WorkflowReference> wrIt = deployment.getWorkflowReferences().iterator();
while (wrIt.hasNext()) {
WorkflowReference wr = wrIt.next();
wfService.abortProcess(wr.getProcessId(), wr.getRuntimeStrategy());
wrIt.remove();
}
deployment = deploymentRepository.save(deployment);

Map<String, Object> params = new HashMap<>();
params.put("DEPLOYMENT_ID", deployment.getId());

// FIXME: Temporary - just for test
params.put(WF_PARAM_DEPLOYMENT_TYPE, deployment.getDeploymentProvider().name());

ProcessInstance pi = null;
try {
pi = wfService.startProcess(WorkflowConfigProducerBean.UNDEPLOY.getProcessId(), params,
Expand Down
46 changes: 45 additions & 1 deletion src/main/java/it/reply/orchestrator/service/ToscaService.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package it.reply.orchestrator.service;

import alien4cloud.model.components.AbstractPropertyValue;
import alien4cloud.model.components.PropertyValue;
import alien4cloud.model.topology.Capability;
import alien4cloud.model.topology.NodeTemplate;
import alien4cloud.model.topology.RelationshipTemplate;
import alien4cloud.tosca.model.ArchiveRoot;
import alien4cloud.tosca.parser.ParsingException;
import alien4cloud.tosca.parser.ParsingResult;

import com.sun.istack.NotNull;

import it.reply.orchestrator.exception.service.ToscaException;

import java.io.IOException;
import java.util.List;
import java.util.Map;
Expand All @@ -20,16 +25,55 @@ public interface ToscaService {
public ParsingResult<ArchiveRoot> getArchiveRootFromTemplate(@Nonnull String toscaTemplate)
throws IOException, ParsingException;

/**
* Obtain the string TOSCA template representation from the in-memory representation. <br/>
* <b>WARNING: Some nodes or properties might be missing!! Use at your own risk!</b>
*
* @param archiveRoot
* @return
* @throws IOException
*/
@Nonnull
public String getTemplateFromTopology(@Nonnull ArchiveRoot archiveRoot) throws IOException;

@Nonnull
public String customizeTemplate(@Nonnull String toscaTemplate, @NotNull String deploymentId)
throws IOException;
throws IOException, ToscaException, ParsingException;

/**
* Parse the TOSCA template (string) and get the in-memory representation.<br/>
* This also checks for validation errors.
*
* @param toscaTemplate
* the TOSCA template as string.
* @return an {@link ArchiveRoot} representing the template.
* @throws IOException
* if an I/O error occurs (converting the string to a CSAR zipped archive internally).
* @throws ParsingException
* if parsing errors occur.
* @throws ToscaException
* if validation errors occur.
*/
@Nonnull
public ArchiveRoot parseTemplate(@Nonnull String toscaTemplate)
throws IOException, ParsingException, ToscaException;

@Nonnull
public Capability getNodeCapabilityByName(NodeTemplate node, String propertyName);

@Nonnull
public AbstractPropertyValue getNodePropertyByName(NodeTemplate node, String propertyName);

@Nonnull
public PropertyValue<?> getNodePropertyValueByName(NodeTemplate node, String propertyName);

@Nonnull
public PropertyValue<?> getCapabilityPropertyValueByName(Capability capability,
String propertyName);

public RelationshipTemplate getRelationshipTemplateByCapabilityName(
Map<String, RelationshipTemplate> relationships, String capabilityName);

public Map<String, NodeTemplate> getCountNodes(ArchiveRoot archiveRoot);

public int getCount(NodeTemplate nodeTemplate);
Expand Down
Loading

0 comments on commit 7201b70

Please sign in to comment.