aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBharat saraswal <bharat.saraswal@huawei.com>2017-09-21 09:48:26 +0530
committerBharat saraswal <bharat.saraswal@huawei.com>2017-09-21 09:48:26 +0530
commit5633ea611b4c84653d082f0c3c37edcaa74ac641 (patch)
tree19e07d0b862a68090def368d5100c1afca535f1c
parent97662b28b1cfd66c167e6a13fbac1d1567780e10 (diff)
Fix Sonar Issue
code refactoring and exception handling Issue-Id: CCSDK-87 Change-Id: I5440c1102dfa8a00a7813107cd3ab967b4316529 Signed-off-by: Bharat saraswal <bharat.saraswal@huawei.com>
-rwxr-xr-xREADME.md2
-rw-r--r--oom-app-common/src/main/java/org/onap/oom/dashboard/controller/CloudifyController.java1098
-rw-r--r--oom-app-common/src/main/java/org/onap/oom/dashboard/controller/ConsulController.java745
-rw-r--r--oom-app-common/src/main/java/org/onap/oom/dashboard/controller/ECDSingleSignOnController.java17
-rw-r--r--oom-app-common/src/main/java/org/onap/oom/dashboard/rest/ControllerRestClientImpl.java65
-rw-r--r--oom-app-common/src/main/java/org/onap/oom/dashboard/rest/ControllerRestClientMockImpl.java24
-rw-r--r--oom-app-common/src/main/java/org/onap/oom/dashboard/rest/HttpComponentsClientHttpRequestFactoryBasicAuth.java7
-rw-r--r--oom-app-common/src/main/java/org/onap/oom/dashboard/rest/IControllerRestClient.java404
8 files changed, 1168 insertions, 1194 deletions
diff --git a/README.md b/README.md
index b6f8e86..08141de 100755
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@ This is the web UI for the ONAP Operations Manager, also known as the OOM Dashbo
It consists of the following Maven projects:
- oom-app-common: Java classes that run in a web container like Tomcat
- oom-app-overlay: CSS, HTML and Javascript resources for the web application
-- oom-app-os: Web application project with featurers for ONAP use
+- oom-app-os: Web application project with features for ONAP use
### Prerequites
diff --git a/oom-app-common/src/main/java/org/onap/oom/dashboard/controller/CloudifyController.java b/oom-app-common/src/main/java/org/onap/oom/dashboard/controller/CloudifyController.java
index e9369e9..f3e136c 100644
--- a/oom-app-common/src/main/java/org/onap/oom/dashboard/controller/CloudifyController.java
+++ b/oom-app-common/src/main/java/org/onap/oom/dashboard/controller/CloudifyController.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,13 +21,11 @@
*******************************************************************************/
package org.onap.oom.dashboard.controller;
+import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
-import java.util.Iterator;
import java.util.List;
-
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -58,8 +56,6 @@ 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
@@ -69,567 +65,573 @@ import com.fasterxml.jackson.core.JsonProcessingException;
@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 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CloudifyController.class);
- 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";
+ /**
+ * Enum for selecting an item type.
+ */
+ public enum CloudifyDataItem {
+ BLUEPRINT, DEPLOYMENT, EXECUTION;
+ }
- /**
- * Supports sorting blueprints by ID
- */
- private static Comparator<CloudifyBlueprint> blueprintComparator = (o1, o2) -> o1.id.compareTo(o2.id);
+ 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 deployments by ID
- */
- private static Comparator<CloudifyDeployment> deploymentComparator = (o1, o2) -> o1.id.compareTo(o2.id);
+ /**
+ * Supports sorting blueprints by ID
+ */
+ private static Comparator<CloudifyBlueprint> blueprintComparator = Comparator.comparing(o -> o.id);
- /**
- * Supports sorting executions by ID
- */
- private static Comparator<CloudifyExecution> executionComparator = (o1, o2) -> o1.id.compareTo(o2.id);
+ /**
+ * Supports sorting deployments by ID
+ */
+ private static Comparator<CloudifyDeployment> deploymentComparator = 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 = 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;
- default:
- throw new DashboardControllerException("getItemListForPage failed: unimplemented case: " + option.name());
- }
+ /**
+ * Supports sorting executions by ID
+ */
+ private static Comparator<CloudifyExecution> executionComparator = Comparator.comparing(o -> o.id);
- // 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 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());
+ }
- /**
- * 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 = 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;
- }
+ // 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);
+ }
- /**
- * 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;
- }
+ /**
+ * 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 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;
- }
+ /**
+ * 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;
+ }
- /**
- * 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 (Throwable 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);
- }
+ /**
+ * 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 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 (Throwable 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);
- }
+ /**
+ * 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);
+ }
- /**
- * 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 (Throwable 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);
- }
+ /**
+ * 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);
+ }
- /**
- * 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 (Throwable 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);
- }
+ /**
+ * 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);
+ }
- /**
- * 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 (Throwable 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);
- }
+ /**
+ * 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);
+ }
+ }
- /**
- * 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 (Throwable 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);
- }
+ /**
+ * 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);
+ }
- /**
- * 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 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 (Throwable 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);
- }
+ /**
+ * 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);
+ }
- /**
- * 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) {
- Iterator<CloudifyExecution> exeIter = itemList.iterator();
- while (exeIter.hasNext()) {
- CloudifyExecution ce = exeIter.next();
- if (!status.equals(ce.status))
- exeIter.remove();
- }
- }
- Collections.sort(itemList, executionComparator);
+ /**
+ * 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);
+ }
+ }
- // 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) {
- 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 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);
- /**
- * 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 (Throwable 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);
- }
+ // 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);
+ }
- /**
- * 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 (Throwable 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);
- }
+ /**
+ * 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);
+ }
- /**
- * 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 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 (Throwable 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);
- }
+ /**
+ * 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);
+ }
+ }
}
diff --git a/oom-app-common/src/main/java/org/onap/oom/dashboard/controller/ConsulController.java b/oom-app-common/src/main/java/org/onap/oom/dashboard/controller/ConsulController.java
index 6c2cfb0..03e956c 100644
--- a/oom-app-common/src/main/java/org/onap/oom/dashboard/controller/ConsulController.java
+++ b/oom-app-common/src/main/java/org/onap/oom/dashboard/controller/ConsulController.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,14 +21,13 @@
*******************************************************************************/
package org.onap.oom.dashboard.controller;
+import com.fasterxml.jackson.core.JsonProcessingException;
import java.net.URI;
import java.time.Instant;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
-
import javax.servlet.http.HttpServletRequest;
import org.onap.oom.dashboard.exception.DashboardControllerException;
@@ -55,8 +54,6 @@ 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 Consul features: health checks of services, nodes, data
* centers. Methods serve Ajax requests made by Angular scripts on pages that
@@ -66,395 +63,383 @@ import com.fasterxml.jackson.core.JsonProcessingException;
@RequestMapping("/healthservices")
public class ConsulController extends DashboardRestrictedBaseController {
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ConsulController.class);
+ private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ConsulController.class);
- /**
- * Enum for selecting an item type.
- */
- public enum ConsulDataItem {
- SERVICE_INFO, SERVICE_HEALTH, NODES, DATACENTERS;
- }
+ /**
+ * Enum for selecting an item type.
+ */
+ public enum ConsulDataItem {
+ SERVICE_INFO, SERVICE_HEALTH, NODES, DATACENTERS;
+ }
- private static final String NODES_PATH = "/nodes";
- private static final String SERVICES_PATH = "/services";
+ private static final String NODES_PATH = "/nodes";
+ private static final String SERVICES_PATH = "/services";
- /**
- * Supports sorting results by node name
- */
- private static Comparator<ConsulNodeInfo> nodeHealthComparator = new Comparator<ConsulNodeInfo>() {
- @Override
- public int compare(ConsulNodeInfo o1, ConsulNodeInfo o2) {
- return o1.node.compareTo(o2.node);
- }
- };
+ /**
+ * Supports sorting results by node name
+ */
+ private static Comparator<ConsulNodeInfo> nodeHealthComparator = Comparator.comparing(o -> o.node);
- /**
- * Supports sorting results by service name
- */
- private static Comparator<ConsulServiceHealth> serviceHealthComparator = new Comparator<ConsulServiceHealth>() {
- @Override
- public int compare(ConsulServiceHealth o1, ConsulServiceHealth o2) {
- return o1.serviceName.compareTo(o2.serviceName);
- }
- };
+ /**
+ * Supports sorting results by service name
+ */
+ private static Comparator<ConsulServiceHealth> serviceHealthComparator = Comparator.comparing(o -> o.serviceName);
- /**
- * Supports sorting results by service name
- */
- private static Comparator<ConsulServiceInfo> serviceInfoComparator = new Comparator<ConsulServiceInfo>() {
- @Override
- public int compare(ConsulServiceInfo o1, ConsulServiceInfo o2) {
- return o1.name.compareTo(o2.name);
- }
- };
+ /**
+ * Supports sorting results by service name
+ */
+ private static Comparator<ConsulServiceInfo> serviceInfoComparator = Comparator.comparing(o -> o.name);
- /**
- * Gets one page of objects and supporting information via the REST client. On
- * success, returns a page of objects as String.
- *
- * @param option
- * Specifies which item 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,
- * JsonProcessingException On any error; e.g., Network failure.
- */
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private String getItemListForPage(long userId, ConsulDataItem option, int pageNum, int pageSize)
- throws DashboardControllerException, JsonProcessingException {
- IControllerRestClient restClient = getControllerRestClient(userId);
- List itemList = null;
- switch (option) {
- case NODES:
- itemList = restClient.getNodes();
- Collections.sort(itemList, nodeHealthComparator);
- break;
- case DATACENTERS:
- itemList = restClient.getDatacenters();
- break;
- default:
- throw new DashboardControllerException("getItemListForPage failed: unimplemented case: " + option.name());
- }
+ /**
+ * Gets one page of objects and supporting information via the REST client. On
+ * success, returns a page of objects as String.
+ *
+ * @param option
+ * Specifies which item 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,
+ * JsonProcessingException On any error; e.g., Network failure.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ private String getItemListForPage(long userId, ConsulDataItem option, int pageNum, int pageSize)
+ throws DashboardControllerException, JsonProcessingException {
+ IControllerRestClient restClient = getControllerRestClient(userId);
+ List itemList;
+ switch (option) {
+ case NODES:
+ itemList = restClient.getNodes();
+ itemList.sort(nodeHealthComparator);
+ break;
+ case DATACENTERS:
+ itemList = restClient.getDatacenters();
+ break;
+ default:
+ throw new DashboardControllerException(
+ "getItemListForPage failed: unimplemented case: " + option.name());
+ }
- // Shrink if needed
- if (itemList.size() > pageSize)
- itemList = getPageOfList(pageNum, pageSize, itemList);
- int pageCount = (int) Math.ceil((double) itemList.size() / pageSize);
- RestResponsePage<List> model = new RestResponsePage<>(itemList.size(), pageCount, itemList);
- String outboundJson = objectMapper.writeValueAsString(model);
- return outboundJson;
- }
+ // Shrink if needed
+ if (itemList.size() > pageSize) {
+ itemList = getPageOfList(pageNum, pageSize, itemList);
+ }
+ int pageCount = (int) Math.ceil((double) itemList.size() / pageSize);
+ RestResponsePage<List> model = new RestResponsePage<>(itemList.size(), 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, ConsulDataItem 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) {
- // Remote service failed; build descriptive error message
- logger.error(EELFLoggerDelegate.errorLogger, "getItemListForPageWrapper caught exception", ex);
- RestResponseError 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;
- }
+ /**
+ * 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, ConsulDataItem option) {
+ String outboundJson;
+ 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) {
+ // Remote service failed; build descriptive error message
+ logger.error(EELFLoggerDelegate.errorLogger, "getItemListForPageWrapper caught exception", ex);
+ RestResponseError 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 all service details.
- *
- * @param request
- * HttpServletRequest
- * @return List of ConsulServiceInfo objects, as JSON
- * @throws JsonProcessingException
- * if serialization fails
- */
- @RequestMapping(value = { SERVICES_PATH }, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getServices(HttpServletRequest request) throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- Object result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- List<ConsulServiceInfo> itemList = restClient.getServices();
- Collections.sort(itemList, serviceInfoComparator);
- result = itemList;
- } catch (Throwable t) {
- result = new RestResponseError("getServices failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
+ /**
+ * Serves all service details.
+ *
+ * @param request
+ * HttpServletRequest
+ * @return List of ConsulServiceInfo objects, as JSON
+ * @throws JsonProcessingException
+ * if serialization fails
+ */
+ @RequestMapping(value = {SERVICES_PATH}, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getServices(HttpServletRequest request) throws JsonProcessingException {
+ MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
+ logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
+ Object result;
+ try {
+ IControllerRestClient restClient = getControllerRestClient(request);
+ List<ConsulServiceInfo> itemList = restClient.getServices();
+ itemList.sort(serviceInfoComparator);
+ result = itemList;
+ } catch (Exception t) {
+ result = new RestResponseError("getServices failed", t);
+ }
+ MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
+ logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
+ return objectMapper.writeValueAsString(result);
+ }
- /**
- * Serves service health details - not paginated.
- *
- * @param request
- * HttpServletRequest
- * @param serviceId
- * Service ID
- * @return List of ConsulServiceHealth objects as JSON
- * @throws JsonProcessingException
- * if serialization fails
- */
- @RequestMapping(value = {
- SERVICES_PATH + "/{serviceId}" }, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getServiceHealthDetails(HttpServletRequest request, @PathVariable String serviceId)
- throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- Object result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.getServiceHealth(serviceId);
- } catch (Throwable t) {
- result = new RestResponseError("getServiceHealthDetails failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
+ /**
+ * Serves service health details - not paginated.
+ *
+ * @param request
+ * HttpServletRequest
+ * @param serviceId
+ * Service ID
+ * @return List of ConsulServiceHealth objects as JSON
+ * @throws JsonProcessingException
+ * if serialization fails
+ */
+ @RequestMapping(value = {
+ SERVICES_PATH + "/{serviceId}"}, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getServiceHealthDetails(HttpServletRequest request, @PathVariable String serviceId)
+ throws JsonProcessingException {
+ MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
+ logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
+ Object result;
+ try {
+ IControllerRestClient restClient = getControllerRestClient(request);
+ result = restClient.getServiceHealth(serviceId);
+ } catch (Exception t) {
+ result = new RestResponseError("getServiceHealthDetails failed", t);
+ }
+ MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
+ logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
+ return objectMapper.writeValueAsString(result);
+ }
- /**
- * Serves service health historical data - not paginated.
- *
- * @param request
- * HttpServletRequest
- * @param serviceName
- * Service name as path parameter
- * @param start
- * Earliest date-time as an ISO 8061 value, such as
- * 2007-12-03T10:15:30+01:00
- * @param end
- * Latest date-time as an ISO 8061 value, such as
- * 2007-12-03T10:15:30+01:00
- * @return List of ConsulServiceHealth objects as JSON
- * @throws JsonProcessingException
- * if serialization fails
- */
- @RequestMapping(value = { "/svchist/{serviceName}" }, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getServiceHealthHistory(HttpServletRequest request, //
- @PathVariable String serviceName, //
- @RequestParam String start, //
- @RequestParam String end) throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- Object result = null;
- try {
- Instant startDateTime = Instant.parse(start);
- Instant endDateTime = Instant.parse(end);
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.getServiceHealthHistory(serviceName, startDateTime, endDateTime);
- } catch (HttpStatusCodeException e) {
- // Rare, but can happen
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Throwable t) {
- // Work around the hack to report no-match.
- result = new RestResponseError("getServiceHealthHistory failed: " + t.getMessage());
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
+ /**
+ * Serves service health historical data - not paginated.
+ *
+ * @param request
+ * HttpServletRequest
+ * @param serviceName
+ * Service name as path parameter
+ * @param start
+ * Earliest date-time as an ISO 8061 value, such as
+ * 2007-12-03T10:15:30+01:00
+ * @param end
+ * Latest date-time as an ISO 8061 value, such as
+ * 2007-12-03T10:15:30+01:00
+ * @return List of ConsulServiceHealth objects as JSON
+ * @throws JsonProcessingException
+ * if serialization fails
+ */
+ @RequestMapping(value = {"/svchist/{serviceName}"}, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getServiceHealthHistory(HttpServletRequest request, //
+ @PathVariable String serviceName, //
+ @RequestParam String start, //
+ @RequestParam String end) throws JsonProcessingException {
+ MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
+ logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
+ Object result = null;
+ try {
+ Instant startDateTime = Instant.parse(start);
+ Instant endDateTime = Instant.parse(end);
+ IControllerRestClient restClient = getControllerRestClient(request);
+ result = restClient.getServiceHealthHistory(serviceName, startDateTime, endDateTime);
+ } catch (HttpStatusCodeException e) {
+ // Rare, but can happen
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Exception t) {
+ // Work around the hack to report no-match.
+ result = new RestResponseError("getServiceHealthHistory failed: " + t.getMessage());
+ }
+ MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
+ logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
+ return objectMapper.writeValueAsString(result);
+ }
- /**
- * Serves one page of service health information by getting all service names,
- * then iterating over them to get the health of each service.
- *
- * ECOMP-C does NOT provide an API to get the health of all services in one
- * request.
- *
- * @param request
- * HttpServletRequest
- * @return List of ConsulServiceHealth objects, as JSON
- * @throws JsonProcessingException
- * on serialization exception
- */
- @SuppressWarnings("unchecked")
- @RequestMapping(value = { "/serviceshealth" }, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getServicesHealth(HttpServletRequest request) throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- List<ConsulServiceHealth> itemList = new ArrayList<>();
- IControllerRestClient restClient = getControllerRestClient(request);
- List<ConsulServiceInfo> svcInfoList = restClient.getServices();
- for (ConsulServiceInfo csi : svcInfoList) {
- List<ConsulServiceHealth> csh = restClient.getServiceHealth(csi.name);
- itemList.addAll(csh);
- }
- Collections.sort(itemList, serviceHealthComparator);
- // 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) {
- result = new RestResponseError("getServicesHealth failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
+ /**
+ * Serves one page of service health information by getting all service names,
+ * then iterating over them to get the health of each service.
+ *
+ * ECOMP-C does NOT provide an API to get the health of all services in one
+ * request.
+ *
+ * @param request
+ * HttpServletRequest
+ * @return List of ConsulServiceHealth objects, as JSON
+ * @throws JsonProcessingException
+ * on serialization exception
+ */
+ @SuppressWarnings("unchecked")
+ @RequestMapping(value = {"/serviceshealth"}, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getServicesHealth(HttpServletRequest request) throws JsonProcessingException {
+ MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
+ logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
+ ECTransportModel result = null;
+ try {
+ List<ConsulServiceHealth> itemList = new ArrayList<>();
+ IControllerRestClient restClient = getControllerRestClient(request);
+ List<ConsulServiceInfo> svcInfoList = restClient.getServices();
+ for (ConsulServiceInfo csi : svcInfoList) {
+ List<ConsulServiceHealth> csh = restClient.getServiceHealth(csi.name);
+ itemList.addAll(csh);
+ }
+ itemList.sort(serviceHealthComparator);
+ // 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("getServicesHealth failed", t);
+ }
+ MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
+ logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
+ return objectMapper.writeValueAsString(result);
+ }
- /**
- * Serves one page of node information.
- *
- * @param request
- * HttpServletRequest
- * @return List of ConsulNodeInfo objects, as JSON
- */
- @RequestMapping(value = { NODES_PATH }, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getNodesInfo(HttpServletRequest request) {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- String json = getItemListForPageWrapper(request, ConsulDataItem.NODES);
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return json;
- }
+ /**
+ * Serves one page of node information.
+ *
+ * @param request
+ * HttpServletRequest
+ * @return List of ConsulNodeInfo objects, as JSON
+ */
+ @RequestMapping(value = {NODES_PATH}, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getNodesInfo(HttpServletRequest request) {
+ MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
+ logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
+ String json = getItemListForPageWrapper(request, ConsulDataItem.NODES);
+ MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
+ logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
+ return json;
+ }
- /**
- * Serves node services health details - not paginated.
- *
- * @param request
- * HttpServletRequest
- * @param nodeName
- * Node name
- * @return List of ConsulServiceHealth objects as JSON
- * @throws JsonProcessingException
- * if serialization fails
- */
- @RequestMapping(value = { NODES_PATH + "/{nodeName}" }, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getNodeServicesHealth(HttpServletRequest request, @PathVariable String nodeName)
- throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- Object result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.getNodeServicesHealth(nodeName);
- } catch (Throwable t) {
- result = new RestResponseError("getNodeServicesHealth failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
+ /**
+ * Serves node services health details - not paginated.
+ *
+ * @param request
+ * HttpServletRequest
+ * @param nodeName
+ * Node name
+ * @return List of ConsulServiceHealth objects as JSON
+ * @throws JsonProcessingException
+ * if serialization fails
+ */
+ @RequestMapping(value = {NODES_PATH + "/{nodeName}"}, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getNodeServicesHealth(HttpServletRequest request, @PathVariable String nodeName)
+ throws JsonProcessingException {
+ MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
+ logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
+ Object result = null;
+ try {
+ IControllerRestClient restClient = getControllerRestClient(request);
+ result = restClient.getNodeServicesHealth(nodeName);
+ } catch (Exception t) {
+ result = new RestResponseError("getNodeServicesHealth failed", t);
+ }
+ MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
+ logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
+ return objectMapper.writeValueAsString(result);
+ }
- /**
- * Serves one page of datacenters health.
- *
- * @param request
- * HttpServletRequest
- * @return List of ConsulHealthStatus objects
- */
- @RequestMapping(value = { "/datacenters" }, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getDatacentersHealth(HttpServletRequest request) {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- String json = getItemListForPageWrapper(request, ConsulDataItem.DATACENTERS);
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return json;
- }
+ /**
+ * Serves one page of data centers health.
+ *
+ * @param request
+ * HttpServletRequest
+ * @return List of ConsulHealthStatus objects
+ */
+ @RequestMapping(value = {"/datacenters"}, method = RequestMethod.GET, produces = "application/json")
+ @ResponseBody
+ public String getDatacentersHealth(HttpServletRequest request) {
+ MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
+ logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
+ String json = getItemListForPageWrapper(request, ConsulDataItem.DATACENTERS);
+ MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
+ logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
+ return json;
+ }
- /**
- * Processes request to register a service for health checks.
- *
- * @param request
- * HttpServletRequest
- * @param registration
- * Consul service registration
- * @return URI of the newly registered resource
- * @throws JsonProcessingException
- * on serialization error
- */
- @RequestMapping(value = { "/register" }, method = RequestMethod.POST, produces = "application/json")
- @ResponseBody
- public String registerService(HttpServletRequest request, @RequestBody ConsulHealthServiceRegistration registration)
- 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);
- URI uri = restClient.registerService(registration);
- result = new RestResponseSuccess(uri.toString());
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Throwable t) {
- result = new RestResponseError("registerService 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 register a service for health checks.
+ *
+ * @param request
+ * HttpServletRequest
+ * @param registration
+ * Consul service registration
+ * @return URI of the newly registered resource
+ * @throws JsonProcessingException
+ * on serialization error
+ */
+ @RequestMapping(value = {"/register"}, method = RequestMethod.POST, produces = "application/json")
+ @ResponseBody
+ public String registerService(HttpServletRequest request, @RequestBody ConsulHealthServiceRegistration registration)
+ 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);
+ URI uri = restClient.registerService(registration);
+ result = new RestResponseSuccess(uri.toString());
+ } catch (HttpStatusCodeException e) {
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Exception t) {
+ result = new RestResponseError("registerService 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 deregister a service for health checks.
- *
- * @param request
- * HttpServletRequest
- * @param serviceName
- * Consul service name to deregister
- * @return Success or error indicator
- * @throws JsonProcessingException
- * on serialization error
- */
- @RequestMapping(value = {
- "/deregister" + "/{serviceName}" }, method = RequestMethod.POST, produces = "application/json")
- @ResponseBody
- public String deregisterService(HttpServletRequest request, @PathVariable String serviceName)
- 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.deregisterService(serviceName);
- result = new RestResponseSuccess("Deregistration yielded code " + Integer.toString(code));
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Throwable t) {
- result = new RestResponseError("deregisterService 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 deregister a service for health checks.
+ *
+ * @param request
+ * HttpServletRequest
+ * @param serviceName
+ * Consul service name to deregister
+ * @return Success or error indicator
+ * @throws JsonProcessingException
+ * on serialization error
+ */
+ @RequestMapping(value = {
+ "/deregister" + "/{serviceName}"}, method = RequestMethod.POST, produces = "application/json")
+ @ResponseBody
+ public String deregisterService(HttpServletRequest request, @PathVariable String serviceName)
+ 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.deregisterService(serviceName);
+ result = new RestResponseSuccess("Deregistration yielded code " + Integer.toString(code));
+ } catch (HttpStatusCodeException e) {
+ result = new RestResponseError(e.getResponseBodyAsString());
+ } catch (Exception t) {
+ result = new RestResponseError("deregisterService failed", t);
+ }
+ MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
+ logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
+ return objectMapper.writeValueAsString(result);
+ }
}
diff --git a/oom-app-common/src/main/java/org/onap/oom/dashboard/controller/ECDSingleSignOnController.java b/oom-app-common/src/main/java/org/onap/oom/dashboard/controller/ECDSingleSignOnController.java
index 0c59b2e..e877890 100644
--- a/oom-app-common/src/main/java/org/onap/oom/dashboard/controller/ECDSingleSignOnController.java
+++ b/oom-app-common/src/main/java/org/onap/oom/dashboard/controller/ECDSingleSignOnController.java
@@ -1,7 +1,3 @@
-package org.onap.oom.dashboard.controller;
-
-import java.io.UnsupportedEncodingException;
-
/*-
* ================================================================================
* ECOMP Portal SDK
@@ -22,6 +18,10 @@ import java.io.UnsupportedEncodingException;
* ================================================================================
*/
+package org.onap.oom.dashboard.controller;
+
+import java.io.UnsupportedEncodingException;
+
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
@@ -68,6 +68,7 @@ import org.springframework.web.util.WebUtils;
public class ECDSingleSignOnController extends UnRestrictedBaseController {
private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ECDSingleSignOnController.class);
+ private static final String REDIRECT = "redirect:";
@Autowired
private LoginService loginService;
@@ -132,7 +133,7 @@ public class ECDSingleSignOnController extends UnRestrictedBaseController {
+ "?noUserError=Yes";
logger.debug(EELFLoggerDelegate.debugLogger, "singleSignOnLogin: user is null, redirect URL is {}",
redirectUrl);
- return new ModelAndView("redirect:" + redirectUrl);
+ return new ModelAndView(REDIRECT + redirectUrl);
} else {
// store the user's information in the session
String loginMethod;
@@ -149,14 +150,14 @@ public class ECDSingleSignOnController extends UnRestrictedBaseController {
logger.debug(EELFLoggerDelegate.debugLogger,
"singleSignOnLogin: create new user session for expired user {}; user {} exists in the system",
userId, commandBean.getUser().getOrgUserId());
- return new ModelAndView("redirect:" + forwardURL);
+ return new ModelAndView(REDIRECT + forwardURL);
}
} // user is null or session is null
else {
// both user and session are non-null.
logger.info(EELFLoggerDelegate.debugLogger, "singleSignOnLogin: redirecting to the forwardURL {}",
forwardURL);
- return new ModelAndView("redirect:" + forwardURL);
+ return new ModelAndView(REDIRECT + forwardURL);
}
} else {
/*
@@ -201,7 +202,7 @@ public class ECDSingleSignOnController extends UnRestrictedBaseController {
+ encodedReturnToAppUrl;
logger.debug(EELFLoggerDelegate.debugLogger, "singleSignOnLogin: portal-bound redirect URL is {}",
redirectUrl);
- return new ModelAndView("redirect:" + redirectUrl);
+ return new ModelAndView(REDIRECT + redirectUrl);
} // portal is available
else {
diff --git a/oom-app-common/src/main/java/org/onap/oom/dashboard/rest/ControllerRestClientImpl.java b/oom-app-common/src/main/java/org/onap/oom/dashboard/rest/ControllerRestClientImpl.java
index 858ed5a..e6d3d54 100644
--- a/oom-app-common/src/main/java/org/onap/oom/dashboard/rest/ControllerRestClientImpl.java
+++ b/oom-app-common/src/main/java/org/onap/oom/dashboard/rest/ControllerRestClientImpl.java
@@ -70,6 +70,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public class ControllerRestClientImpl implements IControllerRestClient {
private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ControllerRestClientImpl.class);
+ private static final String DEPLOYMENT_ID = "deployment_id";
private final String baseUrl;
private final RestTemplate restTemplate;
@@ -158,9 +159,8 @@ public class ControllerRestClientImpl implements IControllerRestClient {
ResponseEntity<CloudifyBlueprintList> response = restTemplate.exchange(url, HttpMethod.GET, null,
new ParameterizedTypeReference<CloudifyBlueprintList>() {
});
- CloudifyBlueprintList result = response.getBody();
- return result;
- }
+ return response.getBody();
+ }
@Override
public CloudifyBlueprintList getBlueprint(final String id) {
@@ -169,8 +169,7 @@ public class ControllerRestClientImpl implements IControllerRestClient {
ResponseEntity<CloudifyBlueprintList> response = restTemplate.exchange(url, HttpMethod.GET, null,
new ParameterizedTypeReference<CloudifyBlueprintList>() {
});
- CloudifyBlueprintList result = response.getBody();
- return result;
+ return response.getBody();
}
@Override
@@ -179,16 +178,14 @@ public class ControllerRestClientImpl implements IControllerRestClient {
logger.debug(EELFLoggerDelegate.debugLogger, "viewBlueprint: url {}", url);
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, null, String.class);
String yaml = response.getBody();
- CloudifyBlueprintContent result = new CloudifyBlueprintContent(id, yaml);
- return result;
+ return new CloudifyBlueprintContent(id, yaml);
}
@Override
public CloudifyBlueprintList uploadBlueprint(CloudifyBlueprintUpload blueprint) {
String url = buildUrl(new String[] { baseUrl, blueprintsPath }, null);
logger.debug(EELFLoggerDelegate.debugLogger, "uploadBlueprint: url {}", url);
- CloudifyBlueprintList result = restTemplate.postForObject(url, blueprint, CloudifyBlueprintList.class);
- return result;
+ return restTemplate.postForObject(url, blueprint, CloudifyBlueprintList.class);
}
@Override
@@ -208,8 +205,7 @@ public class ControllerRestClientImpl implements IControllerRestClient {
ResponseEntity<CloudifyDeploymentList> response = restTemplate.exchange(url, HttpMethod.GET, null,
new ParameterizedTypeReference<CloudifyDeploymentList>() {
});
- CloudifyDeploymentList list = response.getBody();
- return list;
+ return response.getBody();
}
@Override
@@ -218,17 +214,15 @@ public class ControllerRestClientImpl implements IControllerRestClient {
logger.debug(EELFLoggerDelegate.debugLogger, "getDeployment: url {}", url);
ResponseEntity<CloudifyDeploymentList> response = restTemplate.exchange(url, HttpMethod.GET, null,
new ParameterizedTypeReference<CloudifyDeploymentList>() {
- });
- CloudifyDeploymentList list = response.getBody();
- return list;
+ });
+ return response.getBody();
}
@Override
public CloudifyDeploymentList createDeployment(CloudifyDeploymentRequest deployment) {
String url = buildUrl(new String[] { baseUrl, deploymentsPath }, null);
logger.debug(EELFLoggerDelegate.debugLogger, "createDeployment: url {}", url);
- CloudifyDeploymentList result = restTemplate.postForObject(url, deployment, CloudifyDeploymentList.class);
- return result;
+ return restTemplate.postForObject(url, deployment, CloudifyDeploymentList.class);
}
@Override
@@ -244,39 +238,36 @@ public class ControllerRestClientImpl implements IControllerRestClient {
@Override
public CloudifyExecutionList getExecutions(final String deploymentId) {
- String url = buildUrl(new String[] { baseUrl, executionsPath }, new String[] { "deployment_id", deploymentId });
+ String url = buildUrl(new String[]{baseUrl, executionsPath}, new String[]{DEPLOYMENT_ID, deploymentId});
logger.debug(EELFLoggerDelegate.debugLogger, "getExecutions: url {}", url);
ResponseEntity<CloudifyExecutionList> response = restTemplate.exchange(url, HttpMethod.GET, null,
new ParameterizedTypeReference<CloudifyExecutionList>() {
});
- CloudifyExecutionList list = response.getBody();
- return list;
+ return response.getBody();
}
@Override
public CloudifyExecutionList getExecution(String executionId, String deploymentId) {
String url = buildUrl(new String[] { baseUrl, executionsPath, executionId },
- new String[] { "deployment_id", deploymentId });
+ new String[]{DEPLOYMENT_ID, deploymentId});
logger.debug(EELFLoggerDelegate.debugLogger, "getExecution: url {}", url);
ResponseEntity<CloudifyExecutionList> response = restTemplate.exchange(url, HttpMethod.GET, null,
new ParameterizedTypeReference<CloudifyExecutionList>() {
});
- CloudifyExecutionList list = response.getBody();
- return list;
+ return response.getBody();
}
@Override
public CloudifyExecution startExecution(CloudifyExecutionRequest execution) {
String url = buildUrl(new String[] { baseUrl, executionsPath }, null);
logger.debug(EELFLoggerDelegate.debugLogger, "startExecution: url {}", url);
- CloudifyExecution result = restTemplate.postForObject(url, execution, CloudifyExecution.class);
- return result;
+ return restTemplate.postForObject(url, execution, CloudifyExecution.class);
}
@Override
public int cancelExecution(final String executionId, final String deploymentId, final String action) {
String url = buildUrl(new String[] { baseUrl, executionsPath, executionId },
- new String[] { "deployment_id", deploymentId, "action", action });
+ new String[]{DEPLOYMENT_ID, deploymentId, "action", action});
logger.debug(EELFLoggerDelegate.debugLogger, "deleteExecution: url {}", url);
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.DELETE, null,
new ParameterizedTypeReference<String>() {
@@ -288,8 +279,7 @@ public class ControllerRestClientImpl implements IControllerRestClient {
public URI registerService(ConsulHealthServiceRegistration registration) {
String url = buildUrl(new String[] { baseUrl, healthServicesPath, "register" }, null);
logger.debug(EELFLoggerDelegate.debugLogger, "registerService: url {}", url);
- URI uri = restTemplate.postForLocation(url, registration);
- return uri;
+ return restTemplate.postForLocation(url, registration);
}
@Override
@@ -318,7 +308,7 @@ public class ControllerRestClientImpl implements IControllerRestClient {
List<ConsulServiceInfo> list = new ArrayList<>();
for (Map.Entry<String, Object> entry : serviceInfo.entrySet()) {
// Be defensive
- List<String> addrs = null;
+ List<String> addrs;
if (entry.getValue() instanceof List<?>)
addrs = (List<String>) entry.getValue();
else
@@ -335,8 +325,7 @@ public class ControllerRestClientImpl implements IControllerRestClient {
ResponseEntity<List<ConsulServiceHealth>> response = restTemplate.exchange(url, HttpMethod.GET, null,
new ParameterizedTypeReference<List<ConsulServiceHealth>>() {
});
- List<ConsulServiceHealth> list = response.getBody();
- return list;
+ return response.getBody();
}
@Override
@@ -368,8 +357,7 @@ public class ControllerRestClientImpl implements IControllerRestClient {
ResponseEntity<List<ConsulNodeInfo>> response = restTemplate.exchange(url, HttpMethod.GET, null,
new ParameterizedTypeReference<List<ConsulNodeInfo>>() {
});
- List<ConsulNodeInfo> list = response.getBody();
- return list;
+ return response.getBody();
}
@Override
@@ -378,9 +366,8 @@ public class ControllerRestClientImpl implements IControllerRestClient {
logger.debug(EELFLoggerDelegate.debugLogger, "getNodeServicesHealth: url {}", url);
ResponseEntity<List<ConsulServiceHealth>> response = restTemplate.exchange(url, HttpMethod.GET, null,
new ParameterizedTypeReference<List<ConsulServiceHealth>>() {
- });
- List<ConsulServiceHealth> list = response.getBody();
- return list;
+ });
+ return response.getBody();
}
@Override
@@ -411,14 +398,14 @@ public class ControllerRestClientImpl implements IControllerRestClient {
ControllerRestClientImpl client = new ControllerRestClientImpl("http://localhost:8081/controller", "dbus_user",
"dbus_pass");
final String id = args[0];
- System.out.println("Requesting blueprint for " + id);
+ logger.info("Requesting blueprint for " + id);
CloudifyBlueprintList list = client.getBlueprint(id);
if (list == null)
- System.err.println("Received null");
+ logger.error("Received null");
else
for (int i = 0; i < list.items.size(); ++i) {
- System.out.println("Blueprint " + Integer.toString(i));
- System.out.println(list.items.get(i).toString());
+ logger.info("Blueprint " + Integer.toString(i));
+ logger.info(list.items.get(i).toString());
}
}
diff --git a/oom-app-common/src/main/java/org/onap/oom/dashboard/rest/ControllerRestClientMockImpl.java b/oom-app-common/src/main/java/org/onap/oom/dashboard/rest/ControllerRestClientMockImpl.java
index 217f878..67a46c1 100644
--- a/oom-app-common/src/main/java/org/onap/oom/dashboard/rest/ControllerRestClientMockImpl.java
+++ b/oom-app-common/src/main/java/org/onap/oom/dashboard/rest/ControllerRestClientMockImpl.java
@@ -97,10 +97,10 @@ public class ControllerRestClientMockImpl implements IControllerRestClient {
* @return Instance of modelClass
*/
private ECTransportModel getMockData(final Class<? extends ECTransportModel> modelClass, final String path) {
- ECTransportModel result = null;
+ ECTransportModel result;
String json = getMockDataContent(path);
try {
- result = (ECTransportModel) objectMapper.readValue(json, modelClass);
+ result = objectMapper.readValue(json, modelClass);
} catch (Exception ex) {
logger.error("getMockData failed", ex);
throw new RuntimeException(ex);
@@ -121,8 +121,7 @@ public class ControllerRestClientMockImpl implements IControllerRestClient {
@Override
public CloudifyBlueprintContent viewBlueprint(final String id) {
String yaml = getMockDataContent("/blueprintContent.yaml");
- CloudifyBlueprintContent cbc = new CloudifyBlueprintContent(id, yaml);
- return cbc;
+ return new CloudifyBlueprintContent(id, yaml);
}
@Override
@@ -251,12 +250,13 @@ public class ControllerRestClientMockImpl implements IControllerRestClient {
logger.error(EELFLoggerDelegate.errorLogger, "getNode failed", ex);
}
ArrayList<ConsulServiceInfo> result = new ArrayList<>();
- for (Map.Entry<String, Object> entry : map.entrySet()) {
- final String service = entry.getKey();
- @SuppressWarnings("unchecked")
- final List<String> addrs = (List<String>) entry.getValue();
- result.add(new ConsulServiceInfo(service, addrs));
- }
+ if (map != null) {
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
+ final String service = entry.getKey();
+ @SuppressWarnings("unchecked") final List<String> addrs = (List<String>) entry.getValue();
+ result.add(new ConsulServiceInfo(service, addrs));
+ }
+ }
return result;
}
@@ -291,7 +291,7 @@ public class ControllerRestClientMockImpl implements IControllerRestClient {
* On any failure
*/
public static void main(String[] args) throws DashboardControllerException {
- System.out.println("Testing paths and parsing mock data");
+ logger.info("Testing paths and parsing mock data");
ControllerRestClientMockImpl client = new ControllerRestClientMockImpl();
CloudifyBlueprintList list1 = client.getBlueprints();
CloudifyBlueprintList list2 = client.getBlueprint("mock");
@@ -305,7 +305,7 @@ public class ControllerRestClientMockImpl implements IControllerRestClient {
if (list1 == null || list2 == null || list3 == null || list4 == null || list5 == null || list6 == null
|| list7 == null || list8 == null || list9 == null)
throw new DashboardControllerException("Failed");
- System.out.println("Pass.");
+ logger.info("Pass.");
}
}
diff --git a/oom-app-common/src/main/java/org/onap/oom/dashboard/rest/HttpComponentsClientHttpRequestFactoryBasicAuth.java b/oom-app-common/src/main/java/org/onap/oom/dashboard/rest/HttpComponentsClientHttpRequestFactoryBasicAuth.java
index 7ad1d46..2779df5 100644
--- a/oom-app-common/src/main/java/org/onap/oom/dashboard/rest/HttpComponentsClientHttpRequestFactoryBasicAuth.java
+++ b/oom-app-common/src/main/java/org/onap/oom/dashboard/rest/HttpComponentsClientHttpRequestFactoryBasicAuth.java
@@ -52,9 +52,10 @@ public class HttpComponentsClientHttpRequestFactoryBasicAuth extends HttpCompone
this.host = host;
}
- protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
- return createHttpContext();
- }
+ @Override
+ protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
+ return createHttpContext();
+ }
private HttpContext createHttpContext() {
// Create AuthCache instance
diff --git a/oom-app-common/src/main/java/org/onap/oom/dashboard/rest/IControllerRestClient.java b/oom-app-common/src/main/java/org/onap/oom/dashboard/rest/IControllerRestClient.java
index a9b1a2d..0150bbb 100644
--- a/oom-app-common/src/main/java/org/onap/oom/dashboard/rest/IControllerRestClient.java
+++ b/oom-app-common/src/main/java/org/onap/oom/dashboard/rest/IControllerRestClient.java
@@ -7,9 +7,9 @@
* 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.
@@ -24,7 +24,6 @@ package org.onap.oom.dashboard.rest;
import java.net.URI;
import java.time.Instant;
import java.util.List;
-
import org.onap.oom.dashboard.model.CloudifyBlueprintContent;
import org.onap.oom.dashboard.model.CloudifyBlueprintList;
import org.onap.oom.dashboard.model.CloudifyBlueprintUpload;
@@ -45,204 +44,203 @@ import org.onap.oom.dashboard.model.ConsulServiceInfo;
*/
public interface IControllerRestClient {
- public static String blueprintsPath = "blueprints";
- public static String viewBlueprintsPath = "viewblueprints";
- public static String deploymentsPath = "deployments";
- public static String executionsPath = "executions";
- public static String healthServicesPath = "healthservices";
-
- /**
- * Gets the list of Cloudify blueprints.
- *
- * @return CloudifyBlueprintList
- */
- public CloudifyBlueprintList getBlueprints();
-
- /**
- * Gets the Cloudify blueprint metadata for the specified ID
- *
- * @param id
- * Blueprint ID
- * @return CloudifyBlueprintList of size 1; null if not found
- */
- public CloudifyBlueprintList getBlueprint(String id);
-
- /**
- * Gets the Cloudify blueprint content for the specified ID
- *
- * @param id
- * Blueprint ID
- * @return Blueprint content
- */
- public CloudifyBlueprintContent viewBlueprint(String id);
-
- /**
- * Uploads a Cloudify blueprint.
- *
- * @param blueprint
- * Cloudify Blueprint to upload
- * @return CloudifyBlueprintList of size 1; null if not found
- */
- public CloudifyBlueprintList uploadBlueprint(CloudifyBlueprintUpload blueprint);
-
- /**
- * Deletes the Cloudify blueprint with the specified id.
- *
- * @param id
- * Blueprint ID
- * @return Status code; e.g., 200, 202, 204.
- */
- public int deleteBlueprint(String id);
-
- /**
- * Gets the list of Cloudify deployments.
- *
- * @return CloudifyDeploymentList
- */
- public CloudifyDeploymentList getDeployments();
-
- /**
- * Gets the Cloudify deployment for the specified ID
- *
- * @param id
- * Deployment ID
- * @return CloudifyDeploymentList of size 1; null if not found.
- */
- public CloudifyDeploymentList getDeployment(String id);
-
- /**
- * Creates a Cloudify deployment.
- *
- * @param deployment
- * Deployment details
- * @return CloudifyDeploymentList of size 1
- */
- public CloudifyDeploymentList createDeployment(CloudifyDeploymentRequest deployment);
-
- /**
- * Deletes the Cloudify deployment with the specified id.
- *
- * @param id
- * Deployment ID
- * @param ignoreLiveNodes
- * Boolean indicator whether to delete even if live nodes exist
- * @return Status code; e.g., 200, 202, 204.
- */
- public int deleteDeployment(String id, boolean ignoreLiveNodes);
-
- /**
- * Gets the Cloudify executions for the specified deployment ID
- *
- * @param deploymentId
- * Deployment ID
- * @return CloudifyExecutionList
- */
- public CloudifyExecutionList getExecutions(String deploymentId);
-
- /**
- * Gets the Cloudify execution for the specified execution ID and deployment
- * ID
- *
- * @param executionId
- * Execution ID
- * @param deploymentId
- * Deployment ID
- * @return CloudifyExecutionList of size 1
- */
- public CloudifyExecutionList getExecution(String executionId, String deploymentId);
-
- /**
- * Starts a Cloudify execution.
- *
- * @param execution
- * Execution details
- * @return CloudifyExecution
- */
- public CloudifyExecution startExecution(CloudifyExecutionRequest execution);
-
- /**
- * Deletes the Cloudify execution with the specified ids.
- *
- * @param executionId
- * execution ID
- * @param deploymentId
- * Deployment ID
- * @param action
- * either "cancel" or "force-cancel"
- * @return Status code; e.g., 200, 202, 204.
- */
- public int cancelExecution(String executionId, String deploymentId, String action);
-
- /**
- * Registers a service with Consul for health check.
- *
- * @param registration
- * Details about the service to be registered.
- * @return Result of registering a service
- */
- public URI registerService(ConsulHealthServiceRegistration registration);
-
- /**
- * Deregisters a service with Consul for health check.
- *
- * @param serviceName
- * Name of the service to be deregistered.
- * @return Response code
- */
- public int deregisterService(String serviceName);
-
- /**
- * Gets all the services that are monitored by Consul.
- *
- * @return List of ConsulServiceHealth
- */
- public List<ConsulServiceInfo> getServices();
-
- /**
- * Gets the status for the specified service on all nodes.
- *
- * @param serviceName
- * Service name
- * @return List of ConsulServiceHealth
- */
- public List<ConsulServiceHealth> getServiceHealth(String serviceName);
-
- /**
- * Gets the status for the specified service on all nodes for the specified
- * time window.
- *
- * @param serviceName
- * Service name
- * @param start
- * Start (earliest point) of the time window
- * @param end
- * End (latest point) of the time window
- * @return List of ConsulServiceHealth
- */
- public List<ConsulServiceHealthHistory> getServiceHealthHistory(String serviceName, Instant start, Instant end);
-
- /**
- * Gets all the nodes that are monitored by Consul.
- *
- * @return List of ConsulNodeHealth
- */
- public List<ConsulNodeInfo> getNodes();
-
- /**
- * Gets the status for all registered services running on the specified
- * node.
- *
- * @param nodeId
- * Node ID
- * @return List of ConsulServiceHealth
- */
- public List<ConsulServiceHealth> getNodeServicesHealth(String nodeId);
-
- /**
- * Gets all the data centers that are monitored by Consul.
- *
- * @return List of ConsulDatacenter objects
- */
- public List<ConsulDatacenter> getDatacenters();
-
+ String blueprintsPath = "blueprints";
+ String viewBlueprintsPath = "viewblueprints";
+ String deploymentsPath = "deployments";
+ String executionsPath = "executions";
+ String healthServicesPath = "healthservices";
+
+ /**
+ * Gets the list of Cloudify blueprints.
+ *
+ * @return CloudifyBlueprintList
+ */
+ CloudifyBlueprintList getBlueprints();
+
+ /**
+ * Gets the Cloudify blueprint metadata for the specified ID
+ *
+ * @param id
+ * Blueprint ID
+ * @return CloudifyBlueprintList of size 1; null if not found
+ */
+ CloudifyBlueprintList getBlueprint(String id);
+
+ /**
+ * Gets the Cloudify blueprint content for the specified ID
+ *
+ * @param id
+ * Blueprint ID
+ * @return Blueprint content
+ */
+ CloudifyBlueprintContent viewBlueprint(String id);
+
+ /**
+ * Uploads a Cloudify blueprint.
+ *
+ * @param blueprint
+ * Cloudify Blueprint to upload
+ * @return CloudifyBlueprintList of size 1; null if not found
+ */
+ CloudifyBlueprintList uploadBlueprint(CloudifyBlueprintUpload blueprint);
+
+ /**
+ * Deletes the Cloudify blueprint with the specified id.
+ *
+ * @param id
+ * Blueprint ID
+ * @return Status code; e.g., 200, 202, 204.
+ */
+ int deleteBlueprint(String id);
+
+ /**
+ * Gets the list of Cloudify deployments.
+ *
+ * @return CloudifyDeploymentList
+ */
+ CloudifyDeploymentList getDeployments();
+
+ /**
+ * Gets the Cloudify deployment for the specified ID
+ *
+ * @param id
+ * Deployment ID
+ * @return CloudifyDeploymentList of size 1; null if not found.
+ */
+ CloudifyDeploymentList getDeployment(String id);
+
+ /**
+ * Creates a Cloudify deployment.
+ *
+ * @param deployment
+ * Deployment details
+ * @return CloudifyDeploymentList of size 1
+ */
+ CloudifyDeploymentList createDeployment(CloudifyDeploymentRequest deployment);
+
+ /**
+ * Deletes the Cloudify deployment with the specified id.
+ *
+ * @param id
+ * Deployment ID
+ * @param ignoreLiveNodes
+ * Boolean indicator whether to delete even if live nodes exist
+ * @return Status code; e.g., 200, 202, 204.
+ */
+ int deleteDeployment(String id, boolean ignoreLiveNodes);
+
+ /**
+ * Gets the Cloudify executions for the specified deployment ID
+ *
+ * @param deploymentId
+ * Deployment ID
+ * @return CloudifyExecutionList
+ */
+ CloudifyExecutionList getExecutions(String deploymentId);
+
+ /**
+ * Gets the Cloudify execution for the specified execution ID and deployment
+ * ID
+ *
+ * @param executionId
+ * Execution ID
+ * @param deploymentId
+ * Deployment ID
+ * @return CloudifyExecutionList of size 1
+ */
+ CloudifyExecutionList getExecution(String executionId, String deploymentId);
+
+ /**
+ * Starts a Cloudify execution.
+ *
+ * @param execution
+ * Execution details
+ * @return CloudifyExecution
+ */
+ CloudifyExecution startExecution(CloudifyExecutionRequest execution);
+
+ /**
+ * Deletes the Cloudify execution with the specified ids.
+ *
+ * @param executionId
+ * execution ID
+ * @param deploymentId
+ * Deployment ID
+ * @param action
+ * either "cancel" or "force-cancel"
+ * @return Status code; e.g., 200, 202, 204.
+ */
+ int cancelExecution(String executionId, String deploymentId, String action);
+
+ /**
+ * Registers a service with Consul for health check.
+ *
+ * @param registration
+ * Details about the service to be registered.
+ * @return Result of registering a service
+ */
+ URI registerService(ConsulHealthServiceRegistration registration);
+
+ /**
+ * Deregister a service with Consul for health check.
+ *
+ * @param serviceName
+ * Name of the service to be deregister.
+ * @return Response code
+ */
+ int deregisterService(String serviceName);
+
+ /**
+ * Gets all the services that are monitored by Consul.
+ *
+ * @return List of ConsulServiceHealth
+ */
+ List<ConsulServiceInfo> getServices();
+
+ /**
+ * Gets the status for the specified service on all nodes.
+ *
+ * @param serviceName
+ * Service name
+ * @return List of ConsulServiceHealth
+ */
+ List<ConsulServiceHealth> getServiceHealth(String serviceName);
+
+ /**
+ * Gets the status for the specified service on all nodes for the specified
+ * time window.
+ *
+ * @param serviceName
+ * Service name
+ * @param start
+ * Start (earliest point) of the time window
+ * @param end
+ * End (latest point) of the time window
+ * @return List of ConsulServiceHealth
+ */
+ List<ConsulServiceHealthHistory> getServiceHealthHistory(String serviceName, Instant start, Instant end);
+
+ /**
+ * Gets all the nodes that are monitored by Consul.
+ *
+ * @return List of ConsulNodeHealth
+ */
+ List<ConsulNodeInfo> getNodes();
+
+ /**
+ * Gets the status for all registered services running on the specified
+ * node.
+ *
+ * @param nodeId
+ * Node ID
+ * @return List of ConsulServiceHealth
+ */
+ List<ConsulServiceHealth> getNodeServicesHealth(String nodeId);
+
+ /**
+ * Gets all the data centers that are monitored by Consul.
+ *
+ * @return List of ConsulDatacenter objects
+ */
+ List<ConsulDatacenter> getDatacenters();
}