aboutsummaryrefslogtreecommitdiffstats
path: root/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/CloudifyController.java
diff options
context:
space:
mode:
Diffstat (limited to 'ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/CloudifyController.java')
-rw-r--r--ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/CloudifyController.java2013
1 files changed, 1376 insertions, 637 deletions
diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/CloudifyController.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/CloudifyController.java
index 7b05841..d7cdc6f 100644
--- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/CloudifyController.java
+++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/CloudifyController.java
@@ -1,637 +1,1376 @@
-/*******************************************************************************
- * =============LICENSE_START=========================================================
- *
- * =================================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *******************************************************************************/
-package org.onap.ccsdk.dashboard.controller;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.onap.ccsdk.dashboard.model.CloudifyDeploymentList;
-import org.onap.ccsdk.dashboard.model.CloudifyExecutionRequest;
-import org.onap.ccsdk.dashboard.exception.DashboardControllerException;
-import org.onap.ccsdk.dashboard.model.CloudifyBlueprint;
-import org.onap.ccsdk.dashboard.model.CloudifyBlueprintUpload;
-import org.onap.ccsdk.dashboard.model.CloudifyDeployment;
-import org.onap.ccsdk.dashboard.model.CloudifyDeploymentRequest;
-import org.onap.ccsdk.dashboard.model.CloudifyExecution;
-import org.onap.ccsdk.dashboard.model.CloudifyExecutionList;
-import org.onap.ccsdk.dashboard.model.ECTransportModel;
-import org.onap.ccsdk.dashboard.model.RestResponseError;
-import org.onap.ccsdk.dashboard.model.RestResponsePage;
-import org.onap.ccsdk.dashboard.rest.IControllerRestClient;
-import org.onap.portalsdk.core.domain.User;
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.onap.portalsdk.core.util.SystemProperties;
-import org.onap.portalsdk.core.web.support.UserUtils;
-import org.slf4j.MDC;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.client.HttpStatusCodeException;
-
-/**
- * Controller for Cloudify features: blueprints, deployments, executions.
- * Methods serve Ajax requests made by Angular scripts on pages that show
- * content.
- */
-@Controller
-@RequestMapping("/")
-public class CloudifyController extends DashboardRestrictedBaseController {
-
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CloudifyController.class);
-
- /**
- * Enum for selecting an item type.
- */
- public enum CloudifyDataItem {
- BLUEPRINT, DEPLOYMENT, EXECUTION;
- }
-
- private static final String BLUEPRINTS_PATH = "blueprints";
- private static final String VIEW_BLUEPRINTS_PATH = "viewblueprints";
- private static final String DEPLOYMENTS_PATH = "deployments";
- private static final String EXECUTIONS_PATH = "executions";
-
- /**
- * Supports sorting blueprints by ID
- */
- private static Comparator<CloudifyBlueprint> blueprintComparator = Comparator.comparing(o -> o.id);
-
- /**
- * Supports sorting deployments by ID
- */
- private static Comparator<CloudifyDeployment> deploymentComparator = Comparator.comparing(o -> o.id);
-
- /**
- * Supports sorting executions by ID
- */
- private static Comparator<CloudifyExecution> executionComparator = Comparator.comparing(o -> o.id);
-
- /**
- * Gets one page of objects and supporting information via the REST client.
- * On success, returns a PaginatedRestResponse object as String.
- *
- * @param option
- * Specifies which item list type to get
- * @param pageNum
- * Page number of results
- * @param pageSize
- * Number of items per browser page
- * @return JSON block as String, see above.
- * @throws DashboardControllerException
- * On any error; e.g., Network failure.
- */
- @SuppressWarnings({"rawtypes", "unchecked"})
- private String getItemListForPage(long userId, CloudifyDataItem option, int pageNum, int pageSize)
- throws DashboardControllerException, JsonProcessingException {
- IControllerRestClient restClient = getControllerRestClient(userId);
- List itemList;
- switch (option) {
- case BLUEPRINT:
- itemList = restClient.getBlueprints().items;
- itemList.sort(blueprintComparator);
- break;
- case DEPLOYMENT:
- itemList = restClient.getDeployments().items;
- itemList.sort(deploymentComparator);
- break;
- default:
- throw new DashboardControllerException(
- "getItemListForPage failed: unimplemented case: " + option.name());
- }
-
- // Shrink if needed
- final int totalItems = itemList.size();
- final int pageCount = (int) Math.ceil((double) totalItems / pageSize);
- if (totalItems > pageSize) {
- itemList = getPageOfList(pageNum, pageSize, itemList);
- }
- RestResponsePage<List> model = new RestResponsePage<>(totalItems, pageCount, itemList);
- return objectMapper.writeValueAsString(model);
- }
-
- /**
- * Gets one page of the specified items. This method traps exceptions and
- * constructs an appropriate JSON block to report errors.
- *
- * @param request
- * Inbound request
- * @param option
- * Item type to get
- * @return JSON with one page of objects; or an error.
- */
- protected String getItemListForPageWrapper(HttpServletRequest request, CloudifyDataItem option) {
- String outboundJson = null;
- try {
- User appUser = UserUtils.getUserSession(request);
- if (appUser == null || appUser.getLoginId() == null || appUser.getLoginId().length() == 0) {
- throw new DashboardControllerException("getItemListForPageWrapper: Failed to get application user");
- }
- int pageNum = getRequestPageNumber(request);
- int pageSize = getRequestPageSize(request);
- outboundJson = getItemListForPage(appUser.getId(), option, pageNum, pageSize);
- } catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "getItemListForPageWrapper caught exception", ex);
- RestResponseError result;
- if (ex instanceof HttpStatusCodeException) {
- result = new RestResponseError(((HttpStatusCodeException) ex).getResponseBodyAsString());
- } else {
- result = new RestResponseError("Failed to get " + option.name(), ex);
- }
- try {
- outboundJson = objectMapper.writeValueAsString(result);
- } catch (JsonProcessingException jpe) {
- // Should never, ever happen
- outboundJson = "{ \"error\" : \"" + jpe.toString() + "\"}";
- }
- }
- return outboundJson;
- }
-
- /**
- * Serves one page of blueprints
- *
- * @param request
- * HttpServletRequest
- * @return List of CloudifyBlueprint objects
- */
- @RequestMapping(value = {BLUEPRINTS_PATH}, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getBlueprintsByPage(HttpServletRequest request) {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- String json = getItemListForPageWrapper(request, CloudifyDataItem.BLUEPRINT);
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return json;
- }
-
- /**
- * Serves one page of deployments
- *
- * @param request
- * HttpServletRequest
- * @return List of CloudifyDeployment objects
- */
- @RequestMapping(value = {DEPLOYMENTS_PATH}, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getDeploymentsByPage(HttpServletRequest request) {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- String json = getItemListForPageWrapper(request, CloudifyDataItem.DEPLOYMENT);
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return json;
- }
-
- /**
- * Gets the specified blueprint metadata.
- *
- * @param id
- * Blueprint ID
- * @param request
- * HttpServletRequest
- * @return Blueprint as JSON; or error.
- * @throws JsonProcessingException
- * on serialization error
- *
- */
- @RequestMapping(value = {BLUEPRINTS_PATH + "/{id}"}, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getBlueprintById(@PathVariable("id") String id, HttpServletRequest request)
- throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.getBlueprint(id);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("getBlueprintById failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
-
- /**
- * Gets the specified blueprint content for viewing.
- *
- * @param id
- * Blueprint ID
- * @param request
- * HttpServletRequest
- * @return Blueprint as YAML; or error.
- * @throws JsonProcessingException
- * on serialization error
- *
- */
- @RequestMapping(value = {
- VIEW_BLUEPRINTS_PATH + "/{id}"}, method = RequestMethod.GET, produces = "application/yaml")
- @ResponseBody
- public String viewBlueprintContentById(@PathVariable("id") String id, HttpServletRequest request)
- throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.viewBlueprint(id);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("getBlueprintContentById failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
-
- /**
- * Processes request to upload a blueprint from a remote server.
- *
- * @param request
- * HttpServletRequest
- * @param blueprint
- * Cloudify blueprint
- * @return Blueprint as uploaded; or error.
- * @throws JsonProcessingException
- * on serialization error
- */
- @RequestMapping(value = {BLUEPRINTS_PATH}, method = RequestMethod.POST, produces = "application/json")
- @ResponseBody
- public String uploadBlueprint(HttpServletRequest request, @RequestBody CloudifyBlueprintUpload blueprint)
- throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.uploadBlueprint(blueprint);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("uploadBlueprint failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
-
- /**
- * Deletes the specified blueprint.
- *
- * @param id
- * Blueprint ID
- * @param request
- * HttpServletRequest
- * @param response
- * HttpServletResponse
- * @return No content on success; error on failure.
- * @throws JsonProcessingException
- * On serialization failure
- */
- @RequestMapping(value = {BLUEPRINTS_PATH + "/{id}"}, method = RequestMethod.DELETE, produces = "application/json")
- @ResponseBody
- public String deleteBlueprint(@PathVariable("id") String id, HttpServletRequest request,
- HttpServletResponse response) throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- int code = restClient.deleteBlueprint(id);
- response.setStatus(code);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("deleteBlueprint failed on ID " + id, t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- if (result == null) {
- return null;
- } else {
- return objectMapper.writeValueAsString(result);
- }
- }
-
- /**
- * Gets the specified deployment.
- *
- * @param id
- * Deployment ID
- * @param request
- * HttpServletRequest
- * @return Deployment for the specified ID; error on failure.
- * @throws JsonProcessingException
- * On serialization failure
- *
- */
- @RequestMapping(value = {DEPLOYMENTS_PATH + "/{id}"}, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getDeploymentById(@PathVariable("id") String id, HttpServletRequest request)
- throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.getDeployment(id);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("getDeploymentById failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
-
- /**
- * Processes request to create a deployment based on a blueprint.
- *
- * @param request
- * HttpServletRequest
- * @param deployment
- * Deployment to upload
- * @return Body of deployment; error on failure
- * @throws JsonProcessingException
- * On serialization failure
- */
- @RequestMapping(value = {DEPLOYMENTS_PATH}, method = RequestMethod.POST, produces = "application/json")
- @ResponseBody
- public String createDeployment(HttpServletRequest request, @RequestBody CloudifyDeploymentRequest deployment)
- throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.createDeployment(deployment);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("createDeployment failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
-
- /**
- * Deletes the specified deployment.
- *
- * @param id
- * Deployment ID
- * @param ignoreLiveNodes
- * Boolean indicator whether to force a delete in case of live
- * nodes
- * @param request
- * HttpServletRequest
- * @param response
- * HttpServletResponse
- * @return Passes through HTTP status code from remote endpoint; no body on
- * success
- * @throws JsonProcessingException
- * on serialization failure
- */
- @RequestMapping(value = {
- DEPLOYMENTS_PATH + "/{id}"}, method = RequestMethod.DELETE, produces = "application/json")
- @ResponseBody
- public String deleteDeployment(@PathVariable("id") String id,
- @RequestParam(value = "ignore_live_nodes", required = false) Boolean ignoreLiveNodes,
- HttpServletRequest request, HttpServletResponse response) throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- int code = restClient.deleteDeployment(id, ignoreLiveNodes == null ? false : ignoreLiveNodes);
- response.setStatus(code);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("deleteDeployment failed on ID " + id, t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- if (result == null) {
- return null;
- } else {
- return objectMapper.writeValueAsString(result);
- }
- }
-
- /**
- * Gets and serves one page of executions:
- * <OL>
- * <LI>Gets all deployments; OR uses the specified deployment ID if the
- * query parameter is present
- * <LI>Gets executions for each deployment ID
- * <LI>Sorts by execution ID
- * <LI>Reduces the list to the page size (if needed)
- * <LI>If the optional request parameter "status" is present, reduces the
- * list to the executions with that status.
- * </OL>
- *
- * @param request
- * HttpServletRequest
- * @param deployment_id
- * Optional request parameter; if found, only executions for that
- * deployment ID are returned.
- * @param status
- * Optional request parameter; if found, only executions with
- * that status are returned.
- * @return List of CloudifyExecution objects
- * @throws JsonProcessingException
- * on serialization failure
- */
- @SuppressWarnings("unchecked")
- @RequestMapping(value = {EXECUTIONS_PATH}, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getExecutionsByPage(HttpServletRequest request,
- @RequestParam(value = "deployment_id", required = false) String deployment_id,
- @RequestParam(value = "status", required = false) String status) throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- List<CloudifyExecution> itemList = new ArrayList<>();
- IControllerRestClient restClient = getControllerRestClient(request);
- List<String> depIds = new ArrayList<>();
- if (deployment_id == null) {
- CloudifyDeploymentList depList = restClient.getDeployments();
- for (CloudifyDeployment cd : depList.items) {
- depIds.add(cd.id);
- }
- } else {
- depIds.add(deployment_id);
- }
- for (String depId : depIds) {
- CloudifyExecutionList exeList = restClient.getExecutions(depId);
- itemList.addAll(exeList.items);
- }
- // Filter down to specified status as needed
- if (status != null) {
- itemList.removeIf(ce -> !status.equals(ce.status));
- }
- itemList.sort(executionComparator);
-
- // Paginate
- final int pageNum = getRequestPageNumber(request);
- final int pageSize = getRequestPageSize(request);
- final int totalItems = itemList.size();
- final int pageCount = (int) Math.ceil((double) totalItems / pageSize);
- // Shrink if needed
- if (totalItems > pageSize) {
- itemList = getPageOfList(pageNum, pageSize, itemList);
- }
- result = new RestResponsePage<>(totalItems, pageCount, itemList);
- } catch (Exception t) {
- result = new RestResponseError("getExecutionsByPage failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
-
- /**
- * Gets the specified execution for one deployment.
- *
- * It's not clear why the deployment ID is needed.
- *
- * @param execution_id
- * Execution ID (path variable)
- * @param deployment_id
- * Deployment ID (query parameter)
- * @param request
- * HttpServletRequest
- * @return CloudifyExecutionList
- * @throws JsonProcessingException
- * on serialization failure
- */
- @RequestMapping(value = {EXECUTIONS_PATH + "/{id}"}, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getExecutionByIdAndDeploymentId(@PathVariable("id") String execution_id,
- @RequestParam("deployment_id") String deployment_id, HttpServletRequest request)
- throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.getExecutions(deployment_id);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("getExecutionByIdAndDeploymentId failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
-
- /**
- * Processes request to create an execution based on a deployment.
- *
- * @param request
- * HttpServletRequest
- * @param execution
- * Execution model
- * @return Information about the execution
- * @throws JsonProcessingException
- * on serialization failure
- */
- @RequestMapping(value = {EXECUTIONS_PATH}, method = RequestMethod.POST, produces = "application/json")
- @ResponseBody
- public String startExecution(HttpServletRequest request, @RequestBody CloudifyExecutionRequest execution)
- throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.startExecution(execution);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("startExecution failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
-
- /**
- * Cancels an execution.
- *
- * @param id
- * Execution ID
- * @param deploymentId
- * Deployment ID (not clear why this is needed)
- * @param action
- * Action to perform (not clear why this is needed)
- * @param request
- * HttpServletRequest
- * @param response
- * HttpServletRequest
- * @return Passes through HTTP status code from remote endpoint; no body on success
- * @throws JsonProcessingException
- * on serialization failure
- */
- @RequestMapping(value = {EXECUTIONS_PATH + "/{id}"}, method = RequestMethod.DELETE, produces = "application/json")
- @ResponseBody
- public String cancelExecution(@PathVariable("id") String id,
- @RequestParam(value = "deployment_id") String deploymentId, @RequestParam(value = "action") String action,
- HttpServletRequest request, HttpServletResponse response) throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- int code = restClient.cancelExecution(id, deploymentId, action);
- response.setStatus(code);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("cancelExecution failed on ID " + id, t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- if (result == null) {
- return null;
- } else {
- return objectMapper.writeValueAsString(result);
- }
- }
-}
+/*******************************************************************************
+ * =============LICENSE_START=========================================================
+ *
+ * =================================================================================
+ * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *******************************************************************************/
+package org.onap.ccsdk.dashboard.controller;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.onap.ccsdk.dashboard.model.CloudifyBlueprint;
+import org.onap.ccsdk.dashboard.model.CloudifyBlueprintList;
+import org.onap.ccsdk.dashboard.model.CloudifyBlueprintUpload;
+import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenant;
+import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenantList;
+import org.onap.ccsdk.dashboard.model.CloudifyDeployment;
+import org.onap.ccsdk.dashboard.model.CloudifyDeploymentList;
+import org.onap.ccsdk.dashboard.model.CloudifyDeploymentRequest;
+import org.onap.ccsdk.dashboard.model.CloudifyDeploymentUpdateRequest;
+import org.onap.ccsdk.dashboard.model.CloudifyEvent;
+import org.onap.ccsdk.dashboard.model.CloudifyEventList;
+import org.onap.ccsdk.dashboard.model.CloudifyExecution;
+import org.onap.ccsdk.dashboard.model.CloudifyExecutionList;
+import org.onap.ccsdk.dashboard.model.CloudifyExecutionRequest;
+import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceIdList;
+import org.onap.ccsdk.dashboard.model.CloudifyTenant;
+import org.onap.ccsdk.dashboard.model.ECTransportModel;
+import org.onap.ccsdk.dashboard.model.RestResponseError;
+import org.onap.ccsdk.dashboard.model.RestResponsePage;
+import org.onap.ccsdk.dashboard.rest.CloudifyClient;
+import org.onap.ccsdk.dashboard.util.DashboardProperties;
+import org.onap.portalsdk.core.domain.User;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.portalsdk.core.web.support.UserUtils;
+import org.slf4j.MDC;
+import org.springframework.http.HttpHeaders;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.client.HttpStatusCodeException;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+/**
+ * Controller for Cloudify features: blueprints, deployments, executions.
+ * Methods serve Ajax requests made by Angular scripts on pages that show
+ * content.
+ */
+@Controller
+@RequestMapping("/")
+public class CloudifyController extends DashboardRestrictedBaseController {
+
+ private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CloudifyController.class);
+ private CloudifyClient restClient;
+
+ /**
+ * Enum for selecting an item type.
+ */
+ public enum CloudifyDataItem {
+ BLUEPRINT, DEPLOYMENT, EXECUTION, TENANT;
+ }
+
+ private static Date begin;
+ private static Date end;
+ private static final String BLUEPRINTS_PATH = "blueprints";
+ private static final String VIEW_BLUEPRINTS_PATH = "viewblueprints";
+ private static final String DEPLOYMENTS_PATH = "deployments";
+ private static final String EXECUTIONS_PATH = "executions";
+ private static final String TENANTS_PATH = "tenants";
+ private static final String NODE_INSTANCES_PATH = "node-instances";
+ private static final String UPDATE_DEPLOYMENT_PATH = "update-deployment";
+ private static final String SECRETS_PATH = "secrets";
+ private static final String EVENTS_PATH = "events";
+ private static final String DEP_TENANT_STATUS = "deployment-status";
+
+ /**
+ * Supports sorting blueprints by ID
+ */
+ private static Comparator<CloudifyBlueprint> blueprintComparator = new Comparator<CloudifyBlueprint>() {
+ @Override
+ public int compare(CloudifyBlueprint o1, CloudifyBlueprint o2) {
+ return o1.id.compareTo(o2.id);
+ }
+ };
+
+ /**
+ * Supports sorting deployments by ID
+ */
+ private static Comparator<CloudifyDeployment> deploymentComparator = new Comparator<CloudifyDeployment>() {
+ @Override
+ public int compare(CloudifyDeployment o1, CloudifyDeployment o2) {
+ return o1.id.compareTo(o2.id);
+ }
+ };
+
+ /**
+ * Supports sorting events by timestamp
+ */
+ private static Comparator<CloudifyEvent> eventComparator = new Comparator<CloudifyEvent>() {
+ @Override
+ public int compare(CloudifyEvent o1, CloudifyEvent o2) {
+ return o1.reported_timestamp.compareTo(o2.reported_timestamp);
+ }
+ };
+
+ /**
+ * Supports sorting executions by timestamp
+ */
+ private static Comparator<CloudifyExecution> executionComparator = new Comparator<CloudifyExecution>() {
+ @Override
+ public int compare(CloudifyExecution o1, CloudifyExecution o2) {
+ return o1.created_at.compareTo(o2.created_at);
+ }
+ };
+ /**
+ * Gets one page of objects and supporting information via the REST client.
+ * On success, returns a PaginatedRestResponse object as String.
+ *
+ * @param option
+ * Specifies which item list type to get
+ * @param pageNum
+ * Page number of results
+ * @param pageSize
+ * Number of items per browser page
+ * @return JSON block as String, see above.
+ * @throws Exception
+ * On any error; e.g., Network failure.
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private String getItemListForPage(long userId, CloudifyDataItem option, int pageNum, int pageSize)
+ throws Exception {
+ if (this.restClient == null) {
+ this.restClient = getCloudifyRestClient(userId);
+ }
+ List itemList = null;
+ switch (option) {
+ /*
+ case BLUEPRINT:
+ itemList = restClient.getBlueprints().items;
+ Collections.sort(itemList, blueprintComparator);
+ break;
+ case DEPLOYMENT:
+ itemList = restClient.getDeployments().items;
+ Collections.sort(itemList, deploymentComparator);
+ break;
+ */
+ case TENANT:
+ itemList = restClient.getTenants().items;
+ break;
+ default:
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting page of items failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getItemListForPage caught exception");
+ throw new Exception("getItemListForPage failed: unimplemented case: " + option.name());
+ }
+/*
+ String cloudPrimTenant =
+ getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM);
+ String aicPrimTenant =
+ getAppProperties().getProperty(DashboardProperties.AIC_TENANT_PRIM);
+
+ for (CloudifyTenant ct: (List<CloudifyTenant>)itemList) {
+ if ( ct.name.equals(cloudPrimTenant) ) {
+ ct.dName = aicPrimTenant;
+ } else {
+ ct.dName = ct.name;
+ }
+ }
+ */
+ // Shrink if needed
+ final int totalItems = itemList.size();
+ final int pageCount = (int) Math.ceil((double) totalItems / pageSize);
+ if (totalItems > pageSize)
+ itemList = getPageOfList(pageNum, pageSize, itemList);
+ RestResponsePage<List> model = new RestResponsePage<>(totalItems, pageCount, itemList);
+ String outboundJson = objectMapper.writeValueAsString(model);
+ return outboundJson;
+ }
+
+ /**
+ * Gets one page of the specified items. This method traps exceptions and
+ * constructs an appropriate JSON block to report errors.
+ *
+ * @param request
+ * Inbound request
+ * @param option
+ * Item type to get
+ * @return JSON with one page of objects; or an error.
+ */
+ protected String getItemListForPageWrapper(HttpServletRequest request, CloudifyDataItem option) {
+ String outboundJson = null;
+ try {
+ User appUser = UserUtils.getUserSession(request);
+ if (appUser == null || appUser.getLoginId() == null || appUser.getLoginId().length() == 0)
+ throw new Exception("getItemListForPageWrapper: Failed to get application user");
+ int pageNum = getRequestPageNumber(request);
+ int pageSize = getRequestPageSize(request);
+ outboundJson = getItemListForPage(appUser.getId(), option, pageNum, pageSize);
+ } catch (Exception ex) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting page of items failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getItemListForPageWrapper caught exception");
+ RestResponseError result = null;
+ if (ex instanceof HttpStatusCodeException)
+ result = new RestResponseError(((HttpStatusCodeException) ex).getResponseBodyAsString());
+ else
+ result = new RestResponseError("Failed to get " + option.name(), ex);
+ try {
+ outboundJson = objectMapper.writeValueAsString(result);
+ } catch (JsonProcessingException jpe) {
+ // Should never, ever happen
+ outboundJson = "{ \"error\" : \"" + jpe.toString() + "\"}";
+ }
+ }
+ return outboundJson;
+ }
+
+ /**
+ * Serves one page of blueprints
+ *
+ * @param request
+ * HttpServletRequest
+ * @return List of CloudifyBlueprint objects
+ */
+ @RequestMapping(value = { BLUEPRINTS_PATH }, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getBlueprintsByPage(HttpServletRequest request) {
+ preLogAudit(request);
+ String json = getItemListForPageWrapper(request, CloudifyDataItem.BLUEPRINT);
+ postLogAudit(request);
+ return json;
+ }
+
+ /**
+ * Serves one page of deployments
+ *
+ * @param request
+ * HttpServletRequest
+ * @return List of CloudifyDeployment objects
+ */
+ @RequestMapping(value = { DEPLOYMENTS_PATH }, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getDeploymentsByPage(HttpServletRequest request) {
+ preLogAudit(request);
+ String json = getItemListForPageWrapper(request, CloudifyDataItem.DEPLOYMENT);
+ postLogAudit(request);
+ return json;
+ }
+
+ /**
+ * gets the tenants list
+ *
+ * @param request
+ * HttpServletRequest
+ * @return List of CloudifyDeployment objects
+ */
+ @RequestMapping(value = { TENANTS_PATH }, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getTenants(HttpServletRequest request) {
+ preLogAudit(request);
+ String json = getItemListForPageWrapper(request, CloudifyDataItem.TENANT);
+ postLogAudit(request);
+ return json;
+ }
+
+ /**
+ * Gets the specified blueprint metadata.
+ *
+ * @param id
+ * Blueprint ID
+ * @param request
+ * HttpServletRequest
+ * @return Blueprint as JSON; or error.
+ * @throws Exception
+ * on serialization error
+ *
+ */
+ @RequestMapping(value = { BLUEPRINTS_PATH + "/{id}" }, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getBlueprintById(@PathVariable("id") String id,
+ @RequestParam(value = "tenant", required = true) String tenant,
+ HttpServletRequest request) throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ try {
+ restClient = getCloudifyRestClient(request);
+ result = restClient.getBlueprint(id, tenant);
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting blueprint " + id + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getBlueprintById caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting blueprint " + id + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getBlueprintById caught exception");
+ result = new RestResponseError("getBlueprintById failed", t);
+ } finally {
+ postLogAudit(request);
+ }
+ return objectMapper.writeValueAsString(result);
+ }
+
+ /**
+ * Gets the specified blueprint content for viewing.
+ *
+ * @param id
+ * Blueprint ID
+ * @param request
+ * HttpServletRequest
+ * @return Blueprint as YAML; or error.
+ * @throws Exception
+ * on serialization error
+ *
+ */
+ @RequestMapping(value = {
+ VIEW_BLUEPRINTS_PATH + "/{id}" }, method = RequestMethod.GET, produces = "application/yaml")
+ @ResponseBody
+ public String viewBlueprintContentById(@PathVariable("id") String id, HttpServletRequest request) throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ try {
+ restClient = getCloudifyRestClient(request);
+ result = restClient.viewBlueprint(id);
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Viewing blueprint " + id + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "viewBlueprintContentById caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Viewing blueprint " + id + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "viewBlueprintContentById caught exception");
+ result = new RestResponseError("getBlueprintContentById failed", t);
+ } finally {
+ postLogAudit(request);
+ }
+ return objectMapper.writeValueAsString(result);
+ }
+
+ /**
+ * Processes request to upload a blueprint from a remote server.
+ *
+ * @param request
+ * HttpServletRequest
+ * @param blueprint
+ * Cloudify blueprint
+ * @return Blueprint as uploaded; or error.
+ * @throws Exception
+ * on serialization error
+ */
+ @RequestMapping(value = { BLUEPRINTS_PATH }, method = RequestMethod.POST, produces = "application/json")
+ @ResponseBody
+ public String uploadBlueprint(HttpServletRequest request, @RequestBody CloudifyBlueprintUpload blueprint)
+ throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ try {
+ CloudifyClient restClient = getCloudifyRestClient(request);
+ result = restClient.uploadBlueprint(blueprint);
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Uploading blueprint failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "uploadBlueprint caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Uploading blueprint failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "uploadBlueprint caught exception");
+ result = new RestResponseError("uploadBlueprint failed", t);
+ } finally {
+ postLogAudit(request);
+ }
+ return objectMapper.writeValueAsString(result);
+ }
+
+ /**
+ * Deletes the specified blueprint.
+ *
+ * @param id
+ * Blueprint ID
+ * @param request
+ * HttpServletRequest
+ * @param response
+ * HttpServletResponse
+ * @return No content on success; error on failure.
+ * @throws Exception
+ * On serialization failure
+ */
+ @RequestMapping(value = { BLUEPRINTS_PATH + "/{id}" }, method = RequestMethod.DELETE, produces = "application/json")
+ @ResponseBody
+ public String deleteBlueprint(@PathVariable("id") String id, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ try {
+ CloudifyClient restClient = getCloudifyRestClient(request);
+ int code = restClient.deleteBlueprint(id);
+ response.setStatus(code);
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Deleting blueprint " + id + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "deleteBlueprint caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Deleting blueprint " + id + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "deleteBlueprint caught exception");
+ result = new RestResponseError("deleteBlueprint failed on ID " + id, t);
+ } finally {
+ postLogAudit(request);
+ }
+ if (result == null)
+ return null;
+ else
+ return objectMapper.writeValueAsString(result);
+ }
+
+ /**
+ * Gets the specified deployment.
+ *
+ * @param id
+ * Deployment ID
+ * @param request
+ * HttpServletRequest
+ * @return Deployment for the specified ID; error on failure.
+ * @throws Exception
+ * On serialization failure
+ *
+ */
+ @RequestMapping(value = { DEPLOYMENTS_PATH + "/{id}" }, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getDeploymentById(@PathVariable("id") String id,
+ @RequestParam(value = "tenant", required = false) String tenant,
+ HttpServletRequest request) throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ try {
+ CloudifyClient restClient = getCloudifyRestClient(request);
+ if (tenant != null && tenant.length() > 0) {
+ result = restClient.getDeployment(id, tenant);
+ } else {
+ result = restClient.getDeployment(id);
+ }
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting deployment " + id + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getDeploymentById caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting deployment " + id + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getDeploymentById caught exception");
+ result = new RestResponseError("getDeploymentById failed", t);
+ } finally {
+ postLogAudit(request);
+ }
+ return objectMapper.writeValueAsString(result);
+ }
+
+ /**
+ * Query status and tenant info for deployments
+ *
+ */
+ @SuppressWarnings("unchecked")
+ @RequestMapping(value = { DEP_TENANT_STATUS }, method = RequestMethod.POST, produces = "application/json")
+ @ResponseBody
+ public String getTenantStatusForService( HttpServletRequest request,
+ @RequestBody String[] serviceList)
+ throws Exception {
+ preLogAudit(request);
+ User appUser = UserUtils.getUserSession(request);
+ if (appUser == null || appUser.getId() == null )
+ throw new Exception("getControllerRestClient: Failed to get application user");
+ /*
+ 1) Get all the tenant names
+ 2) Get the deployment IDs per tenant for all the tenants, aggregate the deployments list
+ 3) Get the input deployments list (screen input), filter the deployments list from step#2
+ 4) For each item in the list from step#3, get the execution status info and generate the final response
+ */
+ ECTransportModel result = null;
+ HashMap<String, Object> resultMap = new HashMap<String, Object>();
+ List<CloudifyDeployedTenant> tenantList = new ArrayList<CloudifyDeployedTenant>();
+ List<CloudifyExecution> cfyExecList = new ArrayList<CloudifyExecution>();
+ try {
+ CloudifyClient restClient = getCloudifyRestClient(request);
+ List<CloudifyTenant> cldfyTen = restClient.getTenants().items;
+ for (CloudifyTenant ct: (List<CloudifyTenant>)cldfyTen) {
+ result = restClient.getTenantInfoFromDeploy(ct.name);
+ tenantList.addAll(((CloudifyDeployedTenantList)result).items);
+ }
+ result = null;
+ List<CloudifyDeployedTenant> currSrvcTenants = new ArrayList<CloudifyDeployedTenant>();
+
+ for (String serviceId : serviceList) {
+ for (CloudifyDeployedTenant deplTen: tenantList) {
+ if (serviceId.equals(deplTen.id)) {
+ currSrvcTenants.add(deplTen);
+ break;
+ }
+ }
+ }
+ // Get concise execution status for each of the tenant deployment items
+ boolean isHelmType = false;
+ boolean helmStatus = false;
+ for (CloudifyDeployedTenant deplItem: currSrvcTenants) {
+ CloudifyExecutionList execResults = restClient.getExecutionsSummary(deplItem.id, deplItem.tenant_name);
+ isHelmType = false;
+ helmStatus = false;
+ CloudifyBlueprintList bpList = restClient.getBlueprint(deplItem.id, deplItem.tenant_name);
+ Map<String, Object> bpPlan = bpList.items.get(0).plan;
+ Map<String, String> workflows = (Map<String, String>)bpPlan.get("workflows");
+ Map<String, String> pluginInfo = ((List<Map<String, String>>)bpPlan.get("deployment_plugins_to_install")).get(0);
+ if (pluginInfo.get("name").equals("helm-plugin") ) {
+ isHelmType = true;
+ }
+ if (workflows.containsKey("status")) {
+ helmStatus = true;
+ }
+ /*
+ for (CloudifyExecution cfyExec: execResults.items) {
+ if (cfyExec.workflow_id.equalsIgnoreCase("create_deployment_environment")) {
+ Map<String, String> pluginInfo = ((List<Map<String, String>>)cfyExec.parameters.get("deployment_plugins_to_install")).get(0);
+ if (pluginInfo.get("name").equals("helm-plugin") ) {
+ isHelmType = true;
+ }
+ }
+ }
+ */
+ for (CloudifyExecution cfyExec: execResults.items) {
+ if (cfyExec.workflow_id.equalsIgnoreCase("install")) {
+ cfyExec.is_helm = isHelmType;
+ cfyExec.helm_status = helmStatus;
+ cfyExecList.add(cfyExec);
+ }
+ }
+ }
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting deployments failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getTenantStatusForService caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting deployments failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getTenantStatusForService caught exception");
+ result = new RestResponseError("getTenantStatusForService failed", t);
+ } finally {
+ postLogAudit(request);
+ }
+
+ return objectMapper.writeValueAsString(cfyExecList);
+ }
+
+ /**
+ * Processes request to create a deployment based on a blueprint.
+ *
+ * @param request
+ * HttpServletRequest
+ * @param deployment
+ * Deployment to upload
+ * @return Body of deployment; error on failure
+ * @throws Exception
+ * On serialization failure
+ */
+ @RequestMapping(value = { DEPLOYMENTS_PATH }, method = RequestMethod.POST, produces = "application/json")
+ @ResponseBody
+ public String createDeployment(HttpServletRequest request, @RequestBody CloudifyDeploymentRequest deployment)
+ throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ try {
+ CloudifyClient restClient = getCloudifyRestClient(request);
+ result = restClient.createDeployment(deployment);
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Creating deployment failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "createDeployment caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Creating deployment failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "createDeployment caught exception");
+ result = new RestResponseError("createDeployment failed", t);
+ } finally {
+ postLogAudit(request);
+ }
+ return objectMapper.writeValueAsString(result);
+ }
+
+ /**
+ * Deletes the specified deployment.
+ *
+ * @param id
+ * Deployment ID
+ * @param ignoreLiveNodes
+ * Boolean indicator whether to force a delete in case of live
+ * nodes
+ * @param request
+ * HttpServletRequest
+ * @param response
+ * HttpServletResponse
+ * @return Passes thru HTTP status code from remote endpoint; no body on
+ * success
+ * @throws Exception
+ * on serialization failure
+ */
+ @RequestMapping(value = {
+ DEPLOYMENTS_PATH + "/{id}" }, method = RequestMethod.DELETE, produces = "application/json")
+ @ResponseBody
+ public String deleteDeployment(@PathVariable("id") String id,
+ @RequestParam(value = "ignore_live_nodes", required = false) Boolean ignoreLiveNodes,
+ HttpServletRequest request, HttpServletResponse response) throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ try {
+ CloudifyClient restClient = getCloudifyRestClient(request);
+ int code = restClient.deleteDeployment(id, ignoreLiveNodes == null ? false : ignoreLiveNodes);
+ response.setStatus(code);
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Deleting deployment " + id + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "deleteDeployment caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Deleting deployment " + id + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "deleteDeployment caught exception");
+ result = new RestResponseError("deleteDeployment failed on ID " + id, t);
+ } finally {
+ postLogAudit(request);
+ }
+ if (result == null)
+ return null;
+ else
+ return objectMapper.writeValueAsString(result);
+ }
+
+ /**
+ * Gets and serves one page of executions:
+ * <OL>
+ * <LI>Gets all deployments; OR uses the specified deployment ID if the
+ * query parameter is present
+ * <LI>Gets executions for each deployment ID
+ * <LI>Sorts by execution ID
+ * <LI>Reduces the list to the page size (if needed)
+ * <LI>If the optional request parameter "status" is present, reduces the
+ * list to the executions with that status.
+ * </OL>
+ *
+ * @param request
+ * HttpServletRequest
+ * @param deployment_id
+ * Optional request parameter; if found, only executions for that
+ * deployment ID are returned.
+ * @param status
+ * Optional request parameter; if found, only executions with
+ * that status are returned.
+ * @return List of CloudifyExecution objects
+ * @throws Exception
+ * on serialization failure
+ */
+ @SuppressWarnings("unchecked")
+ @RequestMapping(value = { EXECUTIONS_PATH }, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getExecutionsByPage(HttpServletRequest request,
+ @RequestParam(value = "deployment_id", required = false) String deployment_id,
+ @RequestParam(value = "status", required = false) String status,
+ @RequestParam(value = "tenant", required = false) String tenant) throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ try {
+ List<CloudifyExecution> itemList = new ArrayList<CloudifyExecution>();
+ CloudifyClient restClient = getCloudifyRestClient(request);
+ List<String> depIds = new ArrayList<>();
+ if (deployment_id == null) {
+ CloudifyDeploymentList depList = restClient.getDeployments();
+ for (CloudifyDeployment cd : depList.items)
+ depIds.add(cd.id);
+ } else {
+ depIds.add(deployment_id);
+ }
+ String cloudPrimTenant =
+ getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM);
+ if (tenant == null) {
+ tenant = cloudPrimTenant;
+ }
+ for (String depId : depIds) {
+ CloudifyExecutionList exeList = restClient.getExecutions(depId, tenant);
+ itemList.addAll(exeList.items);
+ }
+ // Filter down to specified status as needed
+ if (status != null) {
+ Iterator<CloudifyExecution> exeIter = itemList.iterator();
+ while (exeIter.hasNext()) {
+ CloudifyExecution ce = exeIter.next();
+ if (!status.equals(ce.status))
+ exeIter.remove();
+ }
+ }
+ Collections.sort(itemList, executionComparator);
+
+ // Paginate
+ final int pageNum = getRequestPageNumber(request);
+ final int pageSize = getRequestPageSize(request);
+ final int totalItems = itemList.size();
+ final int pageCount = (int) Math.ceil((double) totalItems / pageSize);
+ // Shrink if needed
+ if (totalItems > pageSize)
+ itemList = getPageOfList(pageNum, pageSize, itemList);
+ result = new RestResponsePage<>(totalItems, pageCount, itemList);
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting executions failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getExecutionsByPage caught exception");
+ result = new RestResponseError("getExecutionsByPage failed", t);
+ } finally {
+ postLogAudit(request);
+ }
+ return objectMapper.writeValueAsString(result);
+ }
+
+ /**
+ * Gets the specified execution for one deployment.
+ *
+ * It's not clear why the deployment ID is needed.
+ *
+ * @param execution_id
+ * Execution ID (path variable)
+ * @param deployment_id
+ * Deployment ID (query parameter)
+ * @param request
+ * HttpServletRequest
+ * @return CloudifyExecutionList
+ * @throws Exception
+ * on serialization failure
+ */
+ @RequestMapping(value = { EXECUTIONS_PATH + "/{id}" }, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getExecutionByIdAndDeploymentId(@PathVariable("id") String execution_id,
+ @RequestParam("deployment_id") String deployment_id,
+ @RequestParam(value = "tenant", required = false) String tenant,
+ HttpServletRequest request) throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ try {
+ String cloudPrimTenant =
+ getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM);
+ if (tenant == null) {
+ tenant = cloudPrimTenant;
+ }
+ CloudifyClient restClient = getCloudifyRestClient(request);
+ result = restClient.getExecutions(deployment_id, tenant);
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting executions " + execution_id + " for deployment " + deployment_id + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getExecutionByIdAndDeploymentId caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting executions " + execution_id + " for deployment " + deployment_id + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getExecutionByIdAndDeploymentId caught exception");
+ result = new RestResponseError("getExecutionByIdAndDeploymentId failed", t);
+ } finally {
+ postLogAudit(request);
+ }
+ return objectMapper.writeValueAsString(result);
+ }
+
+ /**
+ * Gets the execution events for specified execution ID.
+ *
+ *
+ * @param execution_id
+ * Execution ID (request parameter)
+ * @param tenant
+ * tenant name (query parameter)
+ * @param request
+ * HttpServletRequest
+ * @return CloudifyExecutionList
+ * @throws Exception
+ * on serialization failure
+ */
+ @SuppressWarnings("unchecked")
+ @RequestMapping(value = { EVENTS_PATH }, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getExecutionEventsById(@RequestParam(value = "execution_id", required = false) String execution_id,
+ @RequestParam(value = "logType", required = false) String isLogEvent,
+ @RequestParam(value = "tenant", required = false) String tenant,
+ HttpServletRequest request) throws Exception {
+ preLogAudit(request);
+ CloudifyEventList eventsList = null;
+ ECTransportModel result = null;
+ try {
+ String cloudPrimTenant =
+ getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM);
+ if (tenant == null) {
+ tenant = cloudPrimTenant;
+ }
+ CloudifyClient restClient = getCloudifyRestClient(request);
+ eventsList = restClient.getEventlogs(execution_id, tenant);
+ // Filter down to specified event type as needed
+ List<CloudifyEvent> itemList = eventsList.items;
+ if (!isLogEvent.isEmpty() && isLogEvent.equals("false")) {
+ Iterator<CloudifyEvent> exeIter = itemList.iterator();
+ while (exeIter.hasNext()) {
+ CloudifyEvent ce = exeIter.next();
+ if (ce.type.equals("cloudify_log")) {
+ exeIter.remove();
+ }
+ }
+ }
+ Collections.sort(itemList, eventComparator);
+ Collections.reverse(itemList);
+ final int pageNum = getRequestPageNumber(request);
+ final int pageSize = getRequestPageSize(request);
+ final int totalItems = itemList.size();
+ final int pageCount = (int) Math.ceil((double) totalItems / pageSize);
+ // Shrink if needed
+ if (totalItems > pageSize)
+ itemList = getPageOfList(pageNum, pageSize, itemList);
+ result = new RestResponsePage<>(totalItems, pageCount, itemList);
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting executions " + execution_id + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getExecutionEventsById caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting executions " + execution_id + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getExecutionByIdAndDeploymentId caught exception");
+ result = new RestResponseError("getExecutionEventsById failed", t);
+ } finally {
+ postLogAudit(request);
+ }
+ return objectMapper.writeValueAsString(result);
+ }
+
+ /**
+ * Gets the cloudify secret data for the specified secret name.
+ *
+ *
+ * @param secret_name
+ * Secret name (path variable)
+ * @param request
+ * HttpServletRequest
+ * @return CloudifySecret
+ * @throws Exception
+ * on serialization failure
+ */
+ /*
+ @RequestMapping(value = { SECRETS_PATH }, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getSecrets(
+ @RequestParam(value = "tenant") String tenant,
+ HttpServletRequest request) throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ try {
+ String cloudPrimTenant =
+ getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM);
+ if (tenant == null) {
+ tenant = cloudPrimTenant;
+ }
+ IControllerRestClient restClient = getControllerRestClient();
+ result = restClient.getSecrets(tenant);
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting secrets failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getSecret caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting secrets failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getSecret caught exception");
+ result = new RestResponseError("getSecret failed", t);
+ } finally {
+ postLogAudit(request);
+ }
+ return objectMapper.writeValueAsString(result);
+ }
+
+ /**
+ * Gets the cloudify secret data for the specified secret name.
+ *
+ *
+ * @param secret_name
+ * Secret name (path variable)
+ * @param request
+ * HttpServletRequest
+ * @return CloudifySecret
+ * @throws Exception
+ * on serialization failure
+ */
+ @RequestMapping(value = { SECRETS_PATH + "/{secret_name}"}, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getSecret(@PathVariable("secret_name") String secret_name,
+ @RequestParam(value = "tenant") String tenant,
+ HttpServletRequest request) throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ try {
+ String cloudPrimTenant =
+ getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM);
+ if (tenant == null) {
+ tenant = cloudPrimTenant;
+ }
+ CloudifyClient restClient = getCloudifyRestClient(request);
+ result = restClient.getSecret(secret_name, tenant);
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting secret for name " + secret_name + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getSecret caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting secret for name " + secret_name + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getSecret caught exception");
+ result = new RestResponseError("getSecret failed", t);
+ } finally {
+ postLogAudit(request);
+ }
+ return objectMapper.writeValueAsString(result);
+ }
+
+ /**
+ * Processes request to create secrets in cloudify manager.
+ *
+ * @param request
+ * HttpServletRequest
+ * @param execution
+ * Execution model
+ * @return Information about the execution
+ * @throws Exception
+ * on serialization failure
+ */
+/*
+ @RequestMapping(value = { SECRETS_PATH }, method = RequestMethod.POST, produces = "application/json")
+ @ResponseBody
+ public String createSecret(HttpServletRequest request, @RequestBody CloudifySecretUpload secret)
+ throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ try {
+ IControllerRestClient restClient = getControllerRestClient(request);
+ result = restClient.createSecret(secret);
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Starting execution failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "startExecution caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Starting execution failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "startExecution caught exception");
+ result = new RestResponseError("startExecution failed", t);
+ } finally {
+ postLogAudit(request);
+ }
+ return objectMapper.writeValueAsString(result);
+ }
+ */
+ /**
+ * Processes request to create an execution based on a deployment.
+ *
+ * @param request
+ * HttpServletRequest
+ * @param execution
+ * Execution model
+ * @return Information about the execution
+ * @throws Exception
+ * on serialization failure
+ */
+ @RequestMapping(value = { EXECUTIONS_PATH }, method = RequestMethod.POST, produces = "application/json")
+ @ResponseBody
+ public String startExecution(HttpServletRequest request, @RequestBody CloudifyExecutionRequest execution)
+ throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ try {
+ CloudifyClient restClient = getCloudifyRestClient(request);
+ if (!execution.workflow_id.equals("status") && !execution.getParameters().containsKey("node_instance_id")) {
+ // get the node instance ID for the deployment
+ String nodeInstId = "";
+ CloudifyNodeInstanceIdList nodeInstList =
+ restClient.getNodeInstanceId(execution.getDeployment_id(), execution.getTenant());
+ if (nodeInstList != null) {
+ nodeInstId = nodeInstList.items.get(0).id;
+ }
+ Map<String, Object> inParms = execution.getParameters();
+ inParms.put("node_instance_id", nodeInstId);
+ execution.setParameters(inParms);
+ }
+ result = restClient.startExecution(execution);
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Starting execution failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "startExecution caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Starting execution failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "startExecution caught exception");
+ result = new RestResponseError("startExecution failed", t);
+ } finally {
+ postLogAudit(request);
+ }
+ return objectMapper.writeValueAsString(result);
+ }
+
+ /**
+ * Processes request to create an execution based on a deployment.
+ *
+ * @param request
+ * HttpServletRequest
+ * @param execution
+ * Execution model
+ * @return Information about the execution
+ * @throws Exception
+ * on serialization failure
+ */
+ @RequestMapping(value = { UPDATE_DEPLOYMENT_PATH }, method = RequestMethod.POST, produces = "application/json")
+ @ResponseBody
+ public String updateDeployment(HttpServletRequest request, @RequestBody CloudifyDeploymentUpdateRequest execution)
+ throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ try {
+ CloudifyClient restClient = getCloudifyRestClient(request);
+ result = restClient.updateDeployment(execution);
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Updating deployment failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "updateDeployment caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Updating Deployment failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "updateDeployment caught exception");
+ result = new RestResponseError("updateDeployment failed", t);
+ } finally {
+ postLogAudit(request);
+ }
+ return objectMapper.writeValueAsString(result);
+ }
+
+ /**
+ * Cancels an execution.
+ *
+ * @param id
+ * Execution ID
+ * @param deploymentId
+ * Deployment ID (not clear why this is needed)
+ * @param action
+ * Action to perform (not clear why this is needed)
+ * @param request
+ * HttpServletRequest
+ * @param response
+ * HttpServletRequest
+ * @return Passes thru HTTP status code from remote endpoint; no body on
+ * success
+ * @throws Exception
+ * on serialization failure
+ */
+ @RequestMapping(value = { EXECUTIONS_PATH + "/{id}" }, method = RequestMethod.POST, produces = "application/json")
+ @ResponseBody
+ public String cancelExecution(
+ @RequestHeader HttpHeaders headers,
+ @PathVariable("id") String id,
+ @RequestBody Map<String, String> parameters,
+ HttpServletRequest request, HttpServletResponse response)
+ throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ List<String> tenant = null;
+ try {
+ tenant = headers.get("tenant");
+ CloudifyClient restClient = getCloudifyRestClient(request);
+ result = restClient.cancelExecution(id, parameters, tenant.get(0));
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Cancelling execution " + id + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "cancelExecution caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Cancelling execution " + id + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "cancelExecution caught exception");
+ result = new RestResponseError("cancelExecution failed on ID " + id, t);
+ } finally {
+ postLogAudit(request);
+ }
+ if (result == null)
+ return null;
+ else
+ return objectMapper.writeValueAsString(result);
+ }
+
+ /**
+ * Gets the specified node-instance-id content for viewing.
+ *
+ * @param id
+ * deployment ID
+ * @param id
+ * node ID
+ * @param request
+ * HttpServletRequest
+ * @return Blueprint as YAML; or error.
+ * @throws Exception
+ * on serialization error
+ *
+ */
+ @RequestMapping(value = {
+ NODE_INSTANCES_PATH + "/{deploymentId}/{nodeId}" }, method = RequestMethod.GET, produces = "application/yaml")
+ @ResponseBody
+ public String getNodeInstanceId(@PathVariable("deploymentId") String deploymentId,
+ @RequestParam(value = "tenant", required = true) String tenant,
+ @PathVariable("nodeId") String nodeId, HttpServletRequest request) throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ try {
+ CloudifyClient restClient = getCloudifyRestClient(request);
+ result = restClient.getNodeInstanceId(deploymentId, nodeId, tenant);
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting node-instance-id with deploymentId " + deploymentId + " and nodeId " + nodeId + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getNodeInstanceId caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting node-instance-id with deploymentId " + deploymentId + " and nodeId " + nodeId + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getNodeInstanceId caught exception");
+ result = new RestResponseError("getNodeInstanceId failed", t);
+ } finally {
+ postLogAudit(request);
+ }
+ return objectMapper.writeValueAsString(result);
+ }
+
+ @RequestMapping(value = { DEPLOYMENTS_PATH + "/{deploymentId}/revisions"}, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getDeploymentRevisions(@PathVariable("deploymentId") String deploymentId,
+ @RequestParam(value = "tenant") String tenant,
+ HttpServletRequest request) throws Exception {
+ preLogAudit(request);
+ ECTransportModel result = null;
+ try {
+ String cloudPrimTenant =
+ getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM);
+ if (tenant == null) {
+ tenant = cloudPrimTenant;
+ }
+ CloudifyClient restClient = getCloudifyRestClient(request);
+ result = restClient.getNodeInstanceVersion(deploymentId, tenant);
+ } catch (HttpStatusCodeException e) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting executions for deployment " + deploymentId + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getExecutionByIdAndDeploymentId caught exception");
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Throwable t) {
+ MDC.put(SystemProperties.STATUS_CODE, "ERROR");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put("ErrorCode", "300");
+ MDC.put("ErrorCategory", "ERROR");
+ MDC.put("ErrorDescription", "Getting executions for deployment " + deploymentId + " failed!");
+ logger.error(EELFLoggerDelegate.errorLogger, "getExecutionByIdAndDeploymentId caught exception");
+ result = new RestResponseError("getExecutionByIdAndDeploymentId failed", t);
+ } finally {
+ postLogAudit(request);
+ }
+ return objectMapper.writeValueAsString(result);
+ }
+
+ public void preLogAudit(HttpServletRequest request) {
+ begin = new Date();
+ MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(begin));
+ MDC.put(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP, logDateFormat.format(begin));
+ MDC.put(SystemProperties.STATUS_CODE, "COMPLETE");
+ //logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
+ }
+
+ public void postLogAudit(HttpServletRequest request) {
+ end = new Date();
+ MDC.put("AlertSeverity", "0");
+ MDC.put("TargetEntity", "Cloudify Manager");
+ MDC.put("TargetServiceName", "Cloudify Manager");
+ MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(end));
+ MDC.put(SystemProperties.METRICSLOG_END_TIMESTAMP, logDateFormat.format(end));
+ MDC.put(SystemProperties.MDC_TIMER, Long.toString((end.getTime() - begin.getTime())));
+ logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
+ logger.info(EELFLoggerDelegate.metricsLogger, request.getMethod() + request.getRequestURI());
+ }
+}