Skip to content

Commit

Permalink
Disabled Chronos deployment update (not supported)
Browse files Browse the repository at this point in the history
See #34
  • Loading branch information
lorenzo-biava committed May 19, 2016
1 parent 7201b70 commit 6bb3dbb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.reply.orchestrator.exception;

import it.reply.orchestrator.dto.common.Error;
import it.reply.orchestrator.exception.http.BadRequestException;
import it.reply.orchestrator.exception.http.ConflictException;
import it.reply.orchestrator.exception.http.NotFoundException;
import it.reply.orchestrator.exception.service.ToscaException;
Expand Down Expand Up @@ -77,6 +78,22 @@ public Error handleException(ToscaException ex) {
.withTitle(HttpStatus.BAD_REQUEST.getReasonPhrase()).withMessage(ex.getMessage());
}

/**
* Bad request exception handler.
*
* @param ex
* the exception
* @return a {@code ResponseEntity} instance
*/
@ExceptionHandler
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public Error handleException(BadRequestException ex) {

return new Error().withCode(HttpStatus.BAD_REQUEST.value())
.withTitle(HttpStatus.BAD_REQUEST.getReasonPhrase()).withMessage(ex.getMessage());
}

/**
* Server Error exception handler.
*
Expand Down Expand Up @@ -169,9 +186,8 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotV
*/
private ResponseEntity<Object> handleResponse(Exception ex, HttpHeaders headers,
HttpStatus status) {
Error error =
new Error().withCode(status.value()).withTitle(status.getReasonPhrase())
.withMessage(ex.getMessage());
Error error = new Error().withCode(status.value()).withTitle(status.getReasonPhrase())
.withMessage(ex.getMessage());

return new ResponseEntity<Object>(error, headers, status);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package it.reply.orchestrator.exception.http;

/**
* Exception thrown when the client request is bad (i.e. wrong information, wrong resource status,
* etc)
*
* @author m.bassi
*
*/
public class BadRequestException extends OrchestratorApiException {

private static final long serialVersionUID = 1L;

public BadRequestException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import alien4cloud.model.topology.NodeTemplate;
import alien4cloud.tosca.model.ArchiveRoot;
import alien4cloud.tosca.parser.ParsingException;
import alien4cloud.tosca.parser.ParsingResult;

import it.reply.orchestrator.config.WorkflowConfigProducerBean;
import it.reply.orchestrator.dal.entity.Deployment;
Expand All @@ -14,10 +13,12 @@
import it.reply.orchestrator.dal.repository.DeploymentRepository;
import it.reply.orchestrator.dal.repository.ResourceRepository;
import it.reply.orchestrator.dto.request.DeploymentRequest;
import it.reply.orchestrator.enums.DeploymentProvider;
import it.reply.orchestrator.enums.NodeStates;
import it.reply.orchestrator.enums.Status;
import it.reply.orchestrator.enums.Task;
import it.reply.orchestrator.exception.OrchestratorException;
import it.reply.orchestrator.exception.http.BadRequestException;
import it.reply.orchestrator.exception.http.ConflictException;
import it.reply.orchestrator.exception.http.NotFoundException;
import it.reply.workflowmanager.exceptions.WorkflowException;
Expand Down Expand Up @@ -90,9 +91,6 @@ public Deployment createDeployment(DeploymentRequest request) {

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!!)
Expand All @@ -117,7 +115,8 @@ public Deployment createDeployment(DeploymentRequest request) {
Map<String, Object> params = new HashMap<>();
params.put("DEPLOYMENT_ID", deployment.getId());

// FIXME: Temporary - just for test
// FIXME: Define function to decide DeploymentProvider (Temporary - just for prototyping)
isChronosDeployment = isChronosDeployment(nodes);
params.put(WF_PARAM_DEPLOYMENT_TYPE,
(isChronosDeployment ? DEPLOYMENT_TYPE_CHRONOS : DEPLOYMENT_TYPE_TOSCA));

Expand Down Expand Up @@ -205,22 +204,25 @@ public void deleteDeployment(String uuid) {
public void updateDeployment(String id, DeploymentRequest request) {
Deployment deployment = deploymentRepository.findOne(id);
if (deployment != null) {

if (deployment.getDeploymentProvider() == DeploymentProvider.CHRONOS) {
// Chronos deployments cannot be updated
throw new BadRequestException("Chronos deployments cannot be updated.");
}

if (deployment.getStatus() == Status.CREATE_COMPLETE
|| deployment.getStatus() == Status.UPDATE_COMPLETE
|| deployment.getStatus() == Status.UPDATE_FAILED) {
try {
// Check if the new template is valid
ParsingResult<ArchiveRoot> parsingResult =
toscaService.getArchiveRootFromTemplate(request.getTemplate());
toscaService.getArchiveRootFromTemplate(request.getTemplate());

} catch (ParsingException | IOException ex) {
throw new OrchestratorException(ex);
}
deployment.setStatus(Status.UPDATE_IN_PROGRESS);
deployment.setTask(Task.NONE);

Iterator<WorkflowReference> wrIt = deployment.getWorkflowReferences().iterator();

deployment = deploymentRepository.save(deployment);

Map<String, Object> params = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public void finalizeUndeploy(Deployment deployment, boolean undeployed) {
* @return <tt>true</tt> if all jobs have been deleted, <tt>false</tt> otherwise.
*/
public boolean doUndeploy(Deployment deployment) {
// TODO Delete all Jobs on Chronos
// Delete all Jobs on Chronos

try {
// Generate INDIGOJob graph
Expand Down

0 comments on commit 6bb3dbb

Please sign in to comment.