diff options
author | sebdet <sebastien.determe@intl.att.com> | 2019-04-10 14:07:35 +0200 |
---|---|---|
committer | sebdet <sebastien.determe@intl.att.com> | 2019-04-10 14:07:35 +0200 |
commit | cd64cc4b390a15602e084d0d94007ec83aa530a4 (patch) | |
tree | c928f5bc4f9e7b12b2955ec880e69d850cea3073 /src/main/java/org | |
parent | 9342b6c9ea3dd02feb9e1d8acc81e5b50c66f1e2 (diff) |
Add delete support
Move delete code to Camel way so that it's more flexible + introduce
removal of the loop + test
Issue-ID: CLAMP-315
Change-Id: I7df87e1441d4511ad6b42d0d269c3b2c8c7d8eef
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/onap/clamp/loop/LoopOperation.java | 160 | ||||
-rw-r--r-- | src/main/java/org/onap/clamp/loop/LoopService.java | 4 | ||||
-rw-r--r-- | src/main/java/org/onap/clamp/loop/log/LoopLogService.java | 4 |
3 files changed, 8 insertions, 160 deletions
diff --git a/src/main/java/org/onap/clamp/loop/LoopOperation.java b/src/main/java/org/onap/clamp/loop/LoopOperation.java index 5b55ab0d..d9ea2487 100644 --- a/src/main/java/org/onap/clamp/loop/LoopOperation.java +++ b/src/main/java/org/onap/clamp/loop/LoopOperation.java @@ -31,7 +31,6 @@ import com.google.gson.JsonNull; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; -import java.io.IOException; import java.lang.reflect.Array; import java.util.Collection; import java.util.Date; @@ -213,163 +212,4 @@ public class LoopOperation { return new JsonPrimitive(String.valueOf(o)); } - /** - * Submit the Ms policies. - * - * @param loopName - * the loop name - * @return the updated loop - * @throws IOException - * IO exception - * @throws Exceptions - * during the operation - */ - public Loop submitMsPolicies(String loopName) throws OperationException, IOException { - util.entering(request, "LoopOperation: delete microservice policies"); - Date startTime = new Date(); - Loop loop = loopService.getLoop(loopName); - - if (loop == null) { - String msg = "Submit MS policies exception: Not able to find closed loop:" + loopName; - util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), msg, Level.INFO, - ONAPLogConstants.ResponseStatus.ERROR); - throw new OperationException(msg); - } - - // verify the current closed loop state - if (loop.getLastComputedState() != LoopState.SUBMITTED && loop.getLastComputedState() != LoopState.DESIGN) { - String msg = "Submit MS policies exception: This closed loop is in state:" + loop.getLastComputedState() - + ". It could be deleted only when it is in SUBMITTED state."; - util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO, ONAPLogConstants.ResponseStatus.ERROR); - throw new OperationException(msg); - } - - // Establish the api call to Policy to create the ms services - // policyOp.createMsPolicy(loop.getMicroServicePolicies()); - - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("Deletion of MS policies completed"); - util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return loop; - } - - /** - * Delete the Ms policies. - * - * @param loopName - * the loop name - * @return the updated loop - * @throws IOException - * IO exception - * @throws Exceptions - * during the operation - */ - public Loop deleteMsPolicies(Exchange camelExchange, String loopName) throws OperationException, IOException { - util.entering(request, "LoopOperation: delete microservice policies"); - Date startTime = new Date(); - Loop loop = loopService.getLoop(loopName); - - if (loop == null) { - String msg = "Delete MS policies exception: Not able to find closed loop:" + loopName; - util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), msg, Level.INFO, - ONAPLogConstants.ResponseStatus.ERROR); - throw new OperationException(msg); - } - - // verify the current closed loop state - if (loop.getLastComputedState() != LoopState.SUBMITTED) { - String msg = "Delete MS policies exception: This closed loop is in state:" + loop.getLastComputedState() - + ". It could be deleted only when it is in SUBMITTED state."; - util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO, ONAPLogConstants.ResponseStatus.ERROR); - throw new OperationException(msg); - } - - // Establish the api call to Policy to create the ms services - // policyOp.deleteMsPolicy(loop.getMicroServicePolicies()); - - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("Deletion of MS policies completed"); - util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return loop; - } - - /** - * Delete the operational policy. - * - * @param loopName - * the loop name - * @return the updated loop - * @throws Exceptions - * during the operation - */ - public Loop deleteOpPolicy(Exchange camelExchange, String loopName) throws OperationException { - util.entering(request, "LoopOperation: delete guard policy"); - Date startTime = new Date(); - Loop loop = loopService.getLoop(loopName); - - if (loop == null) { - String msg = "Delete guard policy exception: Not able to find closed loop:" + loopName; - util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), msg, Level.INFO, - ONAPLogConstants.ResponseStatus.ERROR); - throw new OperationException(msg); - } - - // verify the current closed loop state - if (loop.getLastComputedState() != LoopState.SUBMITTED) { - String msg = "Delete MS policies exception: This closed loop is in state:" + loop.getLastComputedState() - + ". It could be deleted only when it is in SUBMITTED state."; - util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO, ONAPLogConstants.ResponseStatus.ERROR); - throw new OperationException(msg); - } - - // Establish the api call to Policy to delete operational policy - // client.deleteOpPolicy(); - - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("Deletion of Guard policy completed"); - util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return loop; - } - - /** - * Delete the Guard policy. - * - * @param loopName - * the loop name - * @return the updated loop - * @throws Exceptions - * during the operation - */ - public Loop deleteGuardPolicy(Exchange camelExchange, String loopName) throws OperationException { - util.entering(request, "LoopOperation: delete operational policy"); - Date startTime = new Date(); - Loop loop = loopService.getLoop(loopName); - - if (loop == null) { - String msg = "Delete operational policy exception: Not able to find closed loop:" + loopName; - util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), msg, Level.INFO, - ONAPLogConstants.ResponseStatus.ERROR); - throw new OperationException(msg); - } - - // verify the current closed loop state - if (loop.getLastComputedState() != LoopState.SUBMITTED) { - String msg = "Delete MS policies exception: This closed loop is in state:" + loop.getLastComputedState() - + ". It could be deleted only when it is in SUBMITTED state."; - util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO, ONAPLogConstants.ResponseStatus.ERROR); - throw new OperationException(msg); - } - - // Establish the api call to Policy to delete Guard policy - // client.deleteOpPolicy(); - - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("Deletion of operational policy completed"); - util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return loop; - } } diff --git a/src/main/java/org/onap/clamp/loop/LoopService.java b/src/main/java/org/onap/clamp/loop/LoopService.java index 8d61b877..4c139225 100644 --- a/src/main/java/org/onap/clamp/loop/LoopService.java +++ b/src/main/java/org/onap/clamp/loop/LoopService.java @@ -67,6 +67,10 @@ public class LoopService { return loopsRepository.findById(loopName).orElse(null); } + public void deleteLoop(String loopName) { + loopsRepository.deleteById(loopName); + } + Loop updateAndSaveOperationalPolicies(String loopName, List<OperationalPolicy> newOperationalPolicies) { Loop loop = findClosedLoopByName(loopName); Set<OperationalPolicy> newPolicies = operationalPolicyService.updatePolicies(loop, newOperationalPolicies); diff --git a/src/main/java/org/onap/clamp/loop/log/LoopLogService.java b/src/main/java/org/onap/clamp/loop/log/LoopLogService.java index b593b41e..b02bc11c 100644 --- a/src/main/java/org/onap/clamp/loop/log/LoopLogService.java +++ b/src/main/java/org/onap/clamp/loop/log/LoopLogService.java @@ -40,4 +40,8 @@ public class LoopLogService { public void addLog(String message, String logType, Loop loop) { repository.save(new LoopLog(message, LogType.valueOf(logType), loop)); } + + public boolean isExisting(Long logId) { + return repository.existsById(logId); + } } |