diff options
author | ramprasad kotagiri <rp5662@att.com> | 2019-03-07 15:55:26 -0500 |
---|---|---|
committer | Timoney, Dan (dt5972) <dtimoney@att.com> | 2019-03-13 20:34:06 -0400 |
commit | 2e98a6c64dcdc0891f3729abb045115b790a2c54 (patch) | |
tree | b500d9c108e4eb520a8e00c3f39d7acdfd878728 /ccsdk-app-common | |
parent | 3df51c6bb79df182be4f0f1bac20bde75f434494 (diff) |
Latest code base
Change-Id: I9549091ebeeabcef2d7af7d91cc394d8371e496b
Issue-ID: CCSDK-1011
Signed-off-by: ramprasad kotagiri <rp5662@att.com>
Diffstat (limited to 'ccsdk-app-common')
129 files changed, 12898 insertions, 3482 deletions
diff --git a/ccsdk-app-common/pom.xml b/ccsdk-app-common/pom.xml index be05119..e7a58c6 100644 --- a/ccsdk-app-common/pom.xml +++ b/ccsdk-app-common/pom.xml @@ -15,11 +15,13 @@ <springframework.version>4.2.0.RELEASE</springframework.version>
<hibernate.version>4.3.11.Final</hibernate.version>
<eelf.version>1.0.0</eelf.version>
- <epsdk.version>2.1.0</epsdk.version>
+ <epsdk.version>2.5.1</epsdk.version>
<nexusproxy>https://nexus.onap.org</nexusproxy>
- <snapshotNexusPath>/content/repositories/snapshots/</snapshotNexusPath>
- <releaseNexusPath>/content/repositories/releases/</releaseNexusPath>
- <skipTests>true</skipTests>
+ <snapshotNexusPath>content/repositories/snapshots/</snapshotNexusPath>
+ <releaseNexusPath>content/repositories/releases/</releaseNexusPath>
+ <stagingNexusPath>/content/repositories/staging/</stagingNexusPath>
+ <skipTests>false</skipTests>
+ <jacocoVersion>0.7.6.201602180812</jacocoVersion>
</properties>
<repositories>
@@ -35,6 +37,12 @@ <name>OpenECOMP - Snapshot Repository</name>
<url>${nexusproxy}/${snapshotNexusPath}</url>
</repository>
+ <repository>
+ <!-- Staging repository has ECOMP release staging artifacts -->
+ <id>onap-staging</id>
+ <name>ONAP - Staging Repository</name>
+ <url>${nexusproxy}${stagingNexusPath}</url>
+ </repository>
</repositories>
<!-- disable doclint, a new feature in Java 8, when generating javadoc -->
@@ -115,7 +123,6 @@ </execution>
</executions>
</plugin>
-
<!-- no deployment needed -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -125,12 +132,53 @@ <skip>true</skip>
</configuration>
</plugin>
-
+ <!-- jacoco -->
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>${jacocoVersion}</version>
+ <executions>
+ <execution>
+ <id>prepare-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ <configuration>
+ <destFile>${project.build.directory}/code-coverage/jacoco-ut.exec</destFile>
+ </configuration>
+ </execution>
+ <execution>
+ <id>post-unit-test</id>
+ <phase>test</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ <configuration>
+ <dataFile>${project.build.directory}/code-coverage/jacoco-ut.exec</dataFile>
+ <outputDirectory>${project.basedir}/target/site/jacoco</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <jacoco-agent.destfile>${project.build.directory}/code-coverage/jacoco-ut.exec</jacoco-agent.destfile>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
</plugins>
</build>
<dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <version>2.0</version>
+ </dependency>
<!-- For using HTTP Basic Auth in uService REST client -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
@@ -168,17 +216,27 @@ <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
- <version>2.6.3</version>
+ <version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
- <version>2.6.3</version>
+ <version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
- <version>2.6.3</version>
+ <version>2.9.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.datatype</groupId>
+ <artifactId>jackson-datatype-jdk8</artifactId>
+ <version>2.9.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.dataformat</groupId>
+ <artifactId>jackson-dataformat-yaml</artifactId>
+ <version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
@@ -237,6 +295,13 @@ <artifactId>spring-webmvc</artifactId>
<version>${springframework.version}</version>
</dependency>
+ <!-- Jacoco for offline instrumentation -->
+ <dependency>
+ <groupId>org.jacoco</groupId>
+ <artifactId>org.jacoco.agent</artifactId>
+ <version>${jacocoVersion}</version>
+ <classifier>runtime</classifier>
+ </dependency>
</dependencies>
<!-- no distributionManagement section; no jars pushed to Maven central -->
diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/Authorizer.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/Authorizer.java new file mode 100644 index 0000000..149708f --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/Authorizer.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.controller; + +import java.io.IOException; +import java.util.Collections; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.web.support.AppUtils; + +public class Authorizer { + + private static Authorizer authorizer = new Authorizer(); + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(Authorizer.class); + private static final String AUTH_PROP_FILE_NAME = "authorizer.properties"; + private static final String DCAE_ROLES_KEY = "dcae_roles"; + + public static Authorizer getAuthorizer() { + return authorizer; + } + + public boolean isAuthorized(HttpServletRequest request) { + final String method = request.getMethod(); + final String resource = request.getRequestURI(); + + final Set<Authorizer.Role> authorizedRoles = getAuthorizedRoles(method, resource); + + // Anybody can access this page, no need to check + if (authorizedRoles.contains(Role.ANY)) { + return true; + } + + final Set<Authorizer.Role> roles = getRoles(request); + final Set<Authorizer.Role> intersection = new HashSet<> (roles); + + intersection.retainAll(authorizedRoles); // Removes all roles in roles that aren't contained in authorizedRoles. + + return !intersection.isEmpty(); //If the intersection is not empty, then this user is authorized + } + + // Helper method to set roles + public void putRoles(HttpServletRequest request, Set<Role> roles) { + request.getSession().setAttribute(DCAE_ROLES_KEY, roles); + } + + // Returns roles for the current user making the request + @SuppressWarnings("unchecked") + private Set<Authorizer.Role> getRoles(HttpServletRequest request) { + + // If roles is empty, then write the user's roles to the session + if (request.getSession().getAttribute(DCAE_ROLES_KEY) == null) { + + // HashSet to be used to for putRoles + HashSet<Role> roles = new HashSet<>(); + roles.add(Role.READER); + + // Get roles and turn into list of role objects + HttpSession session = AppUtils.getSession(request); + String roleType = (String)session.getAttribute("auth_role"); + if (roleType != null) { + switch (roleType) { + case "ADMIN": roles.add(Role.ADMIN); + break; + case "WRITE": roles.add(Role.WRITER); + break; + case "READ": roles.add(Role.READER); + break; + default: roles.add(Role.READER); + break; + } + } + // Write user roles + putRoles(request, roles); + } + + // Check if attribute DCAE_ROLES_KEY is valid + final Object rawRoles = request.getSession().getAttribute(DCAE_ROLES_KEY); + + if (!(rawRoles instanceof Set<?>)) { + throw new RuntimeException("Unrecognized object found in session for key=" + DCAE_ROLES_KEY); + } + + return (Set<Authorizer.Role>) request.getSession().getAttribute(DCAE_ROLES_KEY); + } + + // Returns roles authorized to perform the requested method (i.e. getAuthorizedRoles("POST", "/ecd-app-att/deployments")) + private Set<Authorizer.Role> getAuthorizedRoles(String method, String resource) { + final Properties resourceRoles = new Properties(); + + try { + resourceRoles.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(AUTH_PROP_FILE_NAME)); + + final String[] splitMethodResourceKey = (method + resource.replace("/", ".")).split("\\.",0); + final String methodResourceKey = splitMethodResourceKey[0] + "." + splitMethodResourceKey[2]; + + if (!resourceRoles.containsKey(methodResourceKey)) { + LOGGER.warn(AUTH_PROP_FILE_NAME + " does not contain roles for " + methodResourceKey + "; defaulting " + Authorizer.Role.ANY); + return new HashSet<> (Collections.singleton(Role.ANY)); + } + + final String[] rawAuthorizedRoles = ((String) resourceRoles.get(methodResourceKey)).split(","); + final Set<Authorizer.Role> authorizedRoles = new HashSet<> (); + + for (String rawAuthorizedRole : rawAuthorizedRoles) { + authorizedRoles.add(Authorizer.Role.valueOf(rawAuthorizedRole)); + } + + return authorizedRoles; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public enum Role { + ADMIN, + READER, + WRITER, + ANY, + NONE; + } + + +}
\ No newline at end of file diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/CloudifyController.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/CloudifyController.java index 7b05841..d7cdc6f 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/CloudifyController.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/CloudifyController.java @@ -1,637 +1,1376 @@ -/*******************************************************************************
- * =============LICENSE_START=========================================================
- *
- * =================================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *******************************************************************************/
-package org.onap.ccsdk.dashboard.controller;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.onap.ccsdk.dashboard.model.CloudifyDeploymentList;
-import org.onap.ccsdk.dashboard.model.CloudifyExecutionRequest;
-import org.onap.ccsdk.dashboard.exception.DashboardControllerException;
-import org.onap.ccsdk.dashboard.model.CloudifyBlueprint;
-import org.onap.ccsdk.dashboard.model.CloudifyBlueprintUpload;
-import org.onap.ccsdk.dashboard.model.CloudifyDeployment;
-import org.onap.ccsdk.dashboard.model.CloudifyDeploymentRequest;
-import org.onap.ccsdk.dashboard.model.CloudifyExecution;
-import org.onap.ccsdk.dashboard.model.CloudifyExecutionList;
-import org.onap.ccsdk.dashboard.model.ECTransportModel;
-import org.onap.ccsdk.dashboard.model.RestResponseError;
-import org.onap.ccsdk.dashboard.model.RestResponsePage;
-import org.onap.ccsdk.dashboard.rest.IControllerRestClient;
-import org.onap.portalsdk.core.domain.User;
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.onap.portalsdk.core.util.SystemProperties;
-import org.onap.portalsdk.core.web.support.UserUtils;
-import org.slf4j.MDC;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.client.HttpStatusCodeException;
-
-/**
- * Controller for Cloudify features: blueprints, deployments, executions.
- * Methods serve Ajax requests made by Angular scripts on pages that show
- * content.
- */
-@Controller
-@RequestMapping("/")
-public class CloudifyController extends DashboardRestrictedBaseController {
-
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CloudifyController.class);
-
- /**
- * Enum for selecting an item type.
- */
- public enum CloudifyDataItem {
- BLUEPRINT, DEPLOYMENT, EXECUTION;
- }
-
- private static final String BLUEPRINTS_PATH = "blueprints";
- private static final String VIEW_BLUEPRINTS_PATH = "viewblueprints";
- private static final String DEPLOYMENTS_PATH = "deployments";
- private static final String EXECUTIONS_PATH = "executions";
-
- /**
- * Supports sorting blueprints by ID
- */
- private static Comparator<CloudifyBlueprint> blueprintComparator = Comparator.comparing(o -> o.id);
-
- /**
- * Supports sorting deployments by ID
- */
- private static Comparator<CloudifyDeployment> deploymentComparator = Comparator.comparing(o -> o.id);
-
- /**
- * Supports sorting executions by ID
- */
- private static Comparator<CloudifyExecution> executionComparator = Comparator.comparing(o -> o.id);
-
- /**
- * Gets one page of objects and supporting information via the REST client.
- * On success, returns a PaginatedRestResponse object as String.
- *
- * @param option
- * Specifies which item list type to get
- * @param pageNum
- * Page number of results
- * @param pageSize
- * Number of items per browser page
- * @return JSON block as String, see above.
- * @throws DashboardControllerException
- * On any error; e.g., Network failure.
- */
- @SuppressWarnings({"rawtypes", "unchecked"})
- private String getItemListForPage(long userId, CloudifyDataItem option, int pageNum, int pageSize)
- throws DashboardControllerException, JsonProcessingException {
- IControllerRestClient restClient = getControllerRestClient(userId);
- List itemList;
- switch (option) {
- case BLUEPRINT:
- itemList = restClient.getBlueprints().items;
- itemList.sort(blueprintComparator);
- break;
- case DEPLOYMENT:
- itemList = restClient.getDeployments().items;
- itemList.sort(deploymentComparator);
- break;
- default:
- throw new DashboardControllerException(
- "getItemListForPage failed: unimplemented case: " + option.name());
- }
-
- // Shrink if needed
- final int totalItems = itemList.size();
- final int pageCount = (int) Math.ceil((double) totalItems / pageSize);
- if (totalItems > pageSize) {
- itemList = getPageOfList(pageNum, pageSize, itemList);
- }
- RestResponsePage<List> model = new RestResponsePage<>(totalItems, pageCount, itemList);
- return objectMapper.writeValueAsString(model);
- }
-
- /**
- * Gets one page of the specified items. This method traps exceptions and
- * constructs an appropriate JSON block to report errors.
- *
- * @param request
- * Inbound request
- * @param option
- * Item type to get
- * @return JSON with one page of objects; or an error.
- */
- protected String getItemListForPageWrapper(HttpServletRequest request, CloudifyDataItem option) {
- String outboundJson = null;
- try {
- User appUser = UserUtils.getUserSession(request);
- if (appUser == null || appUser.getLoginId() == null || appUser.getLoginId().length() == 0) {
- throw new DashboardControllerException("getItemListForPageWrapper: Failed to get application user");
- }
- int pageNum = getRequestPageNumber(request);
- int pageSize = getRequestPageSize(request);
- outboundJson = getItemListForPage(appUser.getId(), option, pageNum, pageSize);
- } catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "getItemListForPageWrapper caught exception", ex);
- RestResponseError result;
- if (ex instanceof HttpStatusCodeException) {
- result = new RestResponseError(((HttpStatusCodeException) ex).getResponseBodyAsString());
- } else {
- result = new RestResponseError("Failed to get " + option.name(), ex);
- }
- try {
- outboundJson = objectMapper.writeValueAsString(result);
- } catch (JsonProcessingException jpe) {
- // Should never, ever happen
- outboundJson = "{ \"error\" : \"" + jpe.toString() + "\"}";
- }
- }
- return outboundJson;
- }
-
- /**
- * Serves one page of blueprints
- *
- * @param request
- * HttpServletRequest
- * @return List of CloudifyBlueprint objects
- */
- @RequestMapping(value = {BLUEPRINTS_PATH}, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getBlueprintsByPage(HttpServletRequest request) {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- String json = getItemListForPageWrapper(request, CloudifyDataItem.BLUEPRINT);
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return json;
- }
-
- /**
- * Serves one page of deployments
- *
- * @param request
- * HttpServletRequest
- * @return List of CloudifyDeployment objects
- */
- @RequestMapping(value = {DEPLOYMENTS_PATH}, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getDeploymentsByPage(HttpServletRequest request) {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- String json = getItemListForPageWrapper(request, CloudifyDataItem.DEPLOYMENT);
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return json;
- }
-
- /**
- * Gets the specified blueprint metadata.
- *
- * @param id
- * Blueprint ID
- * @param request
- * HttpServletRequest
- * @return Blueprint as JSON; or error.
- * @throws JsonProcessingException
- * on serialization error
- *
- */
- @RequestMapping(value = {BLUEPRINTS_PATH + "/{id}"}, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getBlueprintById(@PathVariable("id") String id, HttpServletRequest request)
- throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.getBlueprint(id);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("getBlueprintById failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
-
- /**
- * Gets the specified blueprint content for viewing.
- *
- * @param id
- * Blueprint ID
- * @param request
- * HttpServletRequest
- * @return Blueprint as YAML; or error.
- * @throws JsonProcessingException
- * on serialization error
- *
- */
- @RequestMapping(value = {
- VIEW_BLUEPRINTS_PATH + "/{id}"}, method = RequestMethod.GET, produces = "application/yaml")
- @ResponseBody
- public String viewBlueprintContentById(@PathVariable("id") String id, HttpServletRequest request)
- throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.viewBlueprint(id);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("getBlueprintContentById failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
-
- /**
- * Processes request to upload a blueprint from a remote server.
- *
- * @param request
- * HttpServletRequest
- * @param blueprint
- * Cloudify blueprint
- * @return Blueprint as uploaded; or error.
- * @throws JsonProcessingException
- * on serialization error
- */
- @RequestMapping(value = {BLUEPRINTS_PATH}, method = RequestMethod.POST, produces = "application/json")
- @ResponseBody
- public String uploadBlueprint(HttpServletRequest request, @RequestBody CloudifyBlueprintUpload blueprint)
- throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.uploadBlueprint(blueprint);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("uploadBlueprint failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
-
- /**
- * Deletes the specified blueprint.
- *
- * @param id
- * Blueprint ID
- * @param request
- * HttpServletRequest
- * @param response
- * HttpServletResponse
- * @return No content on success; error on failure.
- * @throws JsonProcessingException
- * On serialization failure
- */
- @RequestMapping(value = {BLUEPRINTS_PATH + "/{id}"}, method = RequestMethod.DELETE, produces = "application/json")
- @ResponseBody
- public String deleteBlueprint(@PathVariable("id") String id, HttpServletRequest request,
- HttpServletResponse response) throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- int code = restClient.deleteBlueprint(id);
- response.setStatus(code);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("deleteBlueprint failed on ID " + id, t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- if (result == null) {
- return null;
- } else {
- return objectMapper.writeValueAsString(result);
- }
- }
-
- /**
- * Gets the specified deployment.
- *
- * @param id
- * Deployment ID
- * @param request
- * HttpServletRequest
- * @return Deployment for the specified ID; error on failure.
- * @throws JsonProcessingException
- * On serialization failure
- *
- */
- @RequestMapping(value = {DEPLOYMENTS_PATH + "/{id}"}, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getDeploymentById(@PathVariable("id") String id, HttpServletRequest request)
- throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.getDeployment(id);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("getDeploymentById failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
-
- /**
- * Processes request to create a deployment based on a blueprint.
- *
- * @param request
- * HttpServletRequest
- * @param deployment
- * Deployment to upload
- * @return Body of deployment; error on failure
- * @throws JsonProcessingException
- * On serialization failure
- */
- @RequestMapping(value = {DEPLOYMENTS_PATH}, method = RequestMethod.POST, produces = "application/json")
- @ResponseBody
- public String createDeployment(HttpServletRequest request, @RequestBody CloudifyDeploymentRequest deployment)
- throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.createDeployment(deployment);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("createDeployment failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
-
- /**
- * Deletes the specified deployment.
- *
- * @param id
- * Deployment ID
- * @param ignoreLiveNodes
- * Boolean indicator whether to force a delete in case of live
- * nodes
- * @param request
- * HttpServletRequest
- * @param response
- * HttpServletResponse
- * @return Passes through HTTP status code from remote endpoint; no body on
- * success
- * @throws JsonProcessingException
- * on serialization failure
- */
- @RequestMapping(value = {
- DEPLOYMENTS_PATH + "/{id}"}, method = RequestMethod.DELETE, produces = "application/json")
- @ResponseBody
- public String deleteDeployment(@PathVariable("id") String id,
- @RequestParam(value = "ignore_live_nodes", required = false) Boolean ignoreLiveNodes,
- HttpServletRequest request, HttpServletResponse response) throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- int code = restClient.deleteDeployment(id, ignoreLiveNodes == null ? false : ignoreLiveNodes);
- response.setStatus(code);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("deleteDeployment failed on ID " + id, t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- if (result == null) {
- return null;
- } else {
- return objectMapper.writeValueAsString(result);
- }
- }
-
- /**
- * Gets and serves one page of executions:
- * <OL>
- * <LI>Gets all deployments; OR uses the specified deployment ID if the
- * query parameter is present
- * <LI>Gets executions for each deployment ID
- * <LI>Sorts by execution ID
- * <LI>Reduces the list to the page size (if needed)
- * <LI>If the optional request parameter "status" is present, reduces the
- * list to the executions with that status.
- * </OL>
- *
- * @param request
- * HttpServletRequest
- * @param deployment_id
- * Optional request parameter; if found, only executions for that
- * deployment ID are returned.
- * @param status
- * Optional request parameter; if found, only executions with
- * that status are returned.
- * @return List of CloudifyExecution objects
- * @throws JsonProcessingException
- * on serialization failure
- */
- @SuppressWarnings("unchecked")
- @RequestMapping(value = {EXECUTIONS_PATH}, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getExecutionsByPage(HttpServletRequest request,
- @RequestParam(value = "deployment_id", required = false) String deployment_id,
- @RequestParam(value = "status", required = false) String status) throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- List<CloudifyExecution> itemList = new ArrayList<>();
- IControllerRestClient restClient = getControllerRestClient(request);
- List<String> depIds = new ArrayList<>();
- if (deployment_id == null) {
- CloudifyDeploymentList depList = restClient.getDeployments();
- for (CloudifyDeployment cd : depList.items) {
- depIds.add(cd.id);
- }
- } else {
- depIds.add(deployment_id);
- }
- for (String depId : depIds) {
- CloudifyExecutionList exeList = restClient.getExecutions(depId);
- itemList.addAll(exeList.items);
- }
- // Filter down to specified status as needed
- if (status != null) {
- itemList.removeIf(ce -> !status.equals(ce.status));
- }
- itemList.sort(executionComparator);
-
- // Paginate
- final int pageNum = getRequestPageNumber(request);
- final int pageSize = getRequestPageSize(request);
- final int totalItems = itemList.size();
- final int pageCount = (int) Math.ceil((double) totalItems / pageSize);
- // Shrink if needed
- if (totalItems > pageSize) {
- itemList = getPageOfList(pageNum, pageSize, itemList);
- }
- result = new RestResponsePage<>(totalItems, pageCount, itemList);
- } catch (Exception t) {
- result = new RestResponseError("getExecutionsByPage failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
-
- /**
- * Gets the specified execution for one deployment.
- *
- * It's not clear why the deployment ID is needed.
- *
- * @param execution_id
- * Execution ID (path variable)
- * @param deployment_id
- * Deployment ID (query parameter)
- * @param request
- * HttpServletRequest
- * @return CloudifyExecutionList
- * @throws JsonProcessingException
- * on serialization failure
- */
- @RequestMapping(value = {EXECUTIONS_PATH + "/{id}"}, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getExecutionByIdAndDeploymentId(@PathVariable("id") String execution_id,
- @RequestParam("deployment_id") String deployment_id, HttpServletRequest request)
- throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.getExecutions(deployment_id);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("getExecutionByIdAndDeploymentId failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
-
- /**
- * Processes request to create an execution based on a deployment.
- *
- * @param request
- * HttpServletRequest
- * @param execution
- * Execution model
- * @return Information about the execution
- * @throws JsonProcessingException
- * on serialization failure
- */
- @RequestMapping(value = {EXECUTIONS_PATH}, method = RequestMethod.POST, produces = "application/json")
- @ResponseBody
- public String startExecution(HttpServletRequest request, @RequestBody CloudifyExecutionRequest execution)
- throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- result = restClient.startExecution(execution);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("startExecution failed", t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- return objectMapper.writeValueAsString(result);
- }
-
- /**
- * Cancels an execution.
- *
- * @param id
- * Execution ID
- * @param deploymentId
- * Deployment ID (not clear why this is needed)
- * @param action
- * Action to perform (not clear why this is needed)
- * @param request
- * HttpServletRequest
- * @param response
- * HttpServletRequest
- * @return Passes through HTTP status code from remote endpoint; no body on success
- * @throws JsonProcessingException
- * on serialization failure
- */
- @RequestMapping(value = {EXECUTIONS_PATH + "/{id}"}, method = RequestMethod.DELETE, produces = "application/json")
- @ResponseBody
- public String cancelExecution(@PathVariable("id") String id,
- @RequestParam(value = "deployment_id") String deploymentId, @RequestParam(value = "action") String action,
- HttpServletRequest request, HttpServletResponse response) throws JsonProcessingException {
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(new Date()));
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- ECTransportModel result = null;
- try {
- IControllerRestClient restClient = getControllerRestClient(request);
- int code = restClient.cancelExecution(id, deploymentId, action);
- response.setStatus(code);
- } catch (HttpStatusCodeException e) {
- result = new RestResponseError(e.getResponseBodyAsString());
- } catch (Exception t) {
- result = new RestResponseError("cancelExecution failed on ID " + id, t);
- }
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(new Date()));
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- if (result == null) {
- return null;
- } else {
- return objectMapper.writeValueAsString(result);
- }
- }
-}
+/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.controller; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.ccsdk.dashboard.model.CloudifyBlueprint; +import org.onap.ccsdk.dashboard.model.CloudifyBlueprintList; +import org.onap.ccsdk.dashboard.model.CloudifyBlueprintUpload; +import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenant; +import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenantList; +import org.onap.ccsdk.dashboard.model.CloudifyDeployment; +import org.onap.ccsdk.dashboard.model.CloudifyDeploymentList; +import org.onap.ccsdk.dashboard.model.CloudifyDeploymentRequest; +import org.onap.ccsdk.dashboard.model.CloudifyDeploymentUpdateRequest; +import org.onap.ccsdk.dashboard.model.CloudifyEvent; +import org.onap.ccsdk.dashboard.model.CloudifyEventList; +import org.onap.ccsdk.dashboard.model.CloudifyExecution; +import org.onap.ccsdk.dashboard.model.CloudifyExecutionList; +import org.onap.ccsdk.dashboard.model.CloudifyExecutionRequest; +import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceIdList; +import org.onap.ccsdk.dashboard.model.CloudifyTenant; +import org.onap.ccsdk.dashboard.model.ECTransportModel; +import org.onap.ccsdk.dashboard.model.RestResponseError; +import org.onap.ccsdk.dashboard.model.RestResponsePage; +import org.onap.ccsdk.dashboard.rest.CloudifyClient; +import org.onap.ccsdk.dashboard.util.DashboardProperties; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.slf4j.MDC; +import org.springframework.http.HttpHeaders; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.client.HttpStatusCodeException; + +import com.fasterxml.jackson.core.JsonProcessingException; + +/** + * Controller for Cloudify features: blueprints, deployments, executions. + * Methods serve Ajax requests made by Angular scripts on pages that show + * content. + */ +@Controller +@RequestMapping("/") +public class CloudifyController extends DashboardRestrictedBaseController { + + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CloudifyController.class); + private CloudifyClient restClient; + + /** + * Enum for selecting an item type. + */ + public enum CloudifyDataItem { + BLUEPRINT, DEPLOYMENT, EXECUTION, TENANT; + } + + private static Date begin; + private static Date end; + private static final String BLUEPRINTS_PATH = "blueprints"; + private static final String VIEW_BLUEPRINTS_PATH = "viewblueprints"; + private static final String DEPLOYMENTS_PATH = "deployments"; + private static final String EXECUTIONS_PATH = "executions"; + private static final String TENANTS_PATH = "tenants"; + private static final String NODE_INSTANCES_PATH = "node-instances"; + private static final String UPDATE_DEPLOYMENT_PATH = "update-deployment"; + private static final String SECRETS_PATH = "secrets"; + private static final String EVENTS_PATH = "events"; + private static final String DEP_TENANT_STATUS = "deployment-status"; + + /** + * Supports sorting blueprints by ID + */ + private static Comparator<CloudifyBlueprint> blueprintComparator = new Comparator<CloudifyBlueprint>() { + @Override + public int compare(CloudifyBlueprint o1, CloudifyBlueprint o2) { + return o1.id.compareTo(o2.id); + } + }; + + /** + * Supports sorting deployments by ID + */ + private static Comparator<CloudifyDeployment> deploymentComparator = new Comparator<CloudifyDeployment>() { + @Override + public int compare(CloudifyDeployment o1, CloudifyDeployment o2) { + return o1.id.compareTo(o2.id); + } + }; + + /** + * Supports sorting events by timestamp + */ + private static Comparator<CloudifyEvent> eventComparator = new Comparator<CloudifyEvent>() { + @Override + public int compare(CloudifyEvent o1, CloudifyEvent o2) { + return o1.reported_timestamp.compareTo(o2.reported_timestamp); + } + }; + + /** + * Supports sorting executions by timestamp + */ + private static Comparator<CloudifyExecution> executionComparator = new Comparator<CloudifyExecution>() { + @Override + public int compare(CloudifyExecution o1, CloudifyExecution o2) { + return o1.created_at.compareTo(o2.created_at); + } + }; + /** + * Gets one page of objects and supporting information via the REST client. + * On success, returns a PaginatedRestResponse object as String. + * + * @param option + * Specifies which item list type to get + * @param pageNum + * Page number of results + * @param pageSize + * Number of items per browser page + * @return JSON block as String, see above. + * @throws Exception + * On any error; e.g., Network failure. + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + private String getItemListForPage(long userId, CloudifyDataItem option, int pageNum, int pageSize) + throws Exception { + if (this.restClient == null) { + this.restClient = getCloudifyRestClient(userId); + } + List itemList = null; + switch (option) { + /* + case BLUEPRINT: + itemList = restClient.getBlueprints().items; + Collections.sort(itemList, blueprintComparator); + break; + case DEPLOYMENT: + itemList = restClient.getDeployments().items; + Collections.sort(itemList, deploymentComparator); + break; + */ + case TENANT: + itemList = restClient.getTenants().items; + break; + default: + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting page of items failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getItemListForPage caught exception"); + throw new Exception("getItemListForPage failed: unimplemented case: " + option.name()); + } +/* + String cloudPrimTenant = + getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM); + String aicPrimTenant = + getAppProperties().getProperty(DashboardProperties.AIC_TENANT_PRIM); + + for (CloudifyTenant ct: (List<CloudifyTenant>)itemList) { + if ( ct.name.equals(cloudPrimTenant) ) { + ct.dName = aicPrimTenant; + } else { + ct.dName = ct.name; + } + } + */ + // Shrink if needed + final int totalItems = itemList.size(); + final int pageCount = (int) Math.ceil((double) totalItems / pageSize); + if (totalItems > pageSize) + itemList = getPageOfList(pageNum, pageSize, itemList); + RestResponsePage<List> model = new RestResponsePage<>(totalItems, pageCount, itemList); + String outboundJson = objectMapper.writeValueAsString(model); + return outboundJson; + } + + /** + * Gets one page of the specified items. This method traps exceptions and + * constructs an appropriate JSON block to report errors. + * + * @param request + * Inbound request + * @param option + * Item type to get + * @return JSON with one page of objects; or an error. + */ + protected String getItemListForPageWrapper(HttpServletRequest request, CloudifyDataItem option) { + String outboundJson = null; + try { + User appUser = UserUtils.getUserSession(request); + if (appUser == null || appUser.getLoginId() == null || appUser.getLoginId().length() == 0) + throw new Exception("getItemListForPageWrapper: Failed to get application user"); + int pageNum = getRequestPageNumber(request); + int pageSize = getRequestPageSize(request); + outboundJson = getItemListForPage(appUser.getId(), option, pageNum, pageSize); + } catch (Exception ex) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting page of items failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getItemListForPageWrapper caught exception"); + RestResponseError result = null; + if (ex instanceof HttpStatusCodeException) + result = new RestResponseError(((HttpStatusCodeException) ex).getResponseBodyAsString()); + else + result = new RestResponseError("Failed to get " + option.name(), ex); + try { + outboundJson = objectMapper.writeValueAsString(result); + } catch (JsonProcessingException jpe) { + // Should never, ever happen + outboundJson = "{ \"error\" : \"" + jpe.toString() + "\"}"; + } + } + return outboundJson; + } + + /** + * Serves one page of blueprints + * + * @param request + * HttpServletRequest + * @return List of CloudifyBlueprint objects + */ + @RequestMapping(value = { BLUEPRINTS_PATH }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getBlueprintsByPage(HttpServletRequest request) { + preLogAudit(request); + String json = getItemListForPageWrapper(request, CloudifyDataItem.BLUEPRINT); + postLogAudit(request); + return json; + } + + /** + * Serves one page of deployments + * + * @param request + * HttpServletRequest + * @return List of CloudifyDeployment objects + */ + @RequestMapping(value = { DEPLOYMENTS_PATH }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getDeploymentsByPage(HttpServletRequest request) { + preLogAudit(request); + String json = getItemListForPageWrapper(request, CloudifyDataItem.DEPLOYMENT); + postLogAudit(request); + return json; + } + + /** + * gets the tenants list + * + * @param request + * HttpServletRequest + * @return List of CloudifyDeployment objects + */ + @RequestMapping(value = { TENANTS_PATH }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getTenants(HttpServletRequest request) { + preLogAudit(request); + String json = getItemListForPageWrapper(request, CloudifyDataItem.TENANT); + postLogAudit(request); + return json; + } + + /** + * Gets the specified blueprint metadata. + * + * @param id + * Blueprint ID + * @param request + * HttpServletRequest + * @return Blueprint as JSON; or error. + * @throws Exception + * on serialization error + * + */ + @RequestMapping(value = { BLUEPRINTS_PATH + "/{id}" }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getBlueprintById(@PathVariable("id") String id, + @RequestParam(value = "tenant", required = true) String tenant, + HttpServletRequest request) throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + restClient = getCloudifyRestClient(request); + result = restClient.getBlueprint(id, tenant); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting blueprint " + id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getBlueprintById caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting blueprint " + id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getBlueprintById caught exception"); + result = new RestResponseError("getBlueprintById failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + /** + * Gets the specified blueprint content for viewing. + * + * @param id + * Blueprint ID + * @param request + * HttpServletRequest + * @return Blueprint as YAML; or error. + * @throws Exception + * on serialization error + * + */ + @RequestMapping(value = { + VIEW_BLUEPRINTS_PATH + "/{id}" }, method = RequestMethod.GET, produces = "application/yaml") + @ResponseBody + public String viewBlueprintContentById(@PathVariable("id") String id, HttpServletRequest request) throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + restClient = getCloudifyRestClient(request); + result = restClient.viewBlueprint(id); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Viewing blueprint " + id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "viewBlueprintContentById caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Viewing blueprint " + id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "viewBlueprintContentById caught exception"); + result = new RestResponseError("getBlueprintContentById failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + /** + * Processes request to upload a blueprint from a remote server. + * + * @param request + * HttpServletRequest + * @param blueprint + * Cloudify blueprint + * @return Blueprint as uploaded; or error. + * @throws Exception + * on serialization error + */ + @RequestMapping(value = { BLUEPRINTS_PATH }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public String uploadBlueprint(HttpServletRequest request, @RequestBody CloudifyBlueprintUpload blueprint) + throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + CloudifyClient restClient = getCloudifyRestClient(request); + result = restClient.uploadBlueprint(blueprint); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Uploading blueprint failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "uploadBlueprint caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Uploading blueprint failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "uploadBlueprint caught exception"); + result = new RestResponseError("uploadBlueprint failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + /** + * Deletes the specified blueprint. + * + * @param id + * Blueprint ID + * @param request + * HttpServletRequest + * @param response + * HttpServletResponse + * @return No content on success; error on failure. + * @throws Exception + * On serialization failure + */ + @RequestMapping(value = { BLUEPRINTS_PATH + "/{id}" }, method = RequestMethod.DELETE, produces = "application/json") + @ResponseBody + public String deleteBlueprint(@PathVariable("id") String id, HttpServletRequest request, + HttpServletResponse response) throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + CloudifyClient restClient = getCloudifyRestClient(request); + int code = restClient.deleteBlueprint(id); + response.setStatus(code); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting blueprint " + id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteBlueprint caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting blueprint " + id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteBlueprint caught exception"); + result = new RestResponseError("deleteBlueprint failed on ID " + id, t); + } finally { + postLogAudit(request); + } + if (result == null) + return null; + else + return objectMapper.writeValueAsString(result); + } + + /** + * Gets the specified deployment. + * + * @param id + * Deployment ID + * @param request + * HttpServletRequest + * @return Deployment for the specified ID; error on failure. + * @throws Exception + * On serialization failure + * + */ + @RequestMapping(value = { DEPLOYMENTS_PATH + "/{id}" }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getDeploymentById(@PathVariable("id") String id, + @RequestParam(value = "tenant", required = false) String tenant, + HttpServletRequest request) throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + CloudifyClient restClient = getCloudifyRestClient(request); + if (tenant != null && tenant.length() > 0) { + result = restClient.getDeployment(id, tenant); + } else { + result = restClient.getDeployment(id); + } + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting deployment " + id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getDeploymentById caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting deployment " + id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getDeploymentById caught exception"); + result = new RestResponseError("getDeploymentById failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + /** + * Query status and tenant info for deployments + * + */ + @SuppressWarnings("unchecked") + @RequestMapping(value = { DEP_TENANT_STATUS }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public String getTenantStatusForService( HttpServletRequest request, + @RequestBody String[] serviceList) + throws Exception { + preLogAudit(request); + User appUser = UserUtils.getUserSession(request); + if (appUser == null || appUser.getId() == null ) + throw new Exception("getControllerRestClient: Failed to get application user"); + /* + 1) Get all the tenant names + 2) Get the deployment IDs per tenant for all the tenants, aggregate the deployments list + 3) Get the input deployments list (screen input), filter the deployments list from step#2 + 4) For each item in the list from step#3, get the execution status info and generate the final response + */ + ECTransportModel result = null; + HashMap<String, Object> resultMap = new HashMap<String, Object>(); + List<CloudifyDeployedTenant> tenantList = new ArrayList<CloudifyDeployedTenant>(); + List<CloudifyExecution> cfyExecList = new ArrayList<CloudifyExecution>(); + try { + CloudifyClient restClient = getCloudifyRestClient(request); + List<CloudifyTenant> cldfyTen = restClient.getTenants().items; + for (CloudifyTenant ct: (List<CloudifyTenant>)cldfyTen) { + result = restClient.getTenantInfoFromDeploy(ct.name); + tenantList.addAll(((CloudifyDeployedTenantList)result).items); + } + result = null; + List<CloudifyDeployedTenant> currSrvcTenants = new ArrayList<CloudifyDeployedTenant>(); + + for (String serviceId : serviceList) { + for (CloudifyDeployedTenant deplTen: tenantList) { + if (serviceId.equals(deplTen.id)) { + currSrvcTenants.add(deplTen); + break; + } + } + } + // Get concise execution status for each of the tenant deployment items + boolean isHelmType = false; + boolean helmStatus = false; + for (CloudifyDeployedTenant deplItem: currSrvcTenants) { + CloudifyExecutionList execResults = restClient.getExecutionsSummary(deplItem.id, deplItem.tenant_name); + isHelmType = false; + helmStatus = false; + CloudifyBlueprintList bpList = restClient.getBlueprint(deplItem.id, deplItem.tenant_name); + Map<String, Object> bpPlan = bpList.items.get(0).plan; + Map<String, String> workflows = (Map<String, String>)bpPlan.get("workflows"); + Map<String, String> pluginInfo = ((List<Map<String, String>>)bpPlan.get("deployment_plugins_to_install")).get(0); + if (pluginInfo.get("name").equals("helm-plugin") ) { + isHelmType = true; + } + if (workflows.containsKey("status")) { + helmStatus = true; + } + /* + for (CloudifyExecution cfyExec: execResults.items) { + if (cfyExec.workflow_id.equalsIgnoreCase("create_deployment_environment")) { + Map<String, String> pluginInfo = ((List<Map<String, String>>)cfyExec.parameters.get("deployment_plugins_to_install")).get(0); + if (pluginInfo.get("name").equals("helm-plugin") ) { + isHelmType = true; + } + } + } + */ + for (CloudifyExecution cfyExec: execResults.items) { + if (cfyExec.workflow_id.equalsIgnoreCase("install")) { + cfyExec.is_helm = isHelmType; + cfyExec.helm_status = helmStatus; + cfyExecList.add(cfyExec); + } + } + } + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting deployments failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getTenantStatusForService caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting deployments failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getTenantStatusForService caught exception"); + result = new RestResponseError("getTenantStatusForService failed", t); + } finally { + postLogAudit(request); + } + + return objectMapper.writeValueAsString(cfyExecList); + } + + /** + * Processes request to create a deployment based on a blueprint. + * + * @param request + * HttpServletRequest + * @param deployment + * Deployment to upload + * @return Body of deployment; error on failure + * @throws Exception + * On serialization failure + */ + @RequestMapping(value = { DEPLOYMENTS_PATH }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public String createDeployment(HttpServletRequest request, @RequestBody CloudifyDeploymentRequest deployment) + throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + CloudifyClient restClient = getCloudifyRestClient(request); + result = restClient.createDeployment(deployment); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Creating deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "createDeployment caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Creating deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "createDeployment caught exception"); + result = new RestResponseError("createDeployment failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + /** + * Deletes the specified deployment. + * + * @param id + * Deployment ID + * @param ignoreLiveNodes + * Boolean indicator whether to force a delete in case of live + * nodes + * @param request + * HttpServletRequest + * @param response + * HttpServletResponse + * @return Passes thru HTTP status code from remote endpoint; no body on + * success + * @throws Exception + * on serialization failure + */ + @RequestMapping(value = { + DEPLOYMENTS_PATH + "/{id}" }, method = RequestMethod.DELETE, produces = "application/json") + @ResponseBody + public String deleteDeployment(@PathVariable("id") String id, + @RequestParam(value = "ignore_live_nodes", required = false) Boolean ignoreLiveNodes, + HttpServletRequest request, HttpServletResponse response) throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + CloudifyClient restClient = getCloudifyRestClient(request); + int code = restClient.deleteDeployment(id, ignoreLiveNodes == null ? false : ignoreLiveNodes); + response.setStatus(code); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting deployment " + id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteDeployment caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting deployment " + id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteDeployment caught exception"); + result = new RestResponseError("deleteDeployment failed on ID " + id, t); + } finally { + postLogAudit(request); + } + if (result == null) + return null; + else + return objectMapper.writeValueAsString(result); + } + + /** + * Gets and serves one page of executions: + * <OL> + * <LI>Gets all deployments; OR uses the specified deployment ID if the + * query parameter is present + * <LI>Gets executions for each deployment ID + * <LI>Sorts by execution ID + * <LI>Reduces the list to the page size (if needed) + * <LI>If the optional request parameter "status" is present, reduces the + * list to the executions with that status. + * </OL> + * + * @param request + * HttpServletRequest + * @param deployment_id + * Optional request parameter; if found, only executions for that + * deployment ID are returned. + * @param status + * Optional request parameter; if found, only executions with + * that status are returned. + * @return List of CloudifyExecution objects + * @throws Exception + * on serialization failure + */ + @SuppressWarnings("unchecked") + @RequestMapping(value = { EXECUTIONS_PATH }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getExecutionsByPage(HttpServletRequest request, + @RequestParam(value = "deployment_id", required = false) String deployment_id, + @RequestParam(value = "status", required = false) String status, + @RequestParam(value = "tenant", required = false) String tenant) throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + List<CloudifyExecution> itemList = new ArrayList<CloudifyExecution>(); + CloudifyClient restClient = getCloudifyRestClient(request); + List<String> depIds = new ArrayList<>(); + if (deployment_id == null) { + CloudifyDeploymentList depList = restClient.getDeployments(); + for (CloudifyDeployment cd : depList.items) + depIds.add(cd.id); + } else { + depIds.add(deployment_id); + } + String cloudPrimTenant = + getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM); + if (tenant == null) { + tenant = cloudPrimTenant; + } + for (String depId : depIds) { + CloudifyExecutionList exeList = restClient.getExecutions(depId, tenant); + itemList.addAll(exeList.items); + } + // Filter down to specified status as needed + if (status != null) { + Iterator<CloudifyExecution> exeIter = itemList.iterator(); + while (exeIter.hasNext()) { + CloudifyExecution ce = exeIter.next(); + if (!status.equals(ce.status)) + exeIter.remove(); + } + } + Collections.sort(itemList, executionComparator); + + // Paginate + final int pageNum = getRequestPageNumber(request); + final int pageSize = getRequestPageSize(request); + final int totalItems = itemList.size(); + final int pageCount = (int) Math.ceil((double) totalItems / pageSize); + // Shrink if needed + if (totalItems > pageSize) + itemList = getPageOfList(pageNum, pageSize, itemList); + result = new RestResponsePage<>(totalItems, pageCount, itemList); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting executions failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getExecutionsByPage caught exception"); + result = new RestResponseError("getExecutionsByPage failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + /** + * Gets the specified execution for one deployment. + * + * It's not clear why the deployment ID is needed. + * + * @param execution_id + * Execution ID (path variable) + * @param deployment_id + * Deployment ID (query parameter) + * @param request + * HttpServletRequest + * @return CloudifyExecutionList + * @throws Exception + * on serialization failure + */ + @RequestMapping(value = { EXECUTIONS_PATH + "/{id}" }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getExecutionByIdAndDeploymentId(@PathVariable("id") String execution_id, + @RequestParam("deployment_id") String deployment_id, + @RequestParam(value = "tenant", required = false) String tenant, + HttpServletRequest request) throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + String cloudPrimTenant = + getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM); + if (tenant == null) { + tenant = cloudPrimTenant; + } + CloudifyClient restClient = getCloudifyRestClient(request); + result = restClient.getExecutions(deployment_id, tenant); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting executions " + execution_id + " for deployment " + deployment_id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getExecutionByIdAndDeploymentId caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting executions " + execution_id + " for deployment " + deployment_id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getExecutionByIdAndDeploymentId caught exception"); + result = new RestResponseError("getExecutionByIdAndDeploymentId failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + /** + * Gets the execution events for specified execution ID. + * + * + * @param execution_id + * Execution ID (request parameter) + * @param tenant + * tenant name (query parameter) + * @param request + * HttpServletRequest + * @return CloudifyExecutionList + * @throws Exception + * on serialization failure + */ + @SuppressWarnings("unchecked") + @RequestMapping(value = { EVENTS_PATH }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getExecutionEventsById(@RequestParam(value = "execution_id", required = false) String execution_id, + @RequestParam(value = "logType", required = false) String isLogEvent, + @RequestParam(value = "tenant", required = false) String tenant, + HttpServletRequest request) throws Exception { + preLogAudit(request); + CloudifyEventList eventsList = null; + ECTransportModel result = null; + try { + String cloudPrimTenant = + getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM); + if (tenant == null) { + tenant = cloudPrimTenant; + } + CloudifyClient restClient = getCloudifyRestClient(request); + eventsList = restClient.getEventlogs(execution_id, tenant); + // Filter down to specified event type as needed + List<CloudifyEvent> itemList = eventsList.items; + if (!isLogEvent.isEmpty() && isLogEvent.equals("false")) { + Iterator<CloudifyEvent> exeIter = itemList.iterator(); + while (exeIter.hasNext()) { + CloudifyEvent ce = exeIter.next(); + if (ce.type.equals("cloudify_log")) { + exeIter.remove(); + } + } + } + Collections.sort(itemList, eventComparator); + Collections.reverse(itemList); + final int pageNum = getRequestPageNumber(request); + final int pageSize = getRequestPageSize(request); + final int totalItems = itemList.size(); + final int pageCount = (int) Math.ceil((double) totalItems / pageSize); + // Shrink if needed + if (totalItems > pageSize) + itemList = getPageOfList(pageNum, pageSize, itemList); + result = new RestResponsePage<>(totalItems, pageCount, itemList); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting executions " + execution_id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getExecutionEventsById caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting executions " + execution_id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getExecutionByIdAndDeploymentId caught exception"); + result = new RestResponseError("getExecutionEventsById failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + /** + * Gets the cloudify secret data for the specified secret name. + * + * + * @param secret_name + * Secret name (path variable) + * @param request + * HttpServletRequest + * @return CloudifySecret + * @throws Exception + * on serialization failure + */ + /* + @RequestMapping(value = { SECRETS_PATH }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getSecrets( + @RequestParam(value = "tenant") String tenant, + HttpServletRequest request) throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + String cloudPrimTenant = + getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM); + if (tenant == null) { + tenant = cloudPrimTenant; + } + IControllerRestClient restClient = getControllerRestClient(); + result = restClient.getSecrets(tenant); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting secrets failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getSecret caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting secrets failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getSecret caught exception"); + result = new RestResponseError("getSecret failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + /** + * Gets the cloudify secret data for the specified secret name. + * + * + * @param secret_name + * Secret name (path variable) + * @param request + * HttpServletRequest + * @return CloudifySecret + * @throws Exception + * on serialization failure + */ + @RequestMapping(value = { SECRETS_PATH + "/{secret_name}"}, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getSecret(@PathVariable("secret_name") String secret_name, + @RequestParam(value = "tenant") String tenant, + HttpServletRequest request) throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + String cloudPrimTenant = + getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM); + if (tenant == null) { + tenant = cloudPrimTenant; + } + CloudifyClient restClient = getCloudifyRestClient(request); + result = restClient.getSecret(secret_name, tenant); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting secret for name " + secret_name + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getSecret caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting secret for name " + secret_name + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getSecret caught exception"); + result = new RestResponseError("getSecret failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + /** + * Processes request to create secrets in cloudify manager. + * + * @param request + * HttpServletRequest + * @param execution + * Execution model + * @return Information about the execution + * @throws Exception + * on serialization failure + */ +/* + @RequestMapping(value = { SECRETS_PATH }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public String createSecret(HttpServletRequest request, @RequestBody CloudifySecretUpload secret) + throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + IControllerRestClient restClient = getControllerRestClient(request); + result = restClient.createSecret(secret); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Starting execution failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "startExecution caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Starting execution failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "startExecution caught exception"); + result = new RestResponseError("startExecution failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + */ + /** + * Processes request to create an execution based on a deployment. + * + * @param request + * HttpServletRequest + * @param execution + * Execution model + * @return Information about the execution + * @throws Exception + * on serialization failure + */ + @RequestMapping(value = { EXECUTIONS_PATH }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public String startExecution(HttpServletRequest request, @RequestBody CloudifyExecutionRequest execution) + throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + CloudifyClient restClient = getCloudifyRestClient(request); + if (!execution.workflow_id.equals("status") && !execution.getParameters().containsKey("node_instance_id")) { + // get the node instance ID for the deployment + String nodeInstId = ""; + CloudifyNodeInstanceIdList nodeInstList = + restClient.getNodeInstanceId(execution.getDeployment_id(), execution.getTenant()); + if (nodeInstList != null) { + nodeInstId = nodeInstList.items.get(0).id; + } + Map<String, Object> inParms = execution.getParameters(); + inParms.put("node_instance_id", nodeInstId); + execution.setParameters(inParms); + } + result = restClient.startExecution(execution); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Starting execution failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "startExecution caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Starting execution failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "startExecution caught exception"); + result = new RestResponseError("startExecution failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + /** + * Processes request to create an execution based on a deployment. + * + * @param request + * HttpServletRequest + * @param execution + * Execution model + * @return Information about the execution + * @throws Exception + * on serialization failure + */ + @RequestMapping(value = { UPDATE_DEPLOYMENT_PATH }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public String updateDeployment(HttpServletRequest request, @RequestBody CloudifyDeploymentUpdateRequest execution) + throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + CloudifyClient restClient = getCloudifyRestClient(request); + result = restClient.updateDeployment(execution); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Updating deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "updateDeployment caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Updating Deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "updateDeployment caught exception"); + result = new RestResponseError("updateDeployment failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + /** + * Cancels an execution. + * + * @param id + * Execution ID + * @param deploymentId + * Deployment ID (not clear why this is needed) + * @param action + * Action to perform (not clear why this is needed) + * @param request + * HttpServletRequest + * @param response + * HttpServletRequest + * @return Passes thru HTTP status code from remote endpoint; no body on + * success + * @throws Exception + * on serialization failure + */ + @RequestMapping(value = { EXECUTIONS_PATH + "/{id}" }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public String cancelExecution( + @RequestHeader HttpHeaders headers, + @PathVariable("id") String id, + @RequestBody Map<String, String> parameters, + HttpServletRequest request, HttpServletResponse response) + throws Exception { + preLogAudit(request); + ECTransportModel result = null; + List<String> tenant = null; + try { + tenant = headers.get("tenant"); + CloudifyClient restClient = getCloudifyRestClient(request); + result = restClient.cancelExecution(id, parameters, tenant.get(0)); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Cancelling execution " + id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "cancelExecution caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Cancelling execution " + id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "cancelExecution caught exception"); + result = new RestResponseError("cancelExecution failed on ID " + id, t); + } finally { + postLogAudit(request); + } + if (result == null) + return null; + else + return objectMapper.writeValueAsString(result); + } + + /** + * Gets the specified node-instance-id content for viewing. + * + * @param id + * deployment ID + * @param id + * node ID + * @param request + * HttpServletRequest + * @return Blueprint as YAML; or error. + * @throws Exception + * on serialization error + * + */ + @RequestMapping(value = { + NODE_INSTANCES_PATH + "/{deploymentId}/{nodeId}" }, method = RequestMethod.GET, produces = "application/yaml") + @ResponseBody + public String getNodeInstanceId(@PathVariable("deploymentId") String deploymentId, + @RequestParam(value = "tenant", required = true) String tenant, + @PathVariable("nodeId") String nodeId, HttpServletRequest request) throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + CloudifyClient restClient = getCloudifyRestClient(request); + result = restClient.getNodeInstanceId(deploymentId, nodeId, tenant); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting node-instance-id with deploymentId " + deploymentId + " and nodeId " + nodeId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getNodeInstanceId caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting node-instance-id with deploymentId " + deploymentId + " and nodeId " + nodeId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getNodeInstanceId caught exception"); + result = new RestResponseError("getNodeInstanceId failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + @RequestMapping(value = { DEPLOYMENTS_PATH + "/{deploymentId}/revisions"}, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getDeploymentRevisions(@PathVariable("deploymentId") String deploymentId, + @RequestParam(value = "tenant") String tenant, + HttpServletRequest request) throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + String cloudPrimTenant = + getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM); + if (tenant == null) { + tenant = cloudPrimTenant; + } + CloudifyClient restClient = getCloudifyRestClient(request); + result = restClient.getNodeInstanceVersion(deploymentId, tenant); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting executions for deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getExecutionByIdAndDeploymentId caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting executions for deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getExecutionByIdAndDeploymentId caught exception"); + result = new RestResponseError("getExecutionByIdAndDeploymentId failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + public void preLogAudit(HttpServletRequest request) { + begin = new Date(); + MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(begin)); + MDC.put(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP, logDateFormat.format(begin)); + MDC.put(SystemProperties.STATUS_CODE, "COMPLETE"); + //logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME); + } + + public void postLogAudit(HttpServletRequest request) { + end = new Date(); + MDC.put("AlertSeverity", "0"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(end)); + MDC.put(SystemProperties.METRICSLOG_END_TIMESTAMP, logDateFormat.format(end)); + MDC.put(SystemProperties.MDC_TIMER, Long.toString((end.getTime() - begin.getTime()))); + logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI()); + logger.info(EELFLoggerDelegate.metricsLogger, request.getMethod() + request.getRequestURI()); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/CommonApiController.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/CommonApiController.java new file mode 100644 index 0000000..3c17288 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/CommonApiController.java @@ -0,0 +1,1226 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ + +package org.onap.ccsdk.dashboard.controller; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Scanner; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.onap.ccsdk.dashboard.domain.EcdComponent; +import org.onap.ccsdk.dashboard.exceptions.BadRequestException; +import org.onap.ccsdk.dashboard.exceptions.DeploymentNotFoundException; +import org.onap.ccsdk.dashboard.exceptions.DownstreamException; +import org.onap.ccsdk.dashboard.exceptions.ServerErrorException; +import org.onap.ccsdk.dashboard.exceptions.ServiceAlreadyExistsException; +import org.onap.ccsdk.dashboard.exceptions.inventory.BlueprintParseException; +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeAlreadyDeactivatedException; +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeNotFoundException; +import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenant; +import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenantList; +import org.onap.ccsdk.dashboard.model.CloudifyExecution; +import org.onap.ccsdk.dashboard.model.CloudifyExecutionList; +import org.onap.ccsdk.dashboard.model.CloudifyExecutionRequest; +import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceIdList; +import org.onap.ccsdk.dashboard.model.CloudifyTenant; +import org.onap.ccsdk.dashboard.model.ECTransportModel; +import org.onap.ccsdk.dashboard.model.RestResponseError; +import org.onap.ccsdk.dashboard.model.RestResponsePage; +import org.onap.ccsdk.dashboard.model.RestResponseSuccess; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentInput; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentRequest; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentResource; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentResourceLinks; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentResponse; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentResponseLinks; +import org.onap.ccsdk.dashboard.model.inventory.Blueprint; +import org.onap.ccsdk.dashboard.model.inventory.BlueprintResponse; +import org.onap.ccsdk.dashboard.model.inventory.Service; +import org.onap.ccsdk.dashboard.model.inventory.ServiceQueryParams; +import org.onap.ccsdk.dashboard.model.inventory.ServiceRefList; +import org.onap.ccsdk.dashboard.model.inventory.ServiceType; +import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeQueryParams; +import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeRequest; +import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeServiceMap; +import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeUploadRequest; +import org.onap.ccsdk.dashboard.rest.CloudifyClient; +import org.onap.ccsdk.dashboard.rest.DeploymentHandlerClient; +import org.onap.ccsdk.dashboard.rest.InventoryClient; +import org.onap.ccsdk.dashboard.service.ControllerEndpointService; +import org.onap.ccsdk.dashboard.util.DashboardProperties; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpHeaders; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.HttpStatusCodeException; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +@RestController +@RequestMapping("/ecomp-api") +public class CommonApiController extends DashboardRestrictedBaseController { + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(DeploymentHandlerController.class); + + private static final String COMPONENTS_PATH = "components"; + private static final String DEPLOYMENTS_PATH = "deployments"; + private static final String SERVICE_TYPES_PATH = "blueprints"; + private static final String EXECUTIONS_PATH = "executions"; + private static final String API_HELP = "docs"; + private static final String DOCS_FILE_NAME = "ecompApiHelp.txt"; + private static final String DEP_IDS_FOR_TYPE = "deployments/typeIds"; + private static final String DEP_TENANT_STATUS = "deployment-status"; + private static final String TENANTS_PATH = "tenants"; + + @Autowired + private ControllerEndpointService controllerEndpointService; + + /** + * Enum for selecting an item type. + */ + public enum InventoryDataItem { + SERVICES, SERVICE_TYPES, SERVICES_GROUPBY; + } + + private static Date begin, end; + + @RequestMapping(value = "/api-docs", method = RequestMethod.GET, produces = "application/json") + public Resource apiDocs() { + return new ClassPathResource("swagger.json"); + } + + @RequestMapping(value = { COMPONENTS_PATH }, method = RequestMethod.POST, produces = "application/json") + public String insertComponent(HttpServletRequest request, @RequestBody EcdComponent newComponent) + throws Exception { + String outboundJson = null; + controllerEndpointService.insertComponent(newComponent); + RestResponseSuccess success = new RestResponseSuccess("Inserted new component with name " + newComponent.getCname()); + outboundJson = objectMapper.writeValueAsString(success); + return outboundJson; + } + + @RequestMapping(value = { COMPONENTS_PATH }, method = RequestMethod.GET, produces = "application/json") + public String getComponents(HttpServletRequest request) throws Exception { + List<EcdComponent> result = controllerEndpointService.getComponents(); + return objectMapper.writeValueAsString(result); + + } + + /** + * gets the tenants list + * + * @param request + * HttpServletRequest + * @return List of CloudifyDeployment objects + */ + @SuppressWarnings("rawtypes") + @RequestMapping(value = { TENANTS_PATH }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getTenants(HttpServletRequest request) throws Exception { + preLogAudit(request); + CloudifyClient restClient = getCloudifyRestClient(); + List itemList = restClient.getTenants().items; + final int totalItems = itemList.size(); + final int pageSize = 20; + final int pageNum = 1; + 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; + } + /** + * Query status and tenant info for deployments + * + */ + @RequestMapping(value = { DEP_TENANT_STATUS }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public String getTenantStatusForService( HttpServletRequest request, + @RequestBody String[] serviceList) + throws Exception { + preLogAudit(request); + /* + 1) Get all the tenant names + 2) Get the deployment IDs per tenant for all the tenants, aggregate the deployments list + 3) Get the input deployments list (screen input), filter the deployments list from step#2 + 4) For each item in the list from step#3, get the execution status info and generate the final response + */ + ECTransportModel result = null; + HashMap<String, Object> resultMap = new HashMap<String, Object>(); + List<CloudifyDeployedTenant> tenantList = new ArrayList<CloudifyDeployedTenant>(); + List<CloudifyExecution> cfyExecList = new ArrayList<CloudifyExecution>(); + try { + CloudifyClient restClient = getCloudifyRestClient(); + List<CloudifyTenant> cldfyTen = restClient.getTenants().items; + for (CloudifyTenant ct: (List<CloudifyTenant>)cldfyTen) { + result = restClient.getTenantInfoFromDeploy(ct.name); + tenantList.addAll(((CloudifyDeployedTenantList)result).items); + } + result = null; + List<CloudifyDeployedTenant> currSrvcTenants = new ArrayList<CloudifyDeployedTenant>(); + + for (String serviceId : serviceList) { + for (CloudifyDeployedTenant deplTen: tenantList) { + if (serviceId.equals(deplTen.id)) { + currSrvcTenants.add(deplTen); + break; + } + } + } + // Get concise execution status for each of the tenant deployment items + for (CloudifyDeployedTenant deplItem: currSrvcTenants) { + CloudifyExecutionList execResults = restClient.getExecutionsSummary(deplItem.id, deplItem.tenant_name); + for (CloudifyExecution cfyExec: execResults.items) { + if (cfyExec.workflow_id.equalsIgnoreCase("install")) { + cfyExecList.add(cfyExec); + } + } + } + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting deployments failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getTenantStatusForService caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting deployments failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getTenantStatusForService caught exception"); + result = new RestResponseError("getTenantStatusForService failed", t); + } finally { + postLogAudit(request); + } + + return objectMapper.writeValueAsString(cfyExecList); + } + + @RequestMapping(value = { SERVICE_TYPES_PATH }, method = RequestMethod.POST, produces = "application/json") + public String createBlueprint(HttpServletRequest request, + @RequestBody ServiceTypeUploadRequest serviceTypeUplReq ) throws Exception { + String json = null; + try { + Blueprint.parse(serviceTypeUplReq.getBlueprintTemplate()); + InventoryClient inventoryClient = getInventoryClient(); + Collection<String> serviceIds = new ArrayList<String>(); + Collection<String> vnfTypes = new ArrayList<String>(); + Collection<String> serviceLocations = new ArrayList<String>(); + Optional<String> asdcServiceId = null; + Optional<String> asdcResourceId = null; + Optional<String> asdcServiceURL = null; + + ServiceTypeRequest invSrvcTypeReq = + new ServiceTypeRequest(serviceTypeUplReq.owner, serviceTypeUplReq.typeName, + serviceTypeUplReq.typeVersion, serviceTypeUplReq.blueprintTemplate, + serviceTypeUplReq.application, serviceTypeUplReq.component, serviceIds, + vnfTypes, serviceLocations, asdcServiceId, asdcResourceId, asdcServiceURL); + ServiceType response = inventoryClient.addServiceType(invSrvcTypeReq); + //RestResponseSuccess success = new RestResponseSuccess("Uploaded new blueprint with name " + serviceTypeUplReq.typeName); + json = objectMapper.writeValueAsString(response); + } catch (BlueprintParseException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Updating service type failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "updateServiceTypeBlueprint caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("Invalid blueprint format.", e)); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Updating service type failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "updateServiceTypeBlueprint caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getResponseBodyAsString())); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Updating service type failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "updateServiceTypeBlueprint caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("updateServiceTypeBlueprint failed", t)); + } finally { + postLogAudit(request); + } + return json; + } + + @RequestMapping(value = { SERVICE_TYPES_PATH }, method = RequestMethod.GET, produces = "application/json") + public String getBlueprintsByPage(HttpServletRequest request) { + preLogAudit(request); + String json = null; + json = getItemListForPageWrapper(request, InventoryDataItem.SERVICE_TYPES, request.getParameter("name"), + request.getParameter("_include")); + postLogAudit(request); + return json; + } + + @RequestMapping(value = { SERVICE_TYPES_PATH + "/findByName" }, method = RequestMethod.GET, produces = "application/json") + public String queryBlueprintFilter(HttpServletRequest request) { + preLogAudit(request); + String json = null; + json = getItemListForPageWrapper(request, InventoryDataItem.SERVICE_TYPES, request.getParameter("name"), + request.getParameter("_include")); + postLogAudit(request); + return json; + } + + @RequestMapping(value = { DEPLOYMENTS_PATH + "/{deploymentId}"}, method = RequestMethod.GET, produces = "application/json") + public String getDeploymentsByPage(@PathVariable("deploymentId") String deploymentId, + HttpServletRequest request) { + preLogAudit(request); + String json = null; + json = getItemListForPageWrapper(request, InventoryDataItem.SERVICES, deploymentId, + request.getParameter("_include")); + postLogAudit(request); + return json; + } + + @RequestMapping(value = { DEPLOYMENTS_PATH }, method = RequestMethod.GET, produces = "application/json") + public String getAllDeploymentsByPage(HttpServletRequest request) { + preLogAudit(request); + String json = null; + json = getItemListForPageWrapper(request, InventoryDataItem.SERVICES, request.getParameter("deploymentId"), + request.getParameter("_include")); + postLogAudit(request); + 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, InventoryDataItem option, String searchBy, + String filters) { + preLogAudit(request); + + String outboundJson = null; + try { + int pageNum = getRequestPageNumber(request); + int pageSize = getRequestPageSize(request); + outboundJson = getItemListForPage(option, pageNum, pageSize, searchBy, filters); + } catch (Exception ex) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "ECOMP Inventory"); + MDC.put("TargetServiceName", "ECOMP Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting page of items failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getItemListForPageWrapper caught exception"); + RestResponseError result = null; + if (ex instanceof HttpStatusCodeException) + result = new RestResponseError(((HttpStatusCodeException) ex).getResponseBodyAsString()); + else + result = new RestResponseError("Failed to get " + option.name(), ex); + try { + outboundJson = objectMapper.writeValueAsString(result); + } catch (JsonProcessingException jpe) { + // Should never, ever happen + outboundJson = "{ \"error\" : \"" + jpe.toString() + "\"}"; + } + } finally { + postLogAudit(request); + } + 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 Exception + * On any error; e.g., Network failure. + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + private String getItemListForPage(InventoryDataItem option, int pageNum, int pageSize, String searchBy, + String filters) throws Exception { + + InventoryClient inventoryClient = getInventoryClient(); + String outboundJson = ""; + List itemList = null; + + switch (option) { + case SERVICES: + itemList = inventoryClient.getServices().collect(Collectors.toList()); + if (searchBy != null) { + itemList = (List) itemList.stream().filter(s -> ((Service) s).contains(searchBy)) + .collect(Collectors.toList()); + } + // Get the tenant names for all the deployments from Cloudify/API handler + ECTransportModel result = null; + List<CloudifyDeployedTenant> tenantList = new ArrayList<CloudifyDeployedTenant>(); + try { + CloudifyClient restClient = getCloudifyRestClient(); + List<CloudifyTenant> cldfyTen = restClient.getTenants().items; + for (CloudifyTenant ct: (List<CloudifyTenant>)cldfyTen) { + result = restClient.getTenantInfoFromDeploy(ct.name); + tenantList.addAll(((CloudifyDeployedTenantList)result).items); + } + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting deployments failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getTenantInfoFromDeploy caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting deployments failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getDeploymentById caught exception"); + result = new RestResponseError("getTenantInfoFromDeploy failed", t); + } finally { + + } + + for (Service depl: (List<Service>)itemList) { + for (CloudifyDeployedTenant deplTen: tenantList) { + if (depl.getDeploymentRef().equals(deplTen.id)) { + depl.setTenant(deplTen.tenant_name); + break; + } + } + } + break; + case SERVICE_TYPES: + ServiceTypeQueryParams serviceQueryParams = null; + serviceQueryParams = new ServiceTypeQueryParams.Builder().onlyLatest(false).build(); + + itemList = inventoryClient.getServiceTypes(serviceQueryParams).collect(Collectors.toList()); + List<BlueprintResponse> filterList = new ArrayList<BlueprintResponse>(); + + if (searchBy != null && searchBy.length() > 1) { + itemList = (List) itemList.stream().filter(s -> ((ServiceType) s).contains(searchBy)) + .collect(Collectors.toList()); + } + if (filters != null && filters.length() > 0) { + String filterArr[] = filters.split(","); + for (ServiceType bp : (List<ServiceType>) itemList) { + BlueprintResponse bpOut = new BlueprintResponse(); + for (String fltr : filterArr) { + switch (fltr) { + case "typeName": + bpOut.setTypeName(bp.getTypeName()); + break; + case "typeId": + bpOut.setTypeId(bp.getTypeId().get()); + break; + case "typeVersion": + bpOut.setTypeVersion(bp.getTypeVersion()); + break; + default: + break; + } + } + filterList.add(bpOut); + } + if (filterList.size() > 0) { + itemList.clear(); + itemList.addAll(filterList); + } + } + break; + default: + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting page of items failed!"); + throw new Exception("getItemListForPage failed: unimplemented case: " + option.name()); + } + // Shrink if needed + final int totalItems = itemList.size(); + final int pageCount = (int) Math.ceil((double) totalItems / pageSize); + if (totalItems > pageSize) + itemList = getPageOfList(pageNum, pageSize, itemList); + + RestResponsePage<List> model = new RestResponsePage<>(totalItems, pageCount, itemList); + outboundJson = objectMapper.writeValueAsString(model); + + return outboundJson; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private String getBlueprintTypeId(String searchBy, Optional<Integer> version, String typeId) throws Exception { + + InventoryClient inventoryClient = getInventoryClient(); + ServiceTypeQueryParams serviceQueryParams = null; + + if (version.isPresent()) { + serviceQueryParams = new ServiceTypeQueryParams.Builder().typeName(searchBy).onlyLatest(false).build(); + } else { + serviceQueryParams = new ServiceTypeQueryParams.Builder().typeName(searchBy).build(); + } + + List itemList = inventoryClient.getServiceTypes(serviceQueryParams).collect(Collectors.toList()); + + if (version.isPresent()) { + itemList = (List) itemList.stream().filter(s -> ((ServiceType) s).contains(version.get().toString())) + .collect(Collectors.toList()); + } + Optional<String> bpId = Optional.of(""); + if (typeId != null && typeId.equals("typeId")) { + ServiceType item = (ServiceType) ((List) itemList).get(0); + bpId = item.getTypeId(); + } + return bpId.get(); + } + + /** + * Query the installed helm package revisions from cloudify + * + * @param deploymentId + * @param tenant + * @param request + * @return + * @throws Exception + */ + @RequestMapping(value = { DEPLOYMENTS_PATH + "/{deploymentId}/revisions"}, method = RequestMethod.GET, produces = "application/json") + public String getDeploymentRevisions(@PathVariable("deploymentId") String deploymentId, + @RequestParam(value = "tenant") String tenant, + HttpServletRequest request) throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + String cloudPrimTenant = + getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM); + if (tenant == null) { + tenant = cloudPrimTenant; + } + CloudifyClient restClient = getCloudifyRestClient(); + result = restClient.getNodeInstanceVersion(deploymentId, tenant); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting executions for deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getExecutionByIdAndDeploymentId caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting executions for deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getExecutionByIdAndDeploymentId caught exception"); + result = new RestResponseError("getExecutionByIdAndDeploymentId failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + /** + * Query inputs used to create a deployment + * + * @param deploymentId + * @param tenant + * @param request + * @return + * @throws Exception + */ + @RequestMapping(value = { DEPLOYMENTS_PATH + "/{deploymentId}/inputs"}, method = RequestMethod.GET, produces = "application/json") + public String getDeploymentInputs(@PathVariable("deploymentId") String deploymentId, + @RequestParam(value = "tenant") String tenant, + HttpServletRequest request) throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + String cloudPrimTenant = + getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM); + if (tenant == null) { + tenant = cloudPrimTenant; + } + CloudifyClient restClient = getCloudifyRestClient(); + result = restClient.getDeploymentInputs(deploymentId, tenant); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting executions for deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getExecutionByIdAndDeploymentId caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting executions for deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getExecutionByIdAndDeploymentId caught exception"); + result = new RestResponseError("getExecutionByIdAndDeploymentId failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + /** + * Create an upgrade/rollback workflow execution for a deployment. + * + * @param request + * HttpServletRequest + * @param execution + * Execution model + * @return Information about the execution + * @throws Exception + * on serialization failure + */ + @RequestMapping(value = { DEPLOYMENTS_PATH + "/{deploymentId}"}, method = RequestMethod.PUT, produces = "application/json") + public String modifyDeployment(@PathVariable("deploymentId") String deploymentId, + HttpServletRequest request, InputStream upgParams) + throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + CloudifyClient restClient = getCloudifyRestClient(); + String nodeInstId = ""; + Map<String, Object> parameters = + objectMapper.readValue(upgParams, new TypeReference<Map<String, Object>>() {}); + String tenant = (String) parameters.get("tenant"); + String workflow = (String) parameters.get("workflow"); + parameters.remove("tenant"); + parameters.remove("workflow"); + // get the node instance ID for the deployment + CloudifyNodeInstanceIdList nodeInstList = restClient.getNodeInstanceId(deploymentId, tenant); + if (nodeInstList != null) { + nodeInstId = nodeInstList.items.get(0).id; + } + parameters.put("node_instance_id", nodeInstId); + CloudifyExecutionRequest execution = + new CloudifyExecutionRequest(deploymentId, workflow, false, false, tenant, parameters); + result = restClient.startExecution(execution); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Updating deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "updateDeployment caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Updating Deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "updateDeployment caught exception"); + result = new RestResponseError("updateDeployment failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + @RequestMapping(value = { SERVICE_TYPES_PATH + "/{typeid}" + "/services" }, method = RequestMethod.GET, produces = "application/json") + public String getServicesForType( HttpServletRequest request, + @PathVariable("typeid") String typeId) + throws Exception { + preLogAudit(request); + List<ServiceTypeServiceMap> result = new ArrayList<ServiceTypeServiceMap>(); + InventoryClient inventoryClient = getInventoryClient(); + ServiceQueryParams qryParams = new ServiceQueryParams.Builder().typeId(typeId).build(); + ServiceRefList srvcRefs = inventoryClient.getServicesForType(qryParams); + ServiceTypeServiceMap srvcMap = new ServiceTypeServiceMap(typeId, srvcRefs); + result.add(srvcMap); + return objectMapper.writeValueAsString(result); + } + + @RequestMapping(value = { DEPLOYMENTS_PATH }, method = RequestMethod.POST, produces = "application/json") + public String createDeployment( HttpServletRequest request, + @RequestBody DeploymentInput deploymentRequestObject) + throws Exception { + preLogAudit(request); + String json = null; + StringBuffer status = new StringBuffer(); + //Optional<String> bpId = Optional.empty(); + Optional<Integer> bpVersion = null; + String srvcTypeId = null; + String bpName = deploymentRequestObject.getBlueprintName(); + String cName = deploymentRequestObject.getComponent(); + String tag = deploymentRequestObject.getTag(); + String depName = cName+"_"+tag; + + if (deploymentRequestObject.getBlueprintVersion().isPresent()) { + bpVersion = deploymentRequestObject.getBlueprintVersion(); + } + if (deploymentRequestObject.getBlueprintId().isPresent()) { + srvcTypeId = deploymentRequestObject.getBlueprintId().get(); + //srvcTypeId = bpId.get(); + } + if (srvcTypeId == null) { + // get the serviceTypeId from inventory using the blueprint name + try { + srvcTypeId = getBlueprintTypeId(bpName, bpVersion, "typeId"); + } catch (Exception ex) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "ECOMP Inventory"); + MDC.put("TargetServiceName", "ECOMP Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting blueprint ID failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getItemListForPageWrapper caught exception"); + RestResponseError result = null; + if (ex instanceof HttpStatusCodeException) + result = new RestResponseError(((HttpStatusCodeException) ex).getResponseBodyAsString()); + else + result = new RestResponseError("Failed to get blueprint", ex); + try { + json = objectMapper.writeValueAsString(result); + } catch (JsonProcessingException jpe) { + // Should never, ever happen + json = "{ \"error\" : \"" + jpe.toString() + "\"}"; + } + return json; + } finally { + postLogAudit(request); + } + } + DeploymentHandlerClient deploymentHandlerClient = null; + try { + deploymentHandlerClient = getDeploymentHandlerClient(); + DeploymentResponse resp = + deploymentHandlerClient.putDeployment( + depName, deploymentRequestObject.getTenant(), + new DeploymentRequest(srvcTypeId, deploymentRequestObject.getInputs())); + DeploymentResponseLinks deplLinks = resp.getLinks(); + String deplStatus = deplLinks.getStatus(); + if (!deplStatus.contains("cfy_tenant")) { + deplStatus = deplStatus + "?cfy_tenant_name=" + deploymentRequestObject.getTenant(); + } + String self = request.getRequestURL().append("/").append(depName).toString(); + status.append(self).append("/executions?tenant=").append(deploymentRequestObject.getTenant()); + DeploymentResource deplRsrc = new DeploymentResource(depName, + new DeploymentResourceLinks(self, deplStatus, status.toString())); + JSONObject statObj = new JSONObject(deplRsrc); + json = statObj.toString(); + } catch (BadRequestException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (ServiceAlreadyExistsException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (ServerErrorException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (DownstreamException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (JsonProcessingException jpe) { + // Should never, ever happen + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = "{ \"error\" : \"" + jpe.toString() + "\"}"; + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("putDeployment failed", t)); + } finally { + postLogAudit(request); + } + return json; + } + + @RequestMapping(value = { DEPLOYMENTS_PATH + "/{deploymentId}/update"}, method = RequestMethod.PUT, produces = "application/json") + public String updateDeployment( @PathVariable("deploymentId") String deploymentId, HttpServletRequest request, + @RequestBody DeploymentInput deploymentRequestObject) + throws Exception { + preLogAudit(request); + String json = null; + String srvcTypeId = ""; + Optional<Integer> bpVersion = null; + String bpName = deploymentRequestObject.getBlueprintName(); + if (deploymentRequestObject.getBlueprintVersion().isPresent()) { + bpVersion = deploymentRequestObject.getBlueprintVersion(); + } + // get the serviceTypeId from inventory using the blueprint name + try { + srvcTypeId = getBlueprintTypeId(bpName, bpVersion, "typeId"); + } catch (Exception ex) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "ECOMP Inventory"); + MDC.put("TargetServiceName", "ECOMP Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting blueprint ID failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getItemListForPageWrapper caught exception"); + RestResponseError result = null; + if (ex instanceof HttpStatusCodeException) + result = new RestResponseError(((HttpStatusCodeException) ex).getResponseBodyAsString()); + else + result = new RestResponseError("Failed to get blueprint", ex); + try { + json = objectMapper.writeValueAsString(result); + } catch (JsonProcessingException jpe) { + // Should never, ever happen + json = "{ \"error\" : \"" + jpe.toString() + "\"}"; + } + return json; + } finally { + postLogAudit(request); + } + DeploymentHandlerClient deploymentHandlerClient = null; + try { + deploymentHandlerClient = getDeploymentHandlerClient(); + json = objectMapper.writeValueAsString(deploymentHandlerClient.updateDeployment( + deploymentId, deploymentRequestObject.getTenant(), + new DeploymentRequest(srvcTypeId, deploymentRequestObject.getInputs()))); + } catch (BadRequestException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (ServiceAlreadyExistsException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (ServerErrorException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (DownstreamException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (JsonProcessingException jpe) { + // Should never, ever happen + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = "{ \"error\" : \"" + jpe.toString() + "\"}"; + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("putDeployment failed", t)); + } finally { + postLogAudit(request); + } + return json; + } + + /** + * Gets the executions for one deployment. + * + * + * @param deployment_id + * Deployment ID (query parameter) + * @param request + * HttpServletRequest + * @return CloudifyExecutionList + * @throws Exception + * on serialization failure + */ + @RequestMapping(value = { DEPLOYMENTS_PATH + "/{deploymentId}" + "/" + EXECUTIONS_PATH }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getExecutionByDeploymentId( + @PathVariable("deploymentId") String deploymentId, + @RequestParam(value = "tenant", required = true) String tenant, + HttpServletRequest request) throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + String cloudPrimTenant = + getAppProperties().getProperty(DashboardProperties.CLOUDIFY_TENANT_PRIM); + if (tenant == null) { + tenant = cloudPrimTenant; + } + CloudifyClient restClient = getCloudifyRestClient(); + result = restClient.getExecutionsSummary(deploymentId, tenant); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting executions for deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getExecutionByIdAndDeploymentId caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting executions for deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getExecutionByIdAndDeploymentId caught exception"); + result = new RestResponseError("getExecutionByIdAndDeploymentId failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + /** + * Deletes the specified blueprint. + * + * @param id + * Blueprint ID + * @param request + * HttpServletRequest + * @param response + * HttpServletResponse + * @return status code on success; error on failure. + * @throws Exception + * On serialization failure + */ + @RequestMapping(value = { SERVICE_TYPES_PATH + "/{typeid}" }, method = RequestMethod.DELETE, produces = "application/json") + @ResponseBody + public String deleteBlueprint(@PathVariable("typeid") String typeId, HttpServletRequest request, + HttpServletResponse response) throws Exception { + preLogAudit(request); + String json = "{\"202\": \"OK\"}"; + try { + InventoryClient inventoryClient = getInventoryClient(); + ServiceQueryParams qryParams = new ServiceQueryParams.Builder().typeId(typeId).build(); + ServiceRefList srvcRefs = inventoryClient.getServicesForType(qryParams); + if (srvcRefs != null && srvcRefs.totalCount > 0) { + throw new Exception("Services exist for the service type template, delete not permitted"); + } + inventoryClient.deleteServiceType(typeId); + } catch (ServiceTypeNotFoundException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting service type " + typeId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteBlueprint caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (ServiceTypeAlreadyDeactivatedException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting service type " + typeId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteBlueprint caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting service type " + typeId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteBlueprint caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("deleteBlueprint failed", t)); + } finally { + postLogAudit(request); + } + return json; + } + + /** + * Un-deploy an application or service + * + * @param deploymentId + * @param request + * @param tenant + * @param response + * @return + * @throws Exception + */ + @RequestMapping(value = { + DEPLOYMENTS_PATH + "/{deploymentId}" }, method = RequestMethod.DELETE, produces = "application/json") + public String deleteDeployment(@PathVariable("deploymentId") String deploymentId, HttpServletRequest request, + @RequestParam("tenant") String tenant, HttpServletResponse response) throws Exception { + preLogAudit(request); + String json = null; + StringBuffer status = new StringBuffer(); + try { + DeploymentHandlerClient deploymentHandlerClient = getDeploymentHandlerClient(); + deploymentHandlerClient.deleteDeployment(deploymentId, tenant); + String self = request.getRequestURL().toString().split("\\?")[0]; + status.append(self) + .append("/executions?tenant=") + .append(tenant); + DeploymentResource deplRsrc = + new DeploymentResource(deploymentId, + new DeploymentResourceLinks(self, "", status.toString())); + JSONObject statObj = new JSONObject(deplRsrc); + json = statObj.toString(); + } catch (BadRequestException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (ServerErrorException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (DownstreamException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (DeploymentNotFoundException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (JsonProcessingException jpe) { + // Should never, ever happen + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteDeployment caught exception"); + json = "{ \"error\" : \"" + jpe.toString() + "\"}"; + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("deleteDeployment failed", t)); + } finally { + postLogAudit(request); + } + return json; + } + + /** + * Cancels an execution. + * + * @param id + * Execution ID + * @param deploymentId + * Deployment ID (not clear why this is needed) + * @param action + * Action to perform (not clear why this is needed) + * @param request + * HttpServletRequest + * @param response + * HttpServletRequest + * @return Passes thru HTTP status code from remote endpoint; no body on + * success + * @throws Exception + * on serialization failure + */ + @RequestMapping(value = { EXECUTIONS_PATH + "/{id}" }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public String cancelExecution( + @RequestHeader HttpHeaders headers, + @PathVariable("id") String id, + @RequestBody Map<String, String> parameters, + HttpServletRequest request, HttpServletResponse response) + throws Exception { + preLogAudit(request); + ECTransportModel result = null; + List<String> tenant = null; + try { + tenant = headers.get("tenant"); + CloudifyClient restClient = getCloudifyRestClient(); + result = restClient.cancelExecution(id, parameters, tenant.get(0)); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Cancelling execution " + id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "cancelExecution caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Cancelling execution " + id + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "cancelExecution caught exception"); + result = new RestResponseError("cancelExecution failed on ID " + id, t); + } finally { + postLogAudit(request); + } + if (result == null) + return null; + else + return objectMapper.writeValueAsString(result); + } + + private void preLogAudit(HttpServletRequest request) { + begin = new Date(); + MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(begin)); + MDC.put(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP, logDateFormat.format(begin)); + MDC.put(SystemProperties.STATUS_CODE, "COMPLETE"); + // logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, + // APP_NAME); + } + + private void postLogAudit(HttpServletRequest request) { + end = new Date(); + MDC.put("AlertSeverity", "0"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(end)); + MDC.put(SystemProperties.METRICSLOG_END_TIMESTAMP, logDateFormat.format(end)); + MDC.put(SystemProperties.MDC_TIMER, Long.toString((end.getTime() - begin.getTime()))); + logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI()); + logger.info(EELFLoggerDelegate.metricsLogger, request.getMethod() + request.getRequestURI()); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/ConsulController.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/ConsulController.java index 8350737..3aa7821 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/ConsulController.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/ConsulController.java @@ -1,445 +1,483 @@ -/*******************************************************************************
- * =============LICENSE_START=========================================================
- *
- * =================================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *******************************************************************************/
-package org.onap.ccsdk.dashboard.controller;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import java.net.URI;
-import java.time.Instant;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-
-import org.onap.ccsdk.dashboard.model.ConsulHealthServiceRegistration;
-import org.onap.ccsdk.dashboard.model.ConsulNodeInfo;
-import org.onap.ccsdk.dashboard.model.ConsulServiceHealth;
-import org.onap.ccsdk.dashboard.model.RestResponsePage;
-import org.onap.ccsdk.dashboard.rest.IControllerRestClient;
-import org.onap.ccsdk.dashboard.exception.DashboardControllerException;
-import org.onap.ccsdk.dashboard.model.ConsulServiceInfo;
-import org.onap.ccsdk.dashboard.model.ECTransportModel;
-import org.onap.ccsdk.dashboard.model.RestResponseError;
-import org.onap.ccsdk.dashboard.model.RestResponseSuccess;
-import org.onap.portalsdk.core.domain.User;
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.onap.portalsdk.core.util.SystemProperties;
-import org.onap.portalsdk.core.web.support.UserUtils;
-import org.slf4j.MDC;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.client.HttpStatusCodeException;
-
-/**
- * Controller for Consul features: health checks of services, nodes, data
- * centers. Methods serve Ajax requests made by Angular scripts on pages that
- * show content.
- */
-@Controller
-@RequestMapping("/healthservices")
-public class ConsulController extends DashboardRestrictedBaseController {
-
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ConsulController.class);
-
- /**
- * 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";
-
- /**
- * 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 = Comparator.comparing(o -> o.serviceName);
-
- /**
- * 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;
- 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);
- 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;
- 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;
- 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;
- 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 (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);
- }
- 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 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 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 (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 (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);
- }
-}
+/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.controller; + +import java.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.ccsdk.dashboard.model.ConsulHealthServiceRegistration; +import org.onap.ccsdk.dashboard.model.ConsulHealthServiceRegistration.EndpointCheck; +import org.onap.ccsdk.dashboard.model.ConsulNodeInfo; +import org.onap.ccsdk.dashboard.model.ConsulServiceHealth; +import org.onap.ccsdk.dashboard.model.ConsulServiceInfo; +import org.onap.ccsdk.dashboard.model.ECTransportModel; +import org.onap.ccsdk.dashboard.model.RestResponseError; +import org.onap.ccsdk.dashboard.model.RestResponsePage; +import org.onap.ccsdk.dashboard.model.RestResponseSuccess; +import org.onap.ccsdk.dashboard.rest.ConsulClient; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.slf4j.MDC; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.client.HttpStatusCodeException; + +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 + * show content. + */ +@Controller +@RequestMapping("/healthservices") +public class ConsulController extends DashboardRestrictedBaseController { + + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ConsulController.class); + + /** + * Enum for selecting an item type. + */ + public enum ConsulDataItem { + SERVICE_INFO, SERVICE_HEALTH, NODES, DATACENTERS; + } + + private static Date begin, end; + 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 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<ConsulServiceInfo> serviceInfoComparator = new Comparator<ConsulServiceInfo>() { + @Override + public int compare(ConsulServiceInfo o1, ConsulServiceInfo o2) { + return o1.name.compareTo(o2.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 Exception + * On any error; e.g., Network failure. + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + private String getItemListForPage(long userId, ConsulDataItem option, + int pageNum, int pageSize, String dc) throws Exception { + ConsulClient restClient = getConsulRestClient(userId); + List itemList = null; + switch (option) { + case NODES: + itemList = restClient.getNodes(dc); + Collections.sort(itemList, nodeHealthComparator); + break; + case DATACENTERS: + itemList = restClient.getDatacenters(); + break; + default: + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Consul"); + MDC.put("TargetServiceName", "Consul"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting page of items failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getItemListForPage caught exception"); + throw new Exception("getItemListForPage failed: unimplemented case: " + option.name()); + } + final int totalItems = itemList.size(); + // Shrink if needed + if (itemList.size() > pageSize) { + itemList = getPageOfList(pageNum, pageSize, itemList); + } + int pageCount = (int) Math.ceil((double) totalItems / pageSize); + RestResponsePage<List> model = new RestResponsePage<>(totalItems, pageCount, itemList); + return objectMapper.writeValueAsString(model); + } + + /** + * Gets one page of the specified items. This method traps exceptions and + * constructs an appropriate JSON block to report errors. + * + * @param request + * Inbound request + * @param option + * Item type to get + * @return JSON with one page of objects; or an error. + */ + protected String getItemListForPageWrapper(HttpServletRequest request, + String dc, + ConsulDataItem option) { + String outboundJson = null; + try { + User appUser = UserUtils.getUserSession(request); + if (appUser == null || appUser.getLoginId() == null || appUser.getLoginId().length() == 0) + throw new Exception("getItemListForPageWrapper: Failed to get application user"); + int pageNum = getRequestPageNumber(request); + int pageSize = getRequestPageSize(request); + outboundJson = getItemListForPage(appUser.getId(), option, pageNum, pageSize, dc); + } catch (Exception ex) { + // Remote service failed; build descriptive error message + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Consul"); + MDC.put("TargetServiceName", "Consul"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting page of items failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getItemListForPageWrapper caught exception"); + RestResponseError result = 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 service health details - not paginated. + * + * @param request + * HttpServletRequest + * @param serviceId + * Service ID + * @return List of ConsulServiceHealth objects as JSON + * @throws Exception + * if serialization fails + */ + @RequestMapping(value = { + SERVICES_PATH + "/{serviceId}" }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getServiceHealthDetails(HttpServletRequest request, + @RequestParam String dc, + @PathVariable String serviceId) throws Exception { + preLogAudit(request); + Object result = null; + try { + ConsulClient restClient = getConsulRestClient(request); + result = restClient.getServiceHealth(dc,serviceId); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Consul"); + MDC.put("TargetServiceName", "Consul"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting service health details for " + serviceId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getServiceHealthDetails caught exception"); + result = new RestResponseError("getServiceHealthDetails failed", t); + } finally { + postLogAudit(request); + } + 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 Exception + * on serialization exception + */ + @SuppressWarnings("unchecked") + @RequestMapping(value = { "/serviceshealth" }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getServicesHealth(HttpServletRequest request, + @RequestParam String dc) throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + List<ConsulServiceHealth> itemList = new ArrayList<>(); + ConsulClient restClient = getConsulRestClient(request); + List<ConsulServiceInfo> svcInfoList = restClient.getServices(dc); + for (ConsulServiceInfo csi : svcInfoList) { + List<ConsulServiceHealth> csh = restClient.getServiceHealth(dc, 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) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Consul"); + MDC.put("TargetServiceName", "Consul"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting services health failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getServicesHealth caught exception"); + result = new RestResponseError("getServicesHealth failed", t); + } finally { + postLogAudit(request); + } + 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, + @RequestParam String dc) { + preLogAudit(request); + String json = getItemListForPageWrapper(request, dc, ConsulDataItem.NODES); + postLogAudit(request); + return json; + } + + /** + * Serves node services health details - not paginated. + * + * @param request + * HttpServletRequest + * @param nodeName + * Node name + * @return List of ConsulServiceHealth objects as JSON + * @throws Exception + * if serialization fails + */ + @RequestMapping(value = { NODES_PATH + "/{nodeName}" }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getNodeServicesHealth(HttpServletRequest request, + @RequestParam String dc, + @PathVariable String nodeName) throws Exception { + preLogAudit(request); + Object result = null; + try { + ConsulClient restClient = getConsulRestClient(request); + result = restClient.getNodeServicesHealth(dc, nodeName); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Consul"); + MDC.put("TargetServiceName", "Consul"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting node services health for " + nodeName + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getNodeServicesHealth caught exception"); + result = new RestResponseError("getNodeServicesHealth failed", t); + } finally { + postLogAudit(request); + } + 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) { + preLogAudit(request); + String json = getItemListForPageWrapper(request, null, ConsulDataItem.DATACENTERS); + postLogAudit(request); + 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 Exception + * on serialization error + */ + @RequestMapping(value = { "/register" }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public String registerService(HttpServletRequest request, @RequestBody ConsulHealthServiceRegistration registration) + throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + if (registration.services == null) { + throw new Exception("services[] tag is mandatory"); + } + + List<EndpointCheck> checks = registration.services.get(0).checks; + String service_name = registration.services.get(0).name; + String service_port = registration.services.get(0).port; + String service_address = registration.services.get(0).address; + + if (checks == null || service_port.isEmpty() || service_address.isEmpty() || service_name.isEmpty()) { + throw new Exception("fields : [checks[], port, address, name] are mandatory"); + } + for (EndpointCheck check : checks) { + if (check.endpoint.isEmpty() || check.interval.isEmpty() ) { + throw new Exception("Required fields : [endpoint, interval] in checks"); + } + } + ConsulClient restClient = getConsulRestClient(request); + result = new RestResponseSuccess(restClient.registerService(registration)); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Consul"); + MDC.put("TargetServiceName", "Consul"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Registering service failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "registerService caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Consul"); + MDC.put("TargetServiceName", "Consul"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Registering service failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "registerService caught exception"); + result = new RestResponseError("registerService failed", t); + } finally { + postLogAudit(request); + } + 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 Exception + * on serialization error + */ + @RequestMapping(value = { "/deregister" + "/{serviceName}" }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public String deregisterService(HttpServletRequest request, + @PathVariable String serviceName) throws Exception { + preLogAudit(request); + ECTransportModel result = null; + try { + ConsulClient restClient = getConsulRestClient(request); + int code = restClient.deregisterService(serviceName); + result = new RestResponseSuccess("Deregistration yielded code " + Integer.toString(code)); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Consul"); + MDC.put("TargetServiceName", "Consul"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "De-registering service " + serviceName + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deregisterService caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Consul"); + MDC.put("TargetServiceName", "Consul"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "De-registering service " + serviceName + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deregisterService caught exception"); + result = new RestResponseError("deregisterService failed", t); + } finally { + postLogAudit(request); + } + return objectMapper.writeValueAsString(result); + } + + public void preLogAudit(HttpServletRequest request) { + begin = new Date(); + MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(begin)); + MDC.put(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP, logDateFormat.format(begin)); + MDC.put(SystemProperties.STATUS_CODE, "COMPLETE"); + //logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME); + } + + public void postLogAudit(HttpServletRequest request) { + end = new Date(); + MDC.put("AlertSeverity", "0"); + MDC.put("TargetEntity", "Consul"); + MDC.put("TargetServiceName", "Consul"); + MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(end)); + MDC.put(SystemProperties.METRICSLOG_END_TIMESTAMP, logDateFormat.format(end)); + MDC.put(SystemProperties.MDC_TIMER, Long.toString((end.getTime() - begin.getTime()))); + logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI()); + logger.info(EELFLoggerDelegate.metricsLogger, request.getMethod() + request.getRequestURI()); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/DashboardHomeController.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/DashboardHomeController.java index 8ec1d2c..7ccdbf4 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/DashboardHomeController.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/DashboardHomeController.java @@ -1,162 +1,402 @@ -/*******************************************************************************
- * =============LICENSE_START=========================================================
- *
- * =================================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *******************************************************************************/
-package org.onap.ccsdk.dashboard.controller;
-
-import java.util.ArrayList;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.onap.ccsdk.dashboard.domain.ControllerEndpoint;
-import org.onap.ccsdk.dashboard.exception.DashboardControllerException;
-import org.onap.ccsdk.dashboard.model.ControllerEndpointCredentials;
-import org.onap.ccsdk.dashboard.model.ControllerEndpointTransport;
-import org.onap.ccsdk.dashboard.model.RestResponseError;
-import org.onap.ccsdk.dashboard.model.RestResponseSuccess;
-import org.onap.ccsdk.dashboard.service.ControllerEndpointService;
-import org.onap.portalsdk.core.domain.User;
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.onap.portalsdk.core.web.support.UserUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.servlet.ModelAndView;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-/**
- * This controller maps requests for the application's landing page, which is an
- * Angular single-page application.
- */
-@Controller
-@RequestMapping("/")
-public class DashboardHomeController extends DashboardRestrictedBaseController {
-
- /**
- * This path is embedded in the database, so it's nontrivial to change.
- */
- public static final String APP_CONTEXT_PATH = "/ecd";
-
- private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(DashboardHomeController.class);
-
- @Autowired
- private ControllerEndpointService controllerEndpointService;
-
- /**
- * For general use in these methods
- */
- private final ObjectMapper mapper;
-
- private static final String CONTROLLERS_PATH = "controllers";
-
- /**
- * Spring autowires fields AFTER the constructor is called.
- */
- public DashboardHomeController() {
- mapper = new ObjectMapper();
- // Do not serialize null values
- mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
- }
-
- /**
- * @return View name key, which is resolved to a file using an Apache tiles
- * "definitions.xml" file.
- */
- @RequestMapping(value = { APP_CONTEXT_PATH }, method = RequestMethod.GET)
- public ModelAndView dbcDefaultController() {
- // a model is only useful for JSP; this app is angular.
- return new ModelAndView("oom_home_tdkey");
- }
-
- /**
- * Gets the available controller endpoints.
- *
- * @param request
- * HttpServletRequest
- * @return List of ControllerEndpointTransport objects, or an error on failure
- */
- @RequestMapping(value = { CONTROLLERS_PATH }, method = RequestMethod.GET, produces = "application/json")
- @ResponseBody
- public String getControllers(HttpServletRequest request) {
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- String outboundJson = null;
- // Static data
- ControllerEndpointCredentials[] configured = getControllerEndpoints();
- try {
- User appUser = UserUtils.getUserSession(request);
- if (appUser == null || appUser.getLoginId() == null || appUser.getLoginId().length() == 0)
- throw new DashboardControllerException("getControllers: Failed to get application user");
- ControllerEndpointCredentials selectedInDb = getOrSetControllerEndpointSelection(appUser.getId());
- // Built result from properties
- ArrayList<ControllerEndpointTransport> list = new ArrayList<>();
- for (ControllerEndpointCredentials ctrl : configured) {
- // Check if this is the selected endpoint in DB
- boolean selected = (selectedInDb != null && selectedInDb.getUrl() != null
- && selectedInDb.getUrl().equals(ctrl.getUrl()));
- // Result has no privileged information
- ControllerEndpointTransport transport = new ControllerEndpointTransport(selected, ctrl.getName(),
- ctrl.getUrl());
- list.add(transport);
- }
- outboundJson = mapper.writeValueAsString(list);
- } catch (Exception ex) {
- RestResponseError response = new RestResponseError("Failed to get controller endpoint list", ex);
- outboundJson = response.toJson();
- }
- return outboundJson;
- }
-
- /**
- * Sets the controller endpoint selection for the user.
- *
- * @param request
- * HttpServletRequest
- * @param endpoint
- * Body with endpoint details
- * @return Result indicating success or failure
- * @throws DashboardControllerException,
- * if application user is not found
- * @throws JsonProcessingException
- * If serialization fails
- */
- @RequestMapping(value = { CONTROLLERS_PATH }, method = RequestMethod.POST, produces = "application/json")
- @ResponseBody
- public String setControllerSelection(HttpServletRequest request, @RequestBody ControllerEndpointTransport endpoint)
- throws DashboardControllerException, JsonProcessingException {
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME);
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- String outboundJson = null;
- User appUser = UserUtils.getUserSession(request);
- if (appUser == null || appUser.getLoginId() == null || appUser.getLoginId().length() == 0)
- throw new DashboardControllerException("setControllerSelection: Failed to get application user");
- ControllerEndpoint dbEntry = new ControllerEndpoint(appUser.getId(), endpoint.getName(), endpoint.getUrl());
- controllerEndpointService.updateControllerEndpointSelection(dbEntry);
- RestResponseSuccess success = new RestResponseSuccess("Updated selection to " + endpoint.getName());
- outboundJson = mapper.writeValueAsString(success);
- return outboundJson;
- }
-}
+/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.controller; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.onap.ccsdk.dashboard.domain.ControllerEndpoint; +import org.onap.ccsdk.dashboard.domain.EcdComponent; +import org.onap.ccsdk.dashboard.model.ControllerEndpointCredentials; +import org.onap.ccsdk.dashboard.model.ControllerEndpointTransport; +import org.onap.ccsdk.dashboard.model.ControllerOpsTools; +import org.onap.ccsdk.dashboard.model.EcdAppComponent; +import org.onap.ccsdk.dashboard.model.RestResponseError; +import org.onap.ccsdk.dashboard.model.RestResponseSuccess; +import org.onap.ccsdk.dashboard.service.ControllerEndpointService; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * This controller maps requests for the application's landing page, which is + * an Angular single-page application. + */ +@Controller +@RequestMapping("/") +public class DashboardHomeController extends DashboardRestrictedBaseController { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(DashboardHomeController.class); + + @Autowired + private ControllerEndpointService controllerEndpointService; + + /** + * For general use in these methods + */ + private final ObjectMapper mapper; + + private static Date begin, end; + private static final String CONTROLLERS_PATH = "controllers"; + private static final String COMPONENTS_PATH = "components"; + private static final String USER_APPS_PATH = "user-apps"; + private static final String OPS_PATH = "ops"; + private static final String APP_LABEL = "app-label"; + /** + * Never forget that Spring autowires fields AFTER the constructor is + * called. + */ + public DashboardHomeController() { + mapper = new ObjectMapper(); + // Do not serialize null values + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + } + + /** + * @return View name key, which is resolved to a file using an Apache tiles + * "definitions.xml" file. + */ + @RequestMapping(value = { "/ecd" }, method = RequestMethod.GET) + public ModelAndView dbcDefaultController() { + // a model is only useful for JSP; this app is angular. + return new ModelAndView("ecd_home_tdkey"); + } + + /** + * Gets the available blueprint component names + * + * @param request + * HttpServletRequest + * @return List of component name strings, or an error on + * failure + */ + @RequestMapping(value = { COMPONENTS_PATH }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getComponents(HttpServletRequest request) { + preLogAudit(request); + String outboundJson = ""; // "['MSO','CLAMP','APPC','ECOMPSCHEDULER','POLICY']"; + try { + HttpSession session = request.getSession(true); + Set<String> userApps = (Set<String>)session.getAttribute("authComponents"); + if (userApps == null) { + userApps = new TreeSet<String>(); + } + List<EcdComponent> filterList = new ArrayList<EcdComponent>(); + List<EcdAppComponent> ecdApps = new ArrayList<EcdAppComponent>(); + + List<EcdComponent> dbResult = + controllerEndpointService.getComponents(); + + List dcaeCompList = + (List) dbResult.stream().filter(s -> ((EcdComponent) s).contains("dcae")).collect(Collectors.toList()); + + if (!userApps.isEmpty()) { // non-admin role level + for(String userRole : userApps) { + if (userRole.equalsIgnoreCase("dcae")) { + if (dcaeCompList != null && !dcaeCompList.isEmpty()) { + EcdAppComponent dcaeAppComponent = new EcdAppComponent("DCAE", dcaeCompList); + ecdApps.add(dcaeAppComponent); + } + } else { + List tmpItemList = + (List) dbResult.stream().filter(s -> ((EcdComponent) s).contains(userRole)).collect(Collectors.toList()); + if (tmpItemList != null) { + logger.debug(">>>> adding filtered items"); + filterList.addAll(tmpItemList); + } + } + } + if (!filterList.isEmpty()) { + EcdAppComponent ecdAppComponent = new EcdAppComponent("ECOMP", filterList); + ecdApps.add(ecdAppComponent); + } + } else { + // lookup "dcae" in the db component list + if (dcaeCompList != null && !dcaeCompList.isEmpty()) { + EcdAppComponent dcaeAppComponent = new EcdAppComponent("DCAE", dcaeCompList); + ecdApps.add(dcaeAppComponent); + } + if (dbResult != null && !dbResult.isEmpty()) { + EcdAppComponent ecdAppComponent = new EcdAppComponent("ECOMP", dbResult); + ecdApps.add(ecdAppComponent); + } + } + outboundJson = mapper.writeValueAsString(ecdApps); + } catch (Exception ex) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DashboardHomeController"); + MDC.put("TargetServiceName", "DashboardHomeController"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Get components failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "Failed to get components list"); + RestResponseError response = new RestResponseError("Failed to get components list", ex); + outboundJson = response.toJson(); + } finally { + postLogAudit(request); + } + return outboundJson; + } + + /** + * Get the application label - name + environment + * + */ + @RequestMapping(value = {APP_LABEL}, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getAppLabel(HttpServletRequest request) throws Exception { + return mapper.writeValueAsString(appProperties.getPropertyDef(appProperties.CONTROLLER_IN_ENV, "NA")); + //return mapper.writeValueAsString(systemProperties.getAppDisplayName()); + } + /** + * Gets the application name(s) for the authenticated user + * + * @param request + * HttpServletRequest + * @return List of component name strings, or an error on + * failure + */ + @SuppressWarnings("unchecked") + @RequestMapping(value = { USER_APPS_PATH }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getUserApps(HttpServletRequest request) { + preLogAudit(request); + String outboundJson = ""; // "['MSO','CLAMP','APPC','ECOMPSCHEDULER','POLICY']"; + try { + HttpSession session = request.getSession(true); + Set<String> userApps = (Set<String>)session.getAttribute("authComponents"); + if (userApps == null) { + userApps = new TreeSet<String>(); + } + outboundJson = mapper.writeValueAsString(userApps); + } catch (Exception ex) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DashboardHomeController"); + MDC.put("TargetServiceName", "DashboardHomeController"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Get User Apps failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "Failed to get apps list"); + RestResponseError response = new RestResponseError("Failed to get apps list", ex); + outboundJson = response.toJson(); + } finally { + postLogAudit(request); + } + return outboundJson; + } + /** + * Sets the controller endpoint selection for the user. + * + * @param request + * HttpServletRequest + * @param endpoint + * Body with endpoint details + * @return Result indicating success or failure + * @throws Exception + * if application user is not found + */ + @RequestMapping(value = { COMPONENTS_PATH }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public String insertComponent(HttpServletRequest request, @RequestBody EcdComponent newComponent) + throws Exception { + preLogAudit(request); + String outboundJson = null; + controllerEndpointService.insertComponent(newComponent); + RestResponseSuccess success = new RestResponseSuccess("Inserted new component with name " + newComponent.getCname()); + outboundJson = mapper.writeValueAsString(success); + postLogAudit(request); + return outboundJson; + } + + /** + * Gets the OPS Tools URLs from dashboard properties + * + * @param request + * HttpServletRequest + * @return List of ControllerOpsTools objects, or an error on + * failure + * @throws Exception + */ + @RequestMapping(value = { OPS_PATH }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getOpsToolUrls(HttpServletRequest request) { + preLogAudit(request); + String outboundJson = null; + try { + List<ControllerOpsTools> opsList = getControllerOpsTools(); + outboundJson = mapper.writeValueAsString(opsList); + } catch (Exception ex) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DashboardHomeController"); + MDC.put("TargetServiceName", "DashboardHomeController"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Get Ops Tools URLs failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "Failed to get Ops Tools URL list"); + RestResponseError response = new RestResponseError("Failed to get Ops Tools URL list", ex); + outboundJson = response.toJson(); + } finally { + postLogAudit(request); + } + return outboundJson; + } + + // get sites + // get cfy, cnsl URLs + // get cfy tenants + // get cfy secret value for k8s ip per tenant + // construct models TenantOpsCluster, SiteOpsToolLinks + // return final model + /** + * Gets the available controller endpoints. + * + * @param request + * HttpServletRequest + * @return List of ControllerEndpointTransport objects, or an error on + * failure + * @throws Exception + * if application user is not found + */ + @RequestMapping(value = { CONTROLLERS_PATH }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getControllers(HttpServletRequest request) { + preLogAudit(request); + String outboundJson = null; + // Static data + ControllerEndpointCredentials[] configured = getControllerEndpoints(); + try { + User appUser = UserUtils.getUserSession(request); + if (appUser == null || appUser.getLoginId() == null || appUser.getLoginId().length() == 0) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DashboardHomeController"); + MDC.put("TargetServiceName", "DashboardHomeController"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Get controllers failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "Failed to get application user"); + throw new Exception("getControllers: Failed to get application user"); + } + ControllerEndpointCredentials selectedInDb = getOrSetControllerEndpointSelection(appUser.getId()); + // Built result from properties + ArrayList<ControllerEndpointTransport> list = new ArrayList<>(); + for (ControllerEndpointCredentials ctrl : configured) { + // Check if this is the selected endpoint in DB + boolean selected = (selectedInDb != null && selectedInDb.getUrl() != null + && selectedInDb.getUrl().equals(ctrl.getUrl())); + // Result has no privileged information + ControllerEndpointTransport transport = new ControllerEndpointTransport(selected, ctrl.getName(), + ctrl.getUrl(), ctrl.getInventoryUrl(), ctrl.getDhandlerUrl(), ctrl.getConsulUrl()); + list.add(transport); + } + outboundJson = mapper.writeValueAsString(list); + } catch (Exception ex) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DashboardHomeController"); + MDC.put("TargetServiceName", "DashboardHomeController"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Get controllers failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "Failed to get controller endpoint list"); + RestResponseError response = new RestResponseError("Failed to get controller endpoint list", ex); + outboundJson = response.toJson(); + } finally { + postLogAudit(request); + } + return outboundJson; + } + + /** + * Sets the controller endpoint selection for the user. + * + * @param request + * HttpServletRequest + * @param endpoint + * Body with endpoint details + * @return Result indicating success or failure + * @throws Exception + * if application user is not found + */ + @RequestMapping(value = { CONTROLLERS_PATH }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public String setControllerSelection(HttpServletRequest request, @RequestBody ControllerEndpointTransport endpoint) + throws Exception { + preLogAudit(request); + String outboundJson = null; + User appUser = UserUtils.getUserSession(request); + if (appUser == null || appUser.getLoginId() == null || appUser.getLoginId().length() == 0) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DashboardHomeController"); + MDC.put("TargetServiceName", "DashboardHomeController"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Set controllers failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "Failed to get application user"); + postLogAudit(request); + throw new Exception("setControllerSelection: Failed to get application user"); + } + ControllerEndpoint dbEntry = new ControllerEndpoint(appUser.getId(), endpoint.getName(), endpoint.getUrl(), endpoint.getInventoryUrl(), endpoint.getDhandlerUrl()); + controllerEndpointService.updateControllerEndpointSelection(dbEntry); + RestResponseSuccess success = new RestResponseSuccess("Updated selection to " + endpoint.getName()); + outboundJson = mapper.writeValueAsString(success); + postLogAudit(request); + return outboundJson; + } + + public void preLogAudit(HttpServletRequest request) { + begin = new Date(); + MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(begin)); + MDC.put(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP, logDateFormat.format(begin)); + MDC.put(SystemProperties.STATUS_CODE, "COMPLETE"); + //logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME); + } + + public void postLogAudit(HttpServletRequest request) { + end = new Date(); + MDC.put("AlertSeverity", "0"); + MDC.put("TargetEntity", "DashboardHomeController"); + MDC.put("TargetServiceName", "DashboardHomeController"); + MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(end)); + MDC.put(SystemProperties.METRICSLOG_END_TIMESTAMP, logDateFormat.format(end)); + MDC.put(SystemProperties.MDC_TIMER, Long.toString((end.getTime() - begin.getTime()))); + logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI()); + logger.info(EELFLoggerDelegate.metricsLogger, request.getMethod() + request.getRequestURI()); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/DashboardRestrictedBaseController.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/DashboardRestrictedBaseController.java index 02f8770..809dbb9 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/DashboardRestrictedBaseController.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/DashboardRestrictedBaseController.java @@ -1,275 +1,470 @@ -/*******************************************************************************
- * =============LICENSE_START=========================================================
- *
- * =================================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *******************************************************************************/
-package org.onap.ccsdk.dashboard.controller;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.onap.ccsdk.dashboard.exception.DashboardControllerException;
-import org.onap.ccsdk.dashboard.rest.ControllerRestClientMockImpl;
-import org.onap.ccsdk.dashboard.service.ControllerEndpointService;
-import org.onap.ccsdk.dashboard.domain.ControllerEndpoint;
-import org.onap.ccsdk.dashboard.rest.IControllerRestClient;
-import org.onap.ccsdk.dashboard.util.DashboardProperties;
-import org.onap.ccsdk.dashboard.model.ControllerEndpointCredentials;
-import org.onap.ccsdk.dashboard.rest.ControllerRestClientImpl;
-import org.onap.portalsdk.core.controller.RestrictedBaseController;
-import org.onap.portalsdk.core.domain.User;
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.onap.portalsdk.core.web.support.UserUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-/**
- * This base class provides utility methods to child controllers.
- */
-public class DashboardRestrictedBaseController extends RestrictedBaseController {
-
- /**
- * Logger that conforms with ECOMP guidelines
- */
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(DashboardRestrictedBaseController.class);
-
- /**
- * Application name
- */
- protected static final String APP_NAME = "ecd-app";
-
- /**
- * EELF-approved format
- */
- protected static final DateFormat logDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
-
- /**
- * Query parameter for desired page number
- */
- protected static final String PAGE_NUM_QUERY_PARAM = "pageNum";
-
- /**
- * Query parameter for desired items per page
- */
- protected static final String PAGE_SIZE_QUERY_PARAM = "viewPerPage";
-
- /**
- * For general use in these methods and subclasses
- */
- protected final ObjectMapper objectMapper = new ObjectMapper();
-
- /**
- * Application properties - NOT available to constructor.
- */
- @Autowired
- private DashboardProperties appProperties;
-
- /**
- * For getting selected controller
- */
- @Autowired
- private ControllerEndpointService controllerEndpointService;
-
- /**
- * Hello Spring, here's your no-arg constructor.
- */
- public DashboardRestrictedBaseController() {
- // Do not serialize null values
- objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
- }
-
- /**
- * Access method for subclasses.
- *
- * @return DbcappProperties object that was autowired by Spring.
- */
- protected DashboardProperties getAppProperties() {
- return appProperties;
- }
-
- /**
- * Gets the requested page number from a query parameter in the
- * HttpServletRequest. Defaults to 1, which is useful to allow manual
- * testing of endpoints without supplying those pesky parameters.
- *
- * @param request
- * HttpServletRequest
- * @return Value of query parameter {@link #PAGE_NUM_QUERY_PARAM}; 1 if not
- * found.
- */
- protected int getRequestPageNumber(HttpServletRequest request) {
- int pageNum = 1;
- String param = request.getParameter(PAGE_NUM_QUERY_PARAM);
- if (param != null)
- pageNum = Integer.parseInt(param);
- return pageNum;
- }
-
- /**
- * Gets the requested page size from a query parameter in the
- * HttpServletRequest. Defaults to 50, which is useful to allow manual
- * testing of endpoints without supplying those pesky parameters.
- *
- * @param request
- * HttpServletRequest
- * @return Value of query parameter {@link #PAGE_SIZE_QUERY_PARAM}; 50 if
- * not found.
- */
- protected int getRequestPageSize(HttpServletRequest request) {
- int pageSize = 50;
- String param = request.getParameter(PAGE_SIZE_QUERY_PARAM);
- if (param != null)
- pageSize = Integer.parseInt(param);
- return pageSize;
- }
-
- /**
- * Gets the items for the specified page from the specified list.
- *
- * @param pageNum
- * Page number requested by user, indexed from 1
- * @param pageSize
- * Number of items per page
- * @param itemList
- * List of items to adjust
- * @return List of items; empty list if from==to
- */
- @SuppressWarnings("rawtypes")
- protected static List getPageOfList(final int pageNum, final int pageSize, final List itemList) {
- int firstIndexOnThisPage = pageSize * (pageNum - 1);
- int firstIndexOnNextPage = pageSize * pageNum;
- int fromIndex = firstIndexOnThisPage < itemList.size() ? firstIndexOnThisPage : itemList.size();
- int toIndex = firstIndexOnNextPage < itemList.size() ? firstIndexOnNextPage : itemList.size();
- return itemList.subList(fromIndex, toIndex);
- }
-
- /**
- * Gets all configured controllers from properties.
- *
- * @return Array of ControllerEndpointRestricted objects
- * @throws IllegalStateException
- * if a required property is not found
- */
- protected ControllerEndpointCredentials[] getControllerEndpoints() {
- final String[] controllerKeys = appProperties.getCsvListProperty(DashboardProperties.CONTROLLER_KEY_LIST);
- ControllerEndpointCredentials[] controllers = new ControllerEndpointCredentials[controllerKeys.length];
- for (int i = 0; i < controllerKeys.length; ++i) {
- String key = controllerKeys[i];
- final String name = appProperties.getControllerProperty(key, DashboardProperties.CONTROLLER_SUBKEY_NAME);
- final String url = appProperties.getControllerProperty(key, DashboardProperties.CONTROLLER_SUBKEY_URL);
- final String user = appProperties.getControllerProperty(key,
- DashboardProperties.CONTROLLER_SUBKEY_USERNAME);
- final String pass = appProperties.getControllerProperty(key,
- DashboardProperties.CONTROLLER_SUBKEY_PASSWORD);
- final boolean encr = Boolean.parseBoolean (
- appProperties.getControllerProperty(key, DashboardProperties.CONTROLLER_SUBKEY_ENCRYPTED));
- logger.debug(EELFLoggerDelegate.debugLogger, "getConfiguredControllers: key {} yields url {}", key, url);
- controllers[i] = new ControllerEndpointCredentials(false, name, url, user, pass, encr);
- }
- return controllers;
- }
-
- /**
- * Gets the controller endpoint for the specified user ID. Chooses the first
- * one from properties if the user has not selected one previously.
- *
- * @param userId
- * Database User ID
- * @return ControllerEndpointCredentials for the specified user
- */
- protected ControllerEndpointCredentials getOrSetControllerEndpointSelection(long userId) {
- // Always need the complete list from properties
- ControllerEndpointCredentials[] configured = getControllerEndpoints();
- // See if the database has an entry for this user
- ControllerEndpoint dbEntry = controllerEndpointService.getControllerEndpointSelection(userId);
- // If no row found DAO returns an object with null entries.
- if (dbEntry == null || dbEntry.getName() == null) {
- // Arbitrarily choose the first one
- ControllerEndpointCredentials first = configured[0];
- dbEntry = new ControllerEndpoint(userId, first.getName(), first.getUrl());
- controllerEndpointService.updateControllerEndpointSelection(dbEntry);
- }
- // Fetch complete details for the selected item
- ControllerEndpointCredentials selected = null;
- for (ControllerEndpointCredentials cec : configured) {
- if (dbEntry.getUrl().equals(cec.getUrl())) {
- selected = cec;
- break;
- }
- }
- // Defend against a stale database entry.
- if (selected == null) {
- selected = configured[0];
- dbEntry = new ControllerEndpoint(userId, selected.getName(), selected.getUrl());
- controllerEndpointService.updateControllerEndpointSelection(dbEntry);
- }
- return selected;
- }
-
- /**
- * Convenience method that gets the user ID from the session and fetches the
- * REST client. Factors code out of subclass methods.
- *
- * @param request
- * HttpServletRequest
- * @return REST client appropriate for the user
- * @throws DashboardControllerException
- */
- protected IControllerRestClient getControllerRestClient(HttpServletRequest request) throws DashboardControllerException {
- User appUser = UserUtils.getUserSession(request);
- if (appUser == null || appUser.getLoginId() == null || appUser.getLoginId().length() == 0)
- throw new DashboardControllerException("getControllerRestClient: Failed to get application user");
- return getControllerRestClient(appUser.getId());
- }
-
- /**
- * Gets a REST client; either a mock client (returns canned data), or a real
- * client with appropriate credentials from properties.
- *
- * @return REST client.
- * @throws DashboardControllerException on any failure; e.g., if the password cannot be decrypted.
- */
- protected IControllerRestClient getControllerRestClient(long userId) throws DashboardControllerException {
- IControllerRestClient result = null;
- // Be robust to missing development-only property
- boolean mock = false;
- if (appProperties.containsProperty(DashboardProperties.CONTROLLER_MOCK_DATA))
- mock = appProperties.getBooleanProperty(DashboardProperties.CONTROLLER_MOCK_DATA);
- if (mock) {
- result = new ControllerRestClientMockImpl();
- } else {
- try {
- ControllerEndpointCredentials details = getOrSetControllerEndpointSelection(userId);
- final String clearText = details.getEncryptedPassword() ? details.decryptPassword() : details.getPassword();
- result = new ControllerRestClientImpl(details.getUrl(), details.getUsername(), clearText);
- }
- catch (Exception ex) {
- logger.error("getControllerRestClient failed", ex);
- throw new DashboardControllerException(ex);
- }
- }
- return result;
- }
-
-}
+/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.controller; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.onap.ccsdk.dashboard.domain.ControllerEndpoint; +import org.onap.ccsdk.dashboard.model.ControllerEndpointCredentials; +import org.onap.ccsdk.dashboard.model.ControllerOpsTools; +import org.onap.ccsdk.dashboard.rest.CloudifyClient; +import org.onap.ccsdk.dashboard.rest.CloudifyMockClientImpl; +import org.onap.ccsdk.dashboard.rest.CloudifyRestClientImpl; +import org.onap.ccsdk.dashboard.rest.ConsulClient; +import org.onap.ccsdk.dashboard.rest.ConsulMockClientImpl; +import org.onap.ccsdk.dashboard.rest.ConsulRestClientImpl; +import org.onap.ccsdk.dashboard.rest.DeploymentHandlerClient; +import org.onap.ccsdk.dashboard.rest.DeploymentHandlerClientImpl; +import org.onap.ccsdk.dashboard.rest.InventoryClient; +import org.onap.ccsdk.dashboard.rest.RestInventoryClientImpl; +import org.onap.ccsdk.dashboard.rest.RestInventoryClientMockImpl; +import org.onap.ccsdk.dashboard.service.ControllerEndpointService; +import org.onap.ccsdk.dashboard.util.DashboardProperties; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; + +/** + * This base class provides utility methods to child controllers. + */ +public class DashboardRestrictedBaseController extends RestrictedBaseController { + + /** + * Application name + */ + protected static final String APP_NAME = "ecd-app"; + + /** + * EELF-approved format + */ + protected static final DateFormat logDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); + + /** + * Query parameter for desired page number + */ + protected static final String PAGE_NUM_QUERY_PARAM = "pageNum"; + + /** + * Query parameter for desired items per page + */ + protected static final String PAGE_SIZE_QUERY_PARAM = "viewPerPage"; + + /** + * For general use in these methods and subclasses + */ + protected final ObjectMapper objectMapper = new ObjectMapper(); + + /** + * Application properties - NOT available to constructor. + */ + @Autowired + protected DashboardProperties appProperties; + + /** + * For getting selected controller + */ + @Autowired + private ControllerEndpointService controllerEndpointService; + + /** + * Hello Spring, here's your no-arg constructor. + */ + public DashboardRestrictedBaseController() { + // Do not serialize null values + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + // Register Jdk8Module() for Stream and Optional types + objectMapper.registerModule(new Jdk8Module()); + } + + /** + * Access method for subclasses. + * + * @return DbcappProperties object that was autowired by Spring. + */ + protected DashboardProperties getAppProperties() { + return appProperties; + } + + /** + * Gets the requested page number from a query parameter in the + * HttpServletRequest. Defaults to 1, which is useful to allow manual + * testing of endpoints without supplying those pesky parameters. + * + * @param request + * HttpServletRequest + * @return Value of query parameter {@link #PAGE_NUM_QUERY_PARAM}; 1 if not + * found. + */ + protected int getRequestPageNumber(HttpServletRequest request) { + int pageNum = 1; + String param = request.getParameter(PAGE_NUM_QUERY_PARAM); + if (param != null) + pageNum = Integer.parseInt(param); + return pageNum; + } + + /** + * Gets the requested page size from a query parameter in the + * HttpServletRequest. Defaults to 50, which is useful to allow manual + * testing of endpoints without supplying those pesky parameters. + * + * @param request + * HttpServletRequest + * @return Value of query parameter {@link #PAGE_SIZE_QUERY_PARAM}; 50 if + * not found. + */ + protected int getRequestPageSize(HttpServletRequest request) { + int pageSize = 50; + String param = request.getParameter(PAGE_SIZE_QUERY_PARAM); + if (param != null) + pageSize = Integer.parseInt(param); + return pageSize; + } + + /** + * Gets the items for the specified page from the specified list. + * + * @param pageNum + * Page number requested by user, indexed from 1 + * @param pageSize + * Number of items per page + * @param itemList + * List of items to adjust + * @return List of items; empty list if from==to + */ + @SuppressWarnings("rawtypes") + protected static List getPageOfList(final int pageNum, final int pageSize, final List itemList) { + int firstIndexOnThisPage = pageSize * (pageNum - 1); + int firstIndexOnNextPage = pageSize * pageNum; + int fromIndex = firstIndexOnThisPage < itemList.size() ? firstIndexOnThisPage : itemList.size(); + int toIndex = firstIndexOnNextPage < itemList.size() ? firstIndexOnNextPage : itemList.size(); + return itemList.subList(fromIndex, toIndex); + } + + /** + * Gets all configured controllers from properties. + * + * @return Array of ControllerEndpointRestricted objects + * @throws IllegalStateException + * if a required property is not found + */ + protected ControllerEndpointCredentials[] getControllerEndpoints() { + final String[] controllerKeys = DashboardProperties.getCsvListProperty(DashboardProperties.CONTROLLER_KEY_LIST); + ControllerEndpointCredentials[] controllers = new ControllerEndpointCredentials[controllerKeys.length]; + for (int i = 0; i < controllerKeys.length; ++i) { + String key = controllerKeys[i]; + final String name = DashboardProperties.getControllerProperty(key, DashboardProperties.CONTROLLER_SUBKEY_NAME); + final String url = DashboardProperties.getControllerProperty(key, DashboardProperties.CONTROLLER_SUBKEY_URL); + final String inventoryUrl = DashboardProperties.getControllerProperty(key, DashboardProperties.CONTROLLER_SUBKEY_INVENTORY_URL); + final String dhandlerUrl = DashboardProperties.getControllerProperty(key, DashboardProperties.CONTROLLER_SUBKEY_DHANDLER_URL); + final String consulUrl = DashboardProperties.getControllerProperty(key, DashboardProperties.CONTROLLER_SUBKEY_CONSUL_URL); + final String user = DashboardProperties.getControllerProperty(key, + DashboardProperties.CONTROLLER_SUBKEY_USERNAME); + final String pass = DashboardProperties.getControllerProperty(key, + DashboardProperties.CONTROLLER_SUBKEY_PASS); + final boolean encr = Boolean.parseBoolean( + DashboardProperties.getControllerProperty(key, DashboardProperties.CONTROLLER_SUBKEY_ENCRYPTED)); + controllers[i] = new ControllerEndpointCredentials(false, name, url, inventoryUrl, dhandlerUrl, consulUrl, user, pass, encr); + } + return controllers; + } + + /** + * Get the list of configured OPS Tools URLs from dashboard properties + * + * @return Array of ControllerOpsTools objects + * @throws IllegalStateException + * if a required property is not found + */ + protected List<ControllerOpsTools> getControllerOpsTools() { + List<ControllerOpsTools> opsList = new ArrayList<>(); + final String[] controllerKeys = DashboardProperties.getCsvListProperty(DashboardProperties.CONTROLLER_KEY_LIST); + String key = controllerKeys[0]; + final String cfyId = DashboardProperties.OPS_CLOUDIFY_URL.split("\\.")[1]; + final String cfyUrl = DashboardProperties.getControllerProperty(key, DashboardProperties.OPS_CLOUDIFY_URL); + final String k8Id = DashboardProperties.OPS_K8S_URL.split("\\.")[1]; + final String k8Url = DashboardProperties.getControllerProperty(key, DashboardProperties.OPS_K8S_URL); + final String grfId = DashboardProperties.OPS_GRAFANA_URL.split("\\.")[1]; + final String grfUrl = DashboardProperties.getControllerProperty(key, DashboardProperties.OPS_GRAFANA_URL); + final String cnslId = DashboardProperties.OPS_CONSUL_URL.split("\\.")[1]; + final String cnslUrl = DashboardProperties.getControllerProperty(key, DashboardProperties.OPS_CONSUL_URL); + final String promId = DashboardProperties.OPS_PROMETHEUS_URL.split("\\.")[1]; + final String promUrl = DashboardProperties.getControllerProperty(key, DashboardProperties.OPS_PROMETHEUS_URL); + final String dbclId = DashboardProperties.OPS_DBCL_URL.split("\\.")[1]; + final String dbclUrl = DashboardProperties.getControllerProperty(key, DashboardProperties.OPS_DBCL_URL); + opsList.add(new ControllerOpsTools(cfyId, cfyUrl)); + opsList.add(new ControllerOpsTools(k8Id, k8Url)); + opsList.add(new ControllerOpsTools(grfId, grfUrl)); + opsList.add(new ControllerOpsTools(cnslId, cnslUrl)); + opsList.add(new ControllerOpsTools(promId, promUrl)); + opsList.add(new ControllerOpsTools(dbclId, dbclUrl)); + + return opsList; + } + + /** + * Gets the controller endpoint for the specified user ID. Chooses the first + * one from properties if the user has not selected one previously. + * + * @param userId + * Database User ID + * @return ControllerEndpointCredentials for the specified user + */ + protected ControllerEndpointCredentials getOrSetControllerEndpointSelection(long userId) { + // Always need the complete list from properties + ControllerEndpointCredentials[] configured = getControllerEndpoints(); + // See if the database has an entry for this user + ControllerEndpoint dbEntry = controllerEndpointService.getControllerEndpointSelection(userId); + // If no row found DAO returns an object with null entries. + if (dbEntry == null || dbEntry.getName() == null) { + // Arbitrarily choose the first one + ControllerEndpointCredentials first = configured[0]; + dbEntry = new ControllerEndpoint(userId, first.getName(), first.getUrl(), first.getInventoryUrl(), first.getDhandlerUrl()); + controllerEndpointService.updateControllerEndpointSelection(dbEntry); + } + // Fetch complete details for the selected item + ControllerEndpointCredentials selected = null; + for (ControllerEndpointCredentials cec : configured) { + if (dbEntry.getUrl().equals(cec.getUrl())) { + selected = cec; + break; + } + } + // Defend against a stale database entry. + if (selected == null) { + selected = configured[0]; + dbEntry = new ControllerEndpoint(userId, selected.getName(), selected.getUrl(), selected.getInventoryUrl(), selected.getDhandlerUrl()); + controllerEndpointService.updateControllerEndpointSelection(dbEntry); + } + return selected; + } + + protected ControllerEndpointCredentials getOrSetControllerEndpointSelection() { + ControllerEndpointCredentials[] configured = getControllerEndpoints(); + return configured[0]; + } + /** + * Convenience method that gets the user ID from the session and fetches the + * REST client. Factors code out of subclass methods. + * + * @param request + * HttpServletRequest + * @return REST client appropriate for the user + */ + protected CloudifyClient getCloudifyRestClient(HttpServletRequest request) throws Exception { + User appUser = UserUtils.getUserSession(request); + if (appUser == null || appUser.getId() == null ) + throw new Exception("getCloudifyRestClient: Failed to get application user"); + return getCloudifyRestClient(appUser.getId()); + } + + /** + * Gets a REST client; either a mock client (returns canned data), or a real + * client with appropriate credentials from properties. + * + * @return REST client. + */ + protected CloudifyClient getCloudifyRestClient(long userId) throws Exception { + CloudifyClient result = null; + // Be robust to missing development-only property + boolean mock = false; + if (DashboardProperties.containsProperty(DashboardProperties.CONTROLLER_MOCK_DATA)) + mock = DashboardProperties.getBooleanProperty(DashboardProperties.CONTROLLER_MOCK_DATA); + if (mock) { + result = new CloudifyMockClientImpl(); + } else { + ControllerEndpointCredentials details = getOrSetControllerEndpointSelection(userId); + final String clearText = details.getEncryptedPassword() ? details.decryptPassword() : details.getPassword(); + result = new CloudifyRestClientImpl(details.getUrl(), details.getUsername(), clearText); + } + return result; + } + + /** + * Gets a REST client; either a mock client (returns canned data), or a real + * client with appropriate credentials from properties. + * + * @return REST client. + */ + protected CloudifyClient getCloudifyRestClient() throws Exception { + CloudifyClient result = null; + // Be robust to missing development-only property + boolean mock = false; + if (DashboardProperties.containsProperty(DashboardProperties.CONTROLLER_MOCK_DATA)) + mock = DashboardProperties.getBooleanProperty(DashboardProperties.CONTROLLER_MOCK_DATA); + if (mock) { + result = new CloudifyMockClientImpl(); + } else { + ControllerEndpointCredentials details = getOrSetControllerEndpointSelection(); + final String clearText = details.getEncryptedPassword() ? details.decryptPassword() : details.getPassword(); + result = new CloudifyRestClientImpl(details.getUrl(), details.getUsername(), clearText); + } + return result; + } + + /** + * Convenience method that gets the user ID from the session and fetches the + * REST client. Factors code out of subclass methods. + * + * @param request + * HttpServletRequest + * @return REST client appropriate for the user + */ + protected ConsulClient getConsulRestClient(HttpServletRequest request) throws Exception { + User appUser = UserUtils.getUserSession(request); + if (appUser == null || appUser.getId() == null ) + throw new Exception("getControllerRestClient: Failed to get application user"); + return getConsulRestClient(appUser.getId()); + } + + /** + * Gets a REST client; either a mock client (returns canned data), or a real + * client with appropriate credentials from properties. + * + * @return REST client. + */ + protected ConsulClient getConsulRestClient(long userId) throws Exception { + ConsulClient result = null; + // Be robust to missing development-only property + boolean mock = false; + if (DashboardProperties.containsProperty(DashboardProperties.CONTROLLER_MOCK_DATA)) + mock = DashboardProperties.getBooleanProperty(DashboardProperties.CONTROLLER_MOCK_DATA); + if (mock) { + result = new ConsulMockClientImpl(); + } else { + ControllerEndpointCredentials details = getOrSetControllerEndpointSelection(); + final String clearText = details.getEncryptedPassword() ? details.decryptPassword() : details.getPassword(); + result = new ConsulRestClientImpl(details.getConsulUrl(), details.getUsername(), clearText); + } + return result; + } + + /** + * Gets a REST client; either a mock client (returns canned data), or a real + * client with appropriate credentials from properties. + * + * @return REST client. + */ + protected ConsulClient getConsulRestClient() throws Exception { + ConsulClient result = null; + // Be robust to missing development-only property + boolean mock = false; + if (DashboardProperties.containsProperty(DashboardProperties.CONTROLLER_MOCK_DATA)) + mock = DashboardProperties.getBooleanProperty(DashboardProperties.CONTROLLER_MOCK_DATA); + if (mock) { + result = new ConsulMockClientImpl(); + } else { + ControllerEndpointCredentials details = getOrSetControllerEndpointSelection(); + final String clearText = details.getEncryptedPassword() ? details.decryptPassword() : details.getPassword(); + result = new ConsulRestClientImpl(details.getConsulUrl(), details.getUsername(), clearText); + } + return result; + } + + /** + * Convenience method that gets the user ID from the session and fetches the + * Inventory client. Factors code out of subclass methods. + * + * @param request + * HttpServletRequest + * @return Inventory client appropriate for the user + */ + protected InventoryClient getInventoryClient(HttpServletRequest request) throws Exception { + User appUser = UserUtils.getUserSession(request); + if (appUser == null || appUser.getId() == null) + throw new Exception("getControllerRestClient: Failed to get application user"); + return getInventoryClient(appUser.getId()); + } + + /** + * Gets an Inventory client with appropriate credentials from properties. + * + * @return Inventory Client. + */ + protected InventoryClient getInventoryClient(long userId) throws Exception { + InventoryClient result = null; + boolean mock = false; + if (DashboardProperties.containsProperty(DashboardProperties.CONTROLLER_MOCK_DATA)) + mock = DashboardProperties.getBooleanProperty(DashboardProperties.CONTROLLER_MOCK_DATA); + if (mock) { + result = new RestInventoryClientMockImpl(); + } else { + ControllerEndpointCredentials details = getOrSetControllerEndpointSelection(userId); + final String clearText = details.getEncryptedPassword() ? details.decryptPassword() : details.getPassword(); + result = new RestInventoryClientImpl(details.getInventoryUrl(), details.getUsername(), clearText); + } + return result; + } + + protected InventoryClient getInventoryClient() throws Exception { + InventoryClient result = null; + ControllerEndpointCredentials details = getOrSetControllerEndpointSelection(); + final String clearText = details.getEncryptedPassword() ? details.decryptPassword() : details.getPassword(); + result = new RestInventoryClientImpl(details.getInventoryUrl(), details.getUsername(), clearText); + return result; + } + /** + * Convenience method that gets the user ID from the session and fetches the + * Deployment Handler client. Factors code out of subclass methods. + * + * @param request + * HttpServletRequest + * @return Deployment Handler client appropriate for the user + */ + protected DeploymentHandlerClient getDeploymentHandlerClient(HttpServletRequest request) throws Exception { + User appUser = UserUtils.getUserSession(request); + if (appUser == null || appUser.getId() == null) + throw new Exception("getControllerRestClient: Failed to get application user"); + return getDeploymentHandlerClient(appUser.getId()); + } + + /** + * Gets a Deployment Handler client with appropriate credentials from properties. + * + * @return Deployment Handler Client. + */ + protected DeploymentHandlerClient getDeploymentHandlerClient(long userId) throws Exception { + DeploymentHandlerClient result = null; + ControllerEndpointCredentials details = getOrSetControllerEndpointSelection(userId); + final String clearText = details.getEncryptedPassword() ? details.decryptPassword() : details.getPassword(); + result = new DeploymentHandlerClientImpl(details.getDhandlerUrl(), details.getUsername(), clearText); + return result; + } + + protected DeploymentHandlerClient getDeploymentHandlerClient() throws Exception { + DeploymentHandlerClient result = null; + ControllerEndpointCredentials details = getOrSetControllerEndpointSelection(); + final String clearText = details.getEncryptedPassword() ? details.decryptPassword() : details.getPassword(); + result = new DeploymentHandlerClientImpl(details.getDhandlerUrl(), details.getUsername(), clearText); + return result; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/DeploymentHandlerController.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/DeploymentHandlerController.java new file mode 100644 index 0000000..c99583c --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/DeploymentHandlerController.java @@ -0,0 +1,243 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.controller; + +import java.util.Date; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.onap.ccsdk.dashboard.exceptions.BadRequestException; +import org.onap.ccsdk.dashboard.exceptions.DeploymentNotFoundException; +import org.onap.ccsdk.dashboard.exceptions.DownstreamException; +import org.onap.ccsdk.dashboard.exceptions.ServerErrorException; +import org.onap.ccsdk.dashboard.exceptions.ServiceAlreadyExistsException; +import org.onap.ccsdk.dashboard.model.RestResponseError; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentRequest; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentRequestObject; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentResource; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentResourceLinks; +import org.onap.ccsdk.dashboard.rest.DeploymentHandlerClient; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; +import org.slf4j.MDC; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.fasterxml.jackson.core.JsonProcessingException; + +/** + * Controller for Deployment Handler features: get/put/delete deployments + * Methods serve Ajax requests made by Angular scripts on pages that show + * content. + */ +@Controller +@RequestMapping("/deploymenthandler") +public class DeploymentHandlerController extends DashboardRestrictedBaseController { + + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(DeploymentHandlerController.class); + + private static final String DEPLOYMENTS_PATH = "dcae-deployments"; + + private static Date begin, end; + + @RequestMapping(value = { DEPLOYMENTS_PATH + "/{deploymentId:.+}" }, method = RequestMethod.PUT, produces = "application/json") + @ResponseBody + public String putDeployment(HttpServletRequest request, @RequestBody DeploymentRequestObject deploymentRequestObject) throws Exception { + preLogAudit(request); + String json = null; + try { + DeploymentHandlerClient deploymentHandlerClient = getDeploymentHandlerClient(request); + if (deploymentRequestObject.getMethod().equals("create")) { + json = objectMapper.writeValueAsString(deploymentHandlerClient.putDeployment(deploymentRequestObject.getDeploymentId(), + deploymentRequestObject.getTenant(), new DeploymentRequest(deploymentRequestObject.getServiceTypeId(), deploymentRequestObject.getInputs()))); + } else { + json = objectMapper.writeValueAsString(deploymentHandlerClient.updateDeployment(deploymentRequestObject.getDeploymentId(), + deploymentRequestObject.getTenant(), new DeploymentRequest(deploymentRequestObject.getServiceTypeId(), deploymentRequestObject.getInputs()))); + } + } catch (BadRequestException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed! Bad Request"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("Bad Request " + e.getMessage())); + } catch (ServiceAlreadyExistsException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed! Service already exists"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("Service already exists " + e.getMessage())); + } catch (ServerErrorException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed! Server Error"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("Server Error " + e.getMessage())); + } catch (DownstreamException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed! Downstream Exception"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("Downstream Exception " + e.getMessage())); + } catch (JsonProcessingException jpe) { + // Should never, ever happen + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed! Json Processing Exception"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = "{ \"error\" : \"" + jpe.toString() + "\"}"; + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "putDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("putDeployment failed", t)); + } finally { + postLogAudit(request); + } + return json; + } + + @RequestMapping(value = { DEPLOYMENTS_PATH + "/{deploymentId:.+}" }, method = RequestMethod.DELETE, produces = "application/json") + @ResponseBody + public String deleteDeployment(@PathVariable("deploymentId") String deploymentId, HttpServletRequest request, + @RequestParam("tenant") String tenant, HttpServletResponse response) throws Exception { + preLogAudit(request); + String json = null; + StringBuffer status = new StringBuffer(); + try { + DeploymentHandlerClient deploymentHandlerClient = getDeploymentHandlerClient(request); + deploymentHandlerClient.deleteDeployment(deploymentId, tenant); + String self = request.getRequestURL().toString().split("\\?")[0]; + status.append(self) + .append("/executions?tenant=") + .append(tenant); + DeploymentResource deplRsrc = + new DeploymentResource(deploymentId, + new DeploymentResourceLinks(self, "", status.toString())); + JSONObject statObj = new JSONObject(deplRsrc); + json = statObj.toString(); + } catch (BadRequestException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (ServerErrorException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (DownstreamException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (DeploymentNotFoundException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (JsonProcessingException jpe) { + // Should never, ever happen + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteDeployment caught exception"); + json = "{ \"error\" : \"" + jpe.toString() + "\"}"; + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting deployment " + deploymentId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteDeployment caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("deleteDeployment failed", t)); + } finally { + postLogAudit(request); + } + return json; + } + + public void preLogAudit(HttpServletRequest request) { + begin = new Date(); + MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(begin)); + MDC.put(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP, logDateFormat.format(begin)); + MDC.put(SystemProperties.STATUS_CODE, "COMPLETE"); + //logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME); + } + + public void postLogAudit(HttpServletRequest request) { + end = new Date(); + MDC.put("AlertSeverity", "0"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(end)); + MDC.put(SystemProperties.METRICSLOG_END_TIMESTAMP, logDateFormat.format(end)); + MDC.put(SystemProperties.MDC_TIMER, Long.toString((end.getTime() - begin.getTime()))); + logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI()); + logger.info(EELFLoggerDelegate.metricsLogger, request.getMethod() + request.getRequestURI()); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/ECDSingleSignOnController.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/ECDSingleSignOnController.java index 28f939c..de86a3e 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/ECDSingleSignOnController.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/ECDSingleSignOnController.java @@ -1,299 +1,302 @@ -/*-
- * ================================================================================
- * ECOMP Portal SDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ================================================================================
- */
-
-package org.onap.ccsdk.dashboard.controller;
-
-import java.io.UnsupportedEncodingException;
-
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-
-import org.onap.ccsdk.dashboard.exception.DashboardControllerException;
-import org.onap.portalsdk.core.auth.LoginStrategy;
-import org.onap.portalsdk.core.command.LoginBean;
-import org.onap.portalsdk.core.controller.UnRestrictedBaseController;
-import org.onap.portalsdk.core.domain.User;
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.onap.portalsdk.core.menu.MenuProperties;
-import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
-import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler;
-import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
-import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
-import org.onap.portalsdk.core.service.LoginService;
-import org.onap.portalsdk.core.util.SystemProperties;
-import org.onap.portalsdk.core.web.support.AppUtils;
-import org.onap.portalsdk.core.web.support.UserUtils;
-import org.onap.portalsdk.core.service.RoleService;
-import org.onap.portalsdk.core.domain.RoleFunction;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.client.RestClientException;
-import org.springframework.web.client.RestTemplate;
-import org.springframework.web.servlet.ModelAndView;
-import org.springframework.web.util.WebUtils;
-
-@Controller
-@RequestMapping("/")
-/**
- * Replicated from
- * org.onap.portalapp.controller.core.SingleSignOnController to modify the
- * behavior of sending user's browser on a detour of Portal app to get the
- * EPService cookie.
- */
-public class ECDSingleSignOnController extends UnRestrictedBaseController {
-
- private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ECDSingleSignOnController.class);
- private static final String REDIRECT = "redirect:";
-
- @Autowired
- private LoginService loginService;
-
- @Autowired
- private LoginStrategy loginStrategy;
-
- @Autowired
- private RoleService roleService;
-
- private String viewName;
- private String welcomeView;
-
- /**
- * Handles requests directed to the single sign-on page by the session timeout
- * interceptor.
- *
- * @param request
- * HttpServletRequest
- * @param response
- * HttpServletResponse
- * @return Redirect to an appropriate address
- * @throws DashboardControllerException
- * User not found
- * @throws PortalAPIException
- * User ID can't be fetched
- * @throws UnsupportedEncodingException
- * Encoding fails
- */
- @RequestMapping(value = { "/single_signon.htm" }, method = RequestMethod.GET)
- public ModelAndView singleSignOnLogin(HttpServletRequest request, HttpServletResponse response) throws Exception {
- //throws DashboardControllerException, PortalAPIException, UnsupportedEncodingException {
-
- Map<String, String> model = new HashMap<>();
- HashMap<String, String> additionalParamsMap = new HashMap<>();
- LoginBean commandBean = new LoginBean();
-
- // SessionTimeoutInterceptor sets these parameters
- String forwardURL = URLDecoder.decode(request.getParameter("forwardURL"), "UTF-8");
- String redirectToPortal = request.getParameter("redirectToPortal");
-
- if (isLoginCookieExist(request) && redirectToPortal == null) {
- HttpSession session = null;
- session = AppUtils.getSession(request);
- User user = UserUtils.getUserSession(request);
- if (session == null || user == null) {
-
- final String authMech = SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM);
- String userId = loginStrategy.getUserId(request);
- commandBean.setUserid(userId);
- commandBean = getLoginService().findUser(commandBean,
- (String) request.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY), additionalParamsMap);
- List<RoleFunction> roleFunctionList = roleService.getRoleFunctions(userId);
- try {
- commandBean = getLoginService().findUser(commandBean,
- (String) request.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY),
- additionalParamsMap);
- } catch (Exception ex) {
- logger.error("singleSignOnLogin failed", ex);
- throw new DashboardControllerException(ex);
- }
- if (commandBean.getUser() == null) {
- String loginErrorMessage = (commandBean.getLoginErrorMessage() != null)
- ? commandBean.getLoginErrorMessage()
- : SystemProperties.MESSAGE_KEY_LOGIN_ERROR_USER_NOT_FOUND;
- model.put(LoginStrategy.ERROR_MESSAGE_KEY, SystemProperties.getProperty(loginErrorMessage));
- final String redirectUrl = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)
- + "?noUserError=Yes";
- logger.debug(EELFLoggerDelegate.debugLogger, "singleSignOnLogin: user is null, redirect URL is {}",
- redirectUrl);
- return new ModelAndView(REDIRECT + redirectUrl);
- } else {
- // store the user's information in the session
- String loginMethod;
- if (null == authMech || "".equals(authMech) || "BOTH".equals(authMech)) {
- loginMethod = SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_CSP);
- } else if ("CSP".equals(authMech)) {
- loginMethod = SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_CSP);
- } else {
- loginMethod = SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_WEB_JUNCTION);
- }
- UserUtils.setUserSession(request, commandBean.getUser(), commandBean.getMenu(),
- commandBean.getBusinessDirectMenu(), loginMethod, roleFunctionList);
- initateSessionMgtHandler(request);
- 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);
- }
- } // 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);
- }
- } else {
- /*
- * Login cookie not found, or redirect-to-portal parameter was found.
- */
- if (isPortalAvailable()) {
- /*
- * Redirect the user to the portal with a suitable return URL. The forwardURL
- * parameter that arrives as a parameter is a partial (not absolute) request
- * path for a page in the application. The challenge here is to compute the
- * correct absolute path for the original request so the portal can redirect the
- * user back to the right place. If the application sits behind WebJunction, or
- * if separate FE-BE hosts are used, then the URL yielded by the request has a
- * host name that is not reachable by the user.
- */
- String returnToAppUrl = null;
- if (SystemProperties.containsProperty(SystemProperties.APP_BASE_URL)) {
- // New feature as of 1610, release 3.3.3:
- // application can publish a base URL in system.properties
- String appUrl = SystemProperties.getProperty(SystemProperties.APP_BASE_URL);
- returnToAppUrl = appUrl + (appUrl.endsWith("/") ? "" : "/") + forwardURL;
- logger.debug(EELFLoggerDelegate.debugLogger,
- "singleSignOnLogin: using app base URL {} and redirectURL {}", appUrl, returnToAppUrl);
- } else {
- /**
- * Be backward compatible with applications that don't need this feature. This
- * is the controller for the single_signon.htm page, so the replace should
- * always find the specified token.
- */
- returnToAppUrl = request.getRequestURL().toString()
- .replace("single_signon.htm", forwardURL);
- logger.debug(EELFLoggerDelegate.debugLogger, "singleSignOnLogin: computed redirectURL {}",
- returnToAppUrl);
- }
- final String encodedReturnToAppUrl = URLEncoder.encode(returnToAppUrl, "UTF-8");
- // Also send the application's UEB key so Portal can block URL
- // reflection attacks.
- final String uebAppKey = PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY);
- final String url = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL);
- final String portalUrl = url.substring(0, url.lastIndexOf('/')) + "/process_csp";
- final String redirectUrl = portalUrl + "?uebAppKey=" + uebAppKey + "&redirectUrl="
- + encodedReturnToAppUrl;
- logger.debug(EELFLoggerDelegate.debugLogger, "singleSignOnLogin: portal-bound redirect URL is {}",
- redirectUrl);
- return new ModelAndView(REDIRECT + redirectUrl);
- } // portal is available
-
- else {
- /*
- * Portal is not available. Redirect user to the login page, ignoring the
- * forwardURL parameter.
- */
- return new ModelAndView("redirect:login.htm");
- }
-
- }
- }
-
- /**
- * Discover if the portal is available by GET-ing a resource from the REST URL
- * specified in portal.properties, using a very short timeout.
- *
- * @return True if the portal answers, otherwise false.
- */
- private boolean isPortalAvailable() {
- HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
- final int oneSecond = 1000;
- httpRequestFactory.setConnectionRequestTimeout(oneSecond);
- httpRequestFactory.setConnectTimeout(oneSecond);
- httpRequestFactory.setReadTimeout(oneSecond);
- RestTemplate restTemplate = new RestTemplate(httpRequestFactory);
- boolean avail = true;
- try {
- final String portalUrl = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL);
- String s = restTemplate.getForObject(portalUrl, String.class);
- logger.trace("isPortalAvailable got response {}", s);
- } catch (RestClientException ex) {
- logger.debug("isPortalAvailable failed", ex);
- avail = false;
- }
- return avail;
- }
-
- protected void initateSessionMgtHandler(HttpServletRequest request) {
- String portalJSessionId = getPortalJSessionId(request);
- String jSessionId = getJessionId(request);
- PortalTimeoutHandler.sessionCreated(portalJSessionId, jSessionId, AppUtils.getSession(request));
- }
-
- public boolean isLoginCookieExist(HttpServletRequest request) {
- Cookie ep = WebUtils.getCookie(request, LoginStrategy.EP_SERVICE);
- return (ep != null);
- }
-
- public String getPortalJSessionId(HttpServletRequest request) {
- Cookie ep = WebUtils.getCookie(request, LoginStrategy.EP_SERVICE);
- return ep.getValue();
- }
-
- public String getJessionId(HttpServletRequest request) {
- return request.getSession().getId();
- }
-
- @Override
- public String getViewName() {
- return viewName;
- }
-
- @Override
- public void setViewName(String viewName) {
- this.viewName = viewName;
- }
-
- public String getWelcomeView() {
- return welcomeView;
- }
-
- public void setWelcomeView(String welcomeView) {
- this.welcomeView = welcomeView;
- }
-
- public LoginService getLoginService() {
- return loginService;
- }
-
- public void setLoginService(LoginService loginService) {
- this.loginService = loginService;
- }
-
-}
+/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.controller; + +/*- + * ================================================================================ + * ECOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ + +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.onap.portalsdk.core.auth.LoginStrategy; +import org.onap.portalsdk.core.command.LoginBean; +import org.onap.portalsdk.core.controller.UnRestrictedBaseController; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.menu.MenuProperties; +import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler; +import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; +import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; +import org.onap.portalsdk.core.service.LoginService; +import org.onap.portalsdk.core.service.RoleService; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.AppUtils; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.util.WebUtils; + +@Controller +@RequestMapping("/") +/** + * Replicated from + * org.openecomp.portalapp.controller.core.SingleSignOnController to modify the + * behavior of sending user's browser on a detour of Portal app to get the + * EPService cookie. + */ +public class ECDSingleSignOnController extends UnRestrictedBaseController { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ECDSingleSignOnController.class); + + @Autowired + private LoginService loginService; + + @Autowired + private LoginStrategy loginStrategy; + + @Autowired + private RoleService roleService; + + private String viewName; + private String welcomeView; + + /** + * Handles requests directed to the single sign-on page by the session + * timeout interceptor. + * + * @param request + * HttpServletRequest + * @param response + * HttpServletResponse + * @return Redirect to an appropriate address + * @throws Exception + * On any failure + */ + @RequestMapping(value = { "/single_signon.htm" }, method = RequestMethod.GET) + public ModelAndView singleSignOnLogin(HttpServletRequest request, HttpServletResponse response) throws Exception { + + Map<String, String> model = new HashMap<String, String>(); + HashMap<String, String> additionalParamsMap = new HashMap<String, String>(); + LoginBean commandBean = new LoginBean(); + + // SessionTimeoutInterceptor sets these parameters + String forwardURL = URLDecoder.decode(request.getParameter("forwardURL"), "UTF-8"); + String redirectToPortal = request.getParameter("redirectToPortal"); + + if (isLoginCookieExist(request) && redirectToPortal == null) { + HttpSession session = null; + session = AppUtils.getSession(request); + User user = UserUtils.getUserSession(request); + if (session == null || user == null) { + + final String authMech = SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM); + String userId = loginStrategy.getUserId(request); + commandBean.setUserid(userId); + commandBean = getLoginService().findUser(commandBean, + (String) request.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY), + additionalParamsMap); + if (commandBean.getUser() == null) { + String loginErrorMessage = (commandBean.getLoginErrorMessage() != null) + ? commandBean.getLoginErrorMessage() + : SystemProperties.MESSAGE_KEY_LOGIN_ERROR_USER_NOT_FOUND; + model.put(LoginStrategy.ERROR_MESSAGE_KEY, SystemProperties.getProperty(loginErrorMessage)); + final String redirectUrl = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL) + + "?noUserError=Yes"; + logger.debug(EELFLoggerDelegate.debugLogger, "singleSignOnLogin: user is null, redirect URL is {}", + redirectUrl); + return new ModelAndView("redirect:" + redirectUrl); + } else { + // store the user's information in the session + String loginMethod; + if (null == authMech || "".equals(authMech) || "BOTH".equals(authMech)) { + loginMethod = SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_CSP); + } else if ("CSP".equals(authMech)) { + loginMethod = SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_CSP); + } else { + loginMethod = SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_WEB_JUNCTION); + } + UserUtils.setUserSession(request, commandBean.getUser(), commandBean.getMenu(), + commandBean.getBusinessDirectMenu(), loginMethod, roleService.getRoleFunctions(userId)); + initateSessionMgtHandler(request); + 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); + } + } // 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); + } + } else { + /* + * Login cookie not found, or redirect-to-portal parameter was + * found. + */ + if (isPortalAvailable()) { + /* + * Redirect the user to the portal with a suitable return URL. + * The forwardURL parameter that arrives as a parameter is a + * partial (not absolute) request path for a page in the + * application. The challenge here is to compute the correct + * absolute path for the original request so the portal can + * redirect the user back to the right place. If the application + * sits behind WebJunction, or if separate FE-BE hosts are used, + * then the URL yielded by the request has a host name that is + * not reachable by the user. + */ + String returnToAppUrl = null; + if (SystemProperties.containsProperty(SystemProperties.APP_BASE_URL)) { + // New feature as of 1610, release 3.3.3: + // application can publish a base URL in system.properties + String appUrl = SystemProperties.getProperty(SystemProperties.APP_BASE_URL); + returnToAppUrl = appUrl + (appUrl.endsWith("/") ? "" : "/") + forwardURL; + logger.debug(EELFLoggerDelegate.debugLogger, + "singleSignOnLogin: using app base URL {} and redirectURL {}", appUrl, returnToAppUrl); + } else { + /** + * Be backward compatible with applications that don't need + * this feature. This is the controller for the + * single_signon.htm page, so the replace should always find + * the specified token. + */ + returnToAppUrl = ((HttpServletRequest) request).getRequestURL().toString() + .replace("single_signon.htm", forwardURL); + logger.debug(EELFLoggerDelegate.debugLogger, "singleSignOnLogin: computed redirectURL {}", + returnToAppUrl); + } + final String encodedReturnToAppUrl = URLEncoder.encode(returnToAppUrl, "UTF-8"); + // Also send the application's UEB key so Portal can block URL + // reflection attacks. + final String uebAppKey = PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY); + final String url = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL); + final String portalUrl = url.substring(0, url.lastIndexOf('/')) + "/process_csp"; + final String redirectUrl = portalUrl + "?uebAppKey=" + uebAppKey + "&redirectUrl=" + + encodedReturnToAppUrl; + logger.debug(EELFLoggerDelegate.debugLogger, "singleSignOnLogin: portal-bound redirect URL is {}", + redirectUrl); + return new ModelAndView("redirect:" + redirectUrl); + } // portal is available + + else { + /* + * Portal is not available. Redirect user to the login page, + * ignoring the forwardURL parameter. + */ + return new ModelAndView("redirect:login.htm"); + } + + } + } + + /** + * Discover if the portal is available by GET-ing a resource from the REST + * URL specified in portal.properties, using a very short timeout. + * + * @return True if the portal answers, otherwise false. + */ + private boolean isPortalAvailable() { + HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory(); + final int oneSecond = 1000; + httpRequestFactory.setConnectionRequestTimeout(oneSecond); + httpRequestFactory.setConnectTimeout(oneSecond); + httpRequestFactory.setReadTimeout(oneSecond); + RestTemplate restTemplate = new RestTemplate(httpRequestFactory); + boolean avail = true; + try { + final String portalUrl = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL); + String s = restTemplate.getForObject(portalUrl, String.class); + logger.trace("isPortalAvailable got response {}", s); + } catch (RestClientException ex) { + logger.debug("isPortalAvailable failed", ex); + avail = false; + } + return avail; + } + + protected void initateSessionMgtHandler(HttpServletRequest request) { + String portalJSessionId = getPortalJSessionId(request); + String jSessionId = getJessionId(request); + PortalTimeoutHandler.sessionCreated(portalJSessionId, jSessionId, AppUtils.getSession(request)); + } + + public boolean isLoginCookieExist(HttpServletRequest request) { + Cookie ep = WebUtils.getCookie(request, LoginStrategy.EP_SERVICE); + return (ep != null); + } + + public String getPortalJSessionId(HttpServletRequest request) { + Cookie ep = WebUtils.getCookie(request, LoginStrategy.EP_SERVICE); + return ep.getValue(); + } + + public String getJessionId(HttpServletRequest request) { + return request.getSession().getId(); + } + + public String getViewName() { + return viewName; + } + + public void setViewName(String viewName) { + this.viewName = viewName; + } + + public String getWelcomeView() { + return welcomeView; + } + + public void setWelcomeView(String welcomeView) { + this.welcomeView = welcomeView; + } + + public LoginService getLoginService() { + return loginService; + } + + public void setLoginService(LoginService loginService) { + this.loginService = loginService; + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/HealthCheckController.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/HealthCheckController.java index be099a7..0810e3d 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/HealthCheckController.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/HealthCheckController.java @@ -1,86 +1,277 @@ -/*******************************************************************************
- * =============LICENSE_START=========================================================
- *
- * =================================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *******************************************************************************/
-package org.onap.ccsdk.dashboard.controller;
-
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.onap.ccsdk.dashboard.model.HealthStatus;
-import org.onap.portalsdk.core.controller.UnRestrictedBaseController;
-import org.onap.portalsdk.core.domain.App;
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.onap.portalsdk.core.service.DataAccessService;
-import org.onap.portalsdk.core.util.SystemProperties;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.EnableAspectJAutoProxy;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * This controller responds to probes for application health, returning a JSON
- * body to indicate current status.
- */
-@RestController
-@Configuration
-@EnableAspectJAutoProxy
-@RequestMapping("/")
-public class HealthCheckController extends UnRestrictedBaseController {
-
- private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HealthCheckController.class);
-
- private static final String HEALTH_CHECK_PATH = "/healthCheck";
-
- @Autowired
- private DataAccessService dataAccessService;
-
- /**
- * Checks application health by making a trivial query to (what??).
- *
- * @param request
- * HttpServletRequest
- * @return 200 if database access succeeds, 500 if it fails.
- */
- @RequestMapping(value = { HEALTH_CHECK_PATH }, method = RequestMethod.GET, produces = "application/json")
- public HealthStatus healthCheck(HttpServletRequest request) {
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, DashboardRestrictedBaseController.APP_NAME);
- logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI());
- HealthStatus healthStatus = null;
- try {
- logger.debug(EELFLoggerDelegate.debugLogger, "Performing health check");
- @SuppressWarnings("unchecked")
- // Get the single app.
- List<App> list = dataAccessService.getList(App.class, null);
- if (!list.isEmpty())
- healthStatus = new HealthStatus(200, SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME) + " health check succeeded");
- else
- healthStatus = new HealthStatus(500, SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME) + " health check failed to run db query");
- } catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "Failed to perform health check", ex);
- healthStatus = new HealthStatus(500, "health check failed: " + ex.toString());
- }
- return healthStatus;
- }
-
-}
+/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ + +package org.onap.ccsdk.dashboard.controller; + + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.UnknownHostException; +import java.util.Date; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.http.HttpStatus; +import org.onap.ccsdk.dashboard.model.ControllerEndpointCredentials; +import org.onap.ccsdk.dashboard.model.HealthStatus; +import org.onap.portalsdk.core.domain.App; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.objectcache.AbstractCacheManager; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.util.SystemProperties; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +/** + * This controller responds to probes for application health, returning a JSON + * body to indicate current status. + */ +@RestController +@Configuration +@EnableAspectJAutoProxy +@RequestMapping("/") +public class HealthCheckController extends DashboardRestrictedBaseController { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HealthCheckController.class); + + /** + * Application name + */ + protected static final String APP_NAME = "ecd-app"; + + private static Date begin, end; + private static final String APP_HEALTH_CHECK_PATH = "/health"; + private static final String APP_SRVC_HEALTH_CHECK_PATH = "/health-info"; + + private static final String APP_DB_QRY = "from App where id = 1"; + public static final String APP_METADATA = "APP.METADATA"; + + @Autowired + private DataAccessService dataAccessService; + + private AbstractCacheManager cacheManager; + + /** + * application health by simply responding with a JSON object indicating status + * + * @param request + * HttpServletRequest + * @return HealthStatus object always + */ + @RequestMapping(value = { APP_HEALTH_CHECK_PATH }, method = RequestMethod.GET, produces = "application/json") + public HealthStatus healthCheck(HttpServletRequest request, HttpServletResponse response) { + return new HealthStatus(200, SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME) + " health check passed "); + } + + /** + * Checks application health by executing a sample query with local DB + * + * @param request + * HttpServletRequest + * @return 200 if database access succeeds, 500 if it fails. + */ + /* + public HealthStatus healthCheck(HttpServletRequest request, HttpServletResponse response) { + //preLogAudit(request); + HealthStatus healthStatus = new HealthStatus(200, SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME) + " health check passed "); + try { + logger.debug(EELFLoggerDelegate.debugLogger, "Performing health check"); + App app; + Object appObj = getCacheManager().getObject(APP_METADATA); + if (appObj == null) { + app = findApp(); + if (app != null) { + getCacheManager().putObject(APP_METADATA, app); + } else { + healthStatus = new HealthStatus(503, SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME) + " health check failed to query App from database"); + } + } + + if (isDbConnUp()) { + healthStatus = new HealthStatus(200, SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME) + " health check passed "); + } else { + healthStatus = new HealthStatus(503, SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME) + " health check failed to run db query"); + } + } catch (Exception ex) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Health Check"); + MDC.put("TargetServiceName", "Health Check"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Health check failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "Failed to perform health check"); + healthStatus = new HealthStatus(503, "health check failed: " + ex.toString()); + } finally { + postLogAudit(request); + } + if (healthStatus.getStatusCode() != 200) { + response.setStatus(HttpStatus.SC_SERVICE_UNAVAILABLE); + response.sendError(HttpStatus.SC_SERVICE_UNAVAILABLE, objectMapper.writeValueAsString(healthStatus)); + } + + return healthStatus; + } + */ + /** + * Checks application health and availability of dependent services + * + * @param request + * HttpServletRequest + * @return 200 if database access succeeds, 500 if it fails. + */ + @RequestMapping(value = { APP_SRVC_HEALTH_CHECK_PATH }, method = RequestMethod.GET, produces = "application/json") + public HealthStatus srvcHealthCheck(HttpServletRequest request, HttpServletResponse response) throws Exception { + preLogAudit(request); + HealthStatus healthStatus = null; + StringBuffer sb = new StringBuffer(); + try { + logger.debug(EELFLoggerDelegate.debugLogger, "Performing health check"); + if (isDbConnUp()) { + sb.append(SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME)).append( " health check passed; "); + healthStatus = new HealthStatus(200, SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME) + sb.toString()); + } else { + sb.append(SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME)).append(" health check failed to run db query; "); + healthStatus = new HealthStatus(503, SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME) + sb.toString()); + } + ControllerEndpointCredentials[] cec = getControllerEndpoints(); + + for(int i = 0; i < cec.length; ++i) { + // Check if API Handler is reachable + if (!isServiceReachable(cec[i].getUrl())) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "API Handler"); + MDC.put("TargetServiceName", "API Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "API Handler unreachable!"); + sb.append(" API Handler unreachable; "); + logger.error(EELFLoggerDelegate.errorLogger, "Failed to ping API Handler"); + } + // Check if Inventory is reachable + if (!isServiceReachable(cec[i].getInventoryUrl()+"/dcae-services")) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "DCAE Inventory unreachable!"); + sb.append(" DCAE Inventory unreachable; "); + logger.error(EELFLoggerDelegate.errorLogger, "Failed to ping DCAE Inventory"); + } + // Check if Deployment Handler is reachable + if (!isServiceReachable(cec[i].getDhandlerUrl())) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Deployment Handler"); + MDC.put("TargetServiceName", "Deployment Handler"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deployment Handler unreachable!"); + sb.append(" Deployment Handler unreachable; "); + logger.error(EELFLoggerDelegate.errorLogger, "Failed to ping Deployment Handler"); + } + } + } catch (Exception ex) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Health Check"); + MDC.put("TargetServiceName", "Health Check"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Health check failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "Failed to perform health check"); + sb.append(" "); + sb.append(ex.toString()); + healthStatus = new HealthStatus(503, SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME) + " health check failed: " + sb.toString()); + } finally { + postLogAudit(request); + } + if (healthStatus.getStatusCode() != 200) { + response.setStatus(HttpStatus.SC_SERVICE_UNAVAILABLE); + response.sendError(HttpStatus.SC_SERVICE_UNAVAILABLE, objectMapper.writeValueAsString(healthStatus)); + } + return healthStatus; + } + + private boolean isDbConnUp() { + @SuppressWarnings("unchecked") + List<App> list = dataAccessService.executeQuery(APP_DB_QRY, null); + if (list.size() > 0) { + return true; + } else { + return false; + } + } + + private App findApp() { + @SuppressWarnings("unchecked") + List<App> list = dataAccessService.executeQuery(APP_DB_QRY, null); + return (list == null || list.isEmpty()) ? null : (App) list.get(0); + } + + public static boolean isServiceReachable(String targetUrl) throws IOException { + HttpURLConnection httpUrlConnection = (HttpURLConnection) new URL(targetUrl).openConnection(); + httpUrlConnection.setRequestMethod("HEAD"); + + try { + int responseCode = httpUrlConnection.getResponseCode(); + return responseCode == HttpURLConnection.HTTP_OK; + } catch (UnknownHostException noInternetConnection) { + return false; + } + } + + @Autowired + public void setCacheManager(AbstractCacheManager cacheManager) { + this.cacheManager = cacheManager; + } + + public AbstractCacheManager getCacheManager() { + return cacheManager; + } + + public void preLogAudit(HttpServletRequest request) { + begin = new Date(); + MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, DashboardRestrictedBaseController.logDateFormat.format(begin)); + MDC.put(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP, DashboardRestrictedBaseController.logDateFormat.format(begin)); + MDC.put(SystemProperties.STATUS_CODE, "COMPLETE"); + //logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME); + } + + public void postLogAudit(HttpServletRequest request) { + end = new Date(); + MDC.put("AlertSeverity", "0"); + MDC.put("TargetEntity", "Health Check"); + MDC.put("TargetServiceName", "Health Check"); + MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, DashboardRestrictedBaseController.logDateFormat.format(end)); + MDC.put(SystemProperties.METRICSLOG_END_TIMESTAMP, DashboardRestrictedBaseController.logDateFormat.format(end)); + MDC.put(SystemProperties.MDC_TIMER, Long.toString((end.getTime() - begin.getTime()))); + logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI()); + logger.info(EELFLoggerDelegate.metricsLogger, request.getMethod() + request.getRequestURI()); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/InventoryController.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/InventoryController.java new file mode 100644 index 0000000..bdbf6ad --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/controller/InventoryController.java @@ -0,0 +1,984 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ + +package org.onap.ccsdk.dashboard.controller; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; +import java.util.Scanner; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.onap.ccsdk.dashboard.exceptions.inventory.BlueprintParseException; +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeAlreadyDeactivatedException; +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeNotFoundException; +import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenant; +import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenantList; +import org.onap.ccsdk.dashboard.model.CloudifyTenant; +import org.onap.ccsdk.dashboard.model.ECTransportModel; +import org.onap.ccsdk.dashboard.model.RestResponseError; +import org.onap.ccsdk.dashboard.model.RestResponsePage; +import org.onap.ccsdk.dashboard.model.inventory.Blueprint; +import org.onap.ccsdk.dashboard.model.inventory.Service; +import org.onap.ccsdk.dashboard.model.inventory.ServiceQueryParams; +import org.onap.ccsdk.dashboard.model.inventory.ServiceRefList; +import org.onap.ccsdk.dashboard.model.inventory.ServiceType; +import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeQueryParams; +import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeRequest; +import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeServiceMap; +import org.onap.ccsdk.dashboard.rest.CloudifyClient; +import org.onap.ccsdk.dashboard.rest.InventoryClient; +import org.onap.ccsdk.dashboard.util.DashboardProperties; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.AppUtils; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.slf4j.MDC; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.HttpStatusCodeException; + +import com.fasterxml.jackson.core.JsonProcessingException; + +/** + * Controller for Inventory features: services, service types, services groupby. + * Methods serve Ajax requests made by Angular scripts on pages that show + * content. + */ +@RestController +@RequestMapping("/inventory") +public class InventoryController extends DashboardRestrictedBaseController { + + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(InventoryController.class); + + /** + * Enum for selecting an item type. + */ + public enum InventoryDataItem { + SERVICES, SERVICE_TYPES, SERVICES_GROUPBY; + } + + private static Date begin, end; + private static final String SERVICES_PATH = "dcae-services"; + private static final String SERVICE_TYPES_PATH = "dcae-service-types"; + private static final String VIEW_SERVICE_TYPE_BLUEPRINT_PATH = "dcae-service-type-blueprint"; + private static final String DEPLOY_ROLE = ".k8.dev"; + private static final String DEP_IDS_FOR_TYPE = "dcae-services/typeIds"; + + /** + * ATT version with user role auth + * Gets one page of objects and supporting information via the REST client. + * On success, returns a PaginatedRestResponse object as String. + * + * @param option + * Specifies which item list type to get + * @param pageNum + * Page number of results + * @param pageSize + * Number of items per browser page + * @return JSON block as String, see above. + * @throws Exception + * On any error; e.g., Network failure. + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + private String getItemListForPageAuth(HttpServletRequest request, InventoryDataItem option, int pageNum, int pageSize, String sortBy, String searchBy) + throws Exception { + User appUser = UserUtils.getUserSession(request); + if (appUser == null || appUser.getId() == null ) + throw new Exception("getControllerRestClient: Failed to get application user"); + InventoryClient inventoryClient = getInventoryClient(appUser.getId()); + + HttpSession session = AppUtils.getSession(request); + HashMap<String, Boolean> comp_deploy_tab = (HashMap<String, Boolean>)session.getAttribute("comp_access"); + String roleLevel = (String)session.getAttribute("role_level"); + + if (roleLevel == null) { + roleLevel = "app"; + } + if (comp_deploy_tab == null) { + comp_deploy_tab = new HashMap<String, Boolean>(); + } + + Set<String> userApps = (Set<String>)session.getAttribute("authComponents"); + if (userApps == null) { + userApps = new TreeSet<String>(); + } + + List itemList = null; + List<ServiceType> filterList = new ArrayList<ServiceType>(); + List<Service> authDepList = new ArrayList<Service>(); + switch (option) { + case SERVICES: + itemList = inventoryClient.getServices().collect(Collectors.toList()); + if (roleLevel.equals("app")) { + for(String userRole : userApps) { + logger.debug(">>>> check component type from deployment: " + userRole); + for (Service cont: (List<Service>)itemList) { + String deplRef = cont.getDeploymentRef().toLowerCase(); + logger.debug(">>>> container deployment name: " + deplRef); + if (deplRef.contains(userRole)) { + logger.debug(">>>> adding deployment item to filtered subset"); + authDepList.add(cont); + } + } + } + } + + if (searchBy != null) { + if (!roleLevel.equals("app")) { + itemList = (List) itemList.stream().filter(s -> ((Service) s).contains(searchBy)).collect(Collectors.toList()); + } else { + if (!authDepList.isEmpty()) { + authDepList = (List) authDepList.stream().filter(s -> ((Service) s).contains(searchBy)).collect(Collectors.toList()); + } + } + } + if (roleLevel.equals("app")) { + logger.debug(">>>> update response with authorized content"); + itemList.clear(); + itemList.addAll(authDepList); + } + + // check for authorization to perform delete deployed blueprints + + if (!roleLevel.equals("ops")) { + for (Service bp: (List<Service>)itemList) { + String deplRef = bp.getDeploymentRef().split("_")[0].toLowerCase(); + logger.debug(">>>> deployment reference: " + deplRef); + if (comp_deploy_tab.containsKey(deplRef) ) { + boolean enableDeploy = comp_deploy_tab.get(deplRef); + logger.debug(">>>> enable deploy button: " + enableDeploy); + bp.setCanDeploy(Optional.of(enableDeploy)); + } else { + bp.setCanDeploy(Optional.of(false)); + } + } + } else { + for (Service bp: (List<Service>)itemList) { + bp.setCanDeploy(Optional.of(true)); + } + } + + if (sortBy != null) { + if (sortBy.equals("deploymentRef")) { + Collections.sort(itemList, serviceDeploymentRefComparator); + } + else if (sortBy.equals("serviceId")) { + Collections.sort(itemList, serviceIdComparator); + } + else if (sortBy.equals("created")) { + Collections.sort(itemList, serviceCreatedComparator); + } + else if (sortBy.equals("modified")) { + Collections.sort(itemList, serviceModifiedComparator); + } + } + break; + case SERVICE_TYPES: + ServiceTypeQueryParams serviceQueryParams = null; + serviceQueryParams = new ServiceTypeQueryParams.Builder().onlyLatest(false).build(); + itemList = inventoryClient.getServiceTypes(serviceQueryParams).collect(Collectors.toList()); + if (roleLevel.equals("app")) { + for(String userApp : userApps) { + logger.debug(">>>> check component type from BP: " + userApp); + for (ServiceType bp: (List<ServiceType>)itemList) { + String bpComp = bp.getComponent(); + String bpOwner = bp.getOwner(); // for backward compatibility + logger.debug(">>>> BP component name: " + bpComp); + if ( (bpComp != null && bpComp.equalsIgnoreCase(userApp)) || bpOwner.contains(userApp) ) { + logger.debug(">>>> adding item to filtered subset"); + filterList.add(bp); + } + } + } + } + if (searchBy != null) { + if (!roleLevel.equals("app")) { + itemList = (List) itemList.stream().filter(s -> ((ServiceType) s).contains(searchBy)).collect(Collectors.toList()); + } else { + if (!filterList.isEmpty()) { + filterList = (List) filterList.stream().filter(s -> ((ServiceType) s).contains(searchBy)).collect(Collectors.toList()); + } + } + } + if (roleLevel.equals("app")) { + logger.debug(">>>> update response with authorized content"); + itemList.clear(); + itemList.addAll(filterList); + } + + // check for authorization to perform update/delete/deploy blueprints + if (!roleLevel.equals("ops")) { + for (ServiceType bp: (List<ServiceType>)itemList) { + String bpComp = bp.getComponent(); + if (bpComp != null && bpComp.length() > 0) { + bpComp = bpComp.toLowerCase(); + } else { + String bpOwner = bp.getOwner(); // for backward compatibility + if (bpOwner != null && bpOwner.contains(":")) { + bpComp = bp.getOwner().split(":")[0].toLowerCase(); + } + } + logger.debug(">>>> BP component name: " + bpComp); + if (comp_deploy_tab.containsKey(bpComp) ) { + boolean enableDeploy = comp_deploy_tab.get(bpComp); + logger.debug(">>>> enable deploy button: " + enableDeploy); + bp.setCanDeploy(Optional.of(enableDeploy)); + } else { + bp.setCanDeploy(Optional.of(false)); + } + } + } else { + for (ServiceType bp: (List<ServiceType>)itemList) { + bp.setCanDeploy(Optional.of(true)); + } + } + + if (sortBy != null) { + if (sortBy.equals("owner")) { + Collections.sort(itemList, serviceTypeOwnerComparator); + } + else if (sortBy.equals("typeId")) { + Collections.sort(itemList, serviceTypeIdComparator); + } + else if (sortBy.equals("typeName")) { + Collections.sort(itemList, serviceTypeNameComparator); + } + else if (sortBy.equals("typeVersion")) { + Collections.sort(itemList, serviceTypeVersionComparator); + } + else if (sortBy.equals("created")) { + Collections.sort(itemList, serviceTypeCreatedComparator); + } + else if (sortBy.equals("application")) { + Collections.sort(itemList, serviceTypeApplComparator); + } + else if (sortBy.equals("component")) { + Collections.sort(itemList, serviceTypeCompComparator); + } + } + break; + default: + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting page of items failed!"); + throw new Exception("getItemListForPage failed: unimplemented case: " + option.name()); + } + + // Shrink if needed + final int totalItems = itemList.size(); + final int pageCount = (int) Math.ceil((double) totalItems / pageSize); + if (totalItems > pageSize) + itemList = getPageOfList(pageNum, pageSize, itemList); + + RestResponsePage<List> model = new RestResponsePage<>(totalItems, pageCount, itemList); + 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 Exception + * On any error; e.g., Network failure. + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + private String getItemListForPage(HttpServletRequest request, InventoryDataItem option, int pageNum, int pageSize, String sortBy, String searchBy) + throws Exception { + User appUser = UserUtils.getUserSession(request); + if (appUser == null || appUser.getId() == null ) + throw new Exception("getControllerRestClient: Failed to get application user"); + InventoryClient inventoryClient = getInventoryClient(appUser.getId()); + + List itemList = null; + switch (option) { + case SERVICES: + itemList = inventoryClient.getServices().collect(Collectors.toList()); + // Get the tenant names for all the deployments from Cloudify/API handler + ECTransportModel result = null; + List<CloudifyDeployedTenant> tenantList = new ArrayList<CloudifyDeployedTenant>(); + try { + CloudifyClient restClient = getCloudifyRestClient(request); + List<CloudifyTenant> cldfyTen = restClient.getTenants().items; + for (CloudifyTenant ct: (List<CloudifyTenant>)cldfyTen) { + result = restClient.getTenantInfoFromDeploy(ct.name); + tenantList.addAll(((CloudifyDeployedTenantList)result).items); + } + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting deployments failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getTenantInfoFromDeploy caught exception"); + result = new RestResponseError(e.getResponseBodyAsString()); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "Cloudify Manager"); + MDC.put("TargetServiceName", "Cloudify Manager"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting deployments failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getDeploymentById caught exception"); + result = new RestResponseError("getTenantInfoFromDeploy failed", t); + } finally { + postLogAudit(request); + } + for (Service depl: (List<Service>)itemList) { + for (CloudifyDeployedTenant deplTen: tenantList) { + if (depl.getDeploymentRef().equals(deplTen.id)) { + depl.setTenant(deplTen.tenant_name); + break; + } + } + } + if (searchBy != null) { + itemList = (List) itemList.stream().filter(s -> ((Service) s).contains(searchBy)).collect(Collectors.toList()); + } + for (Service bp: (List<Service>)itemList) { + bp.setCanDeploy(Optional.of(true)); + } + if (sortBy != null) { + if (sortBy.equals("deploymentRef")) { + Collections.sort(itemList, serviceDeploymentRefComparator); + } + else if (sortBy.equals("serviceId")) { + Collections.sort(itemList, serviceIdComparator); + } + else if (sortBy.equals("created")) { + Collections.sort(itemList, serviceCreatedComparator); + } + else if (sortBy.equals("modified")) { + Collections.sort(itemList, serviceModifiedComparator); + } + } + break; + case SERVICE_TYPES: + itemList = inventoryClient.getServiceTypes().collect(Collectors.toList()); + if (searchBy != null) { + itemList = (List) itemList.stream().filter(s -> ((ServiceType) s).contains(searchBy)).collect(Collectors.toList()); + } + for (ServiceType bp: (List<ServiceType>)itemList) { + bp.setCanDeploy(Optional.of(true)); + } + if (sortBy != null) { + if (sortBy.equals("owner")) { + Collections.sort(itemList, serviceTypeOwnerComparator); + } + else if (sortBy.equals("typeId")) { + Collections.sort(itemList, serviceTypeIdComparator); + } + else if (sortBy.equals("typeName")) { + Collections.sort(itemList, serviceTypeNameComparator); + } + else if (sortBy.equals("typeVersion")) { + Collections.sort(itemList, serviceTypeVersionComparator); + } + else if (sortBy.equals("created")) { + Collections.sort(itemList, serviceTypeCreatedComparator); + } + else if (sortBy.equals("application")) { + Collections.sort(itemList, serviceTypeApplComparator); + } + else if (sortBy.equals("component")) { + Collections.sort(itemList, serviceTypeCompComparator); + } + } + break; + default: + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting page of items failed!"); + throw new Exception("getItemListForPage failed: unimplemented case: " + option.name()); + } + + // Shrink if needed + final int totalItems = itemList.size(); + final int pageCount = (int) Math.ceil((double) totalItems / pageSize); + if (totalItems > pageSize) + itemList = getPageOfList(pageNum, pageSize, itemList); + + RestResponsePage<List> model = new RestResponsePage<>(totalItems, pageCount, itemList); + String outboundJson = objectMapper.writeValueAsString(model); + return outboundJson; + } + + /** + * Gets one page of the specified items. This method traps exceptions and + * constructs an appropriate JSON block to report errors. + * + * @param request + * Inbound request + * @param option + * Item type to get + * @return JSON with one page of objects; or an error. + */ + protected String getItemListForPageWrapper(HttpServletRequest request, InventoryDataItem option, String sortBy, String searchBy) { + preLogAudit(request); + String outboundJson = null; + try { + int pageNum = getRequestPageNumber(request); + int pageSize = getRequestPageSize(request); + String appEnv = "os"; + appEnv = getAppProperties().getPropertyDef(DashboardProperties.CONTROLLER_TYPE, "att"); + if (appEnv.equals("os")) { + outboundJson = getItemListForPage(request, option, pageNum, pageSize, sortBy, searchBy); + } else { + outboundJson = getItemListForPageAuth(request, option, pageNum, pageSize, sortBy, searchBy); + } + } catch (Exception ex) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Getting page of items failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "getItemListForPageWrapper caught exception"); + RestResponseError result = null; + if (ex instanceof HttpStatusCodeException) + result = new RestResponseError(((HttpStatusCodeException) ex).getResponseBodyAsString()); + else + result = new RestResponseError("Failed to get " + option.name(), ex); + try { + outboundJson = objectMapper.writeValueAsString(result); + } catch (JsonProcessingException jpe) { + // Should never, ever happen + outboundJson = "{ \"error\" : \"" + jpe.toString() + "\"}"; + } + } finally { + postLogAudit(request); + } + return outboundJson; + } + + /** + * Supports sorting service types by owner + */ + private static Comparator<ServiceType> serviceTypeOwnerComparator = new Comparator<ServiceType>() { + @Override + public int compare(ServiceType o1, ServiceType o2) { + return o1.getOwner().compareToIgnoreCase(o2.getOwner()); + } + }; + + /** + * Supports sorting service types by application + */ + private static Comparator<ServiceType> serviceTypeApplComparator = new Comparator<ServiceType>() { + @Override + public int compare(ServiceType o1, ServiceType o2) { + return o1.getApplication().compareToIgnoreCase(o2.getApplication()); + } + }; + + /** + * Supports sorting service types by component + */ + private static Comparator<ServiceType> serviceTypeCompComparator = new Comparator<ServiceType>() { + @Override + public int compare(ServiceType o1, ServiceType o2) { + return o1.getComponent().compareToIgnoreCase(o2.getComponent()); + } + }; + + /** + * Supports sorting service types by type id + */ + private static Comparator<ServiceType> serviceTypeIdComparator = new Comparator<ServiceType>() { + @Override + public int compare(ServiceType o1, ServiceType o2) { + return o1.getTypeId().get().compareToIgnoreCase(o2.getTypeId().get()); + } + }; + + /** + * Supports sorting service types by type name + */ + private static Comparator<ServiceType> serviceTypeNameComparator = new Comparator<ServiceType>() { + @Override + public int compare(ServiceType o1, ServiceType o2) { + return o1.getTypeName().compareToIgnoreCase(o2.getTypeName()); + } + }; + + /** + * Supports sorting service types by type version + */ + private static Comparator<ServiceType> serviceTypeVersionComparator = new Comparator<ServiceType>() { + @Override + public int compare(ServiceType o1, ServiceType o2) { + return o1.getTypeVersion().compareTo(o2.getTypeVersion()); + } + }; + + /** + * Supports sorting service types by created date + */ + private static Comparator<ServiceType> serviceTypeCreatedComparator = new Comparator<ServiceType>() { + @Override + public int compare(ServiceType o1, ServiceType o2) { + return o1.getCreated().get().compareToIgnoreCase(o2.getCreated().get()); + } + }; + + /** + * Supports sorting services by deploymentRef + */ + private static Comparator<Service> serviceDeploymentRefComparator = new Comparator<Service>() { + @Override + public int compare(Service o1, Service o2) { + return o1.getDeploymentRef().compareToIgnoreCase(o2.getDeploymentRef()); + } + }; + + /** + * Supports sorting services by service id + */ + private static Comparator<Service> serviceIdComparator = new Comparator<Service>() { + @Override + public int compare(Service o1, Service o2) { + return o1.getServiceId().compareToIgnoreCase(o2.getServiceId()); + } + }; + + /** + * Supports sorting services by created date + */ + private static Comparator<Service> serviceCreatedComparator = new Comparator<Service>() { + @Override + public int compare(Service o1, Service o2) { + return o1.getCreated().compareToIgnoreCase(o2.getCreated()); + } + }; + + /** + * Supports sorting services by created date + */ + private static Comparator<Service> serviceModifiedComparator = new Comparator<Service>() { + @Override + public int compare(Service o1, Service o2) { + return o1.getModified().compareToIgnoreCase(o2.getModified()); + } + }; + + /** + * Serves one page of service types + * + * @param request + * HttpServletRequest + * @return List of ServiceTypes objects + */ + @RequestMapping(value = { SERVICE_TYPES_PATH }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getServiceTypesByPage(HttpServletRequest request) { + preLogAudit(request); + String json = null; + //json = getMockDataContent("/serviceTypesList.json"); + json = + getItemListForPageWrapper(request, InventoryDataItem.SERVICE_TYPES, request.getParameter("sortBy"), request.getParameter("searchBy")); + postLogAudit(request); + return json; + } + + + private String getMockDataContent(final String path) { + String result = null; + try { + InputStream is = getClass().getResourceAsStream(path); + if (is == null) + throw new Exception("Failed to find resource at path " + path); + Scanner scanner = new Scanner(is, "UTF-8"); + result = scanner.useDelimiter("\\A").next(); + scanner.close(); + is.close(); + } catch (Exception ex) { + logger.error("getMockDataContent failed", ex); + throw new RuntimeException(ex); + } + return result; + } + + /** + * Query Service objects matching a service type ID + * + */ + @RequestMapping(value = { DEP_IDS_FOR_TYPE }, method = RequestMethod.POST, produces = "application/json") + public String getServicesForType( HttpServletRequest request, + @RequestBody String[] typeList) + throws Exception { + preLogAudit(request); + User appUser = UserUtils.getUserSession(request); + if (appUser == null || appUser.getId() == null ) + throw new Exception("getControllerRestClient: Failed to get application user"); + InventoryClient inventoryClient = getInventoryClient(appUser.getId()); + List<ServiceTypeServiceMap> result = new ArrayList<ServiceTypeServiceMap>(); + for (String typeId: typeList) { + ServiceQueryParams qryParams = new ServiceQueryParams.Builder().typeId(typeId).build(); + ServiceRefList srvcRefs = inventoryClient.getServicesForType(qryParams); + ServiceTypeServiceMap srvcMap = new ServiceTypeServiceMap(typeId, srvcRefs); + result.add(srvcMap); + } + return objectMapper.writeValueAsString(result); + } + + /** + * Serves one page of services + * + * @param request + * HttpServletRequest + * + * @return List of Service objects + */ + @RequestMapping(value = { SERVICES_PATH }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public String getServicesByPage(HttpServletRequest request) { + //preLogAudit(request); + String json = null; + json = getItemListForPageWrapper(request, InventoryDataItem.SERVICES, request.getParameter("sortBy"), request.getParameter("searchBy")); + postLogAudit(request); + return json; + } + /** + * Gets the specified blueprint content for viewing. + * + * @param id + * Blueprint ID + * @param request + * HttpServletRequest + * @return Blueprint as YAML; or error. + * @throws Exception + * on serialization error + * + */ + @RequestMapping(value = { + VIEW_SERVICE_TYPE_BLUEPRINT_PATH + "/{typeid}" }, method = RequestMethod.GET, produces = "application/yaml") + @ResponseBody + public String viewServiceTypeBlueprintContentById(@PathVariable("typeid") String typeId, HttpServletRequest request) throws Exception { + preLogAudit(request); + String json = null; + try { + InventoryClient inventoryClient = getInventoryClient(request); + json = objectMapper.writeValueAsString(inventoryClient.getServiceType(typeId).get()); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Viewing service type " + typeId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "viewServiceTypeBlueprintContentById caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getResponseBodyAsString())); + } catch (JsonProcessingException jpe) { + // Should never, ever happen + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Viewing service type " + typeId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "viewServiceTypeBlueprintContentById caught exception"); + json = "{ \"error\" : \"" + jpe.toString() + "\"}"; + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Viewing service type " + typeId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "viewServiceTypeBlueprintContentById caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("getBlueprintContentById failed", t)); + } finally { + postLogAudit(request); + } + return json; + } + + /** + * Deletes the specified blueprint. + * + * @param id + * Blueprint ID + * @param request + * HttpServletRequest + * @param response + * HttpServletResponse + * @return status code on success; error on failure. + * @throws Exception + * On serialization failure + */ + @RequestMapping(value = { SERVICE_TYPES_PATH + "/{typeid}" }, method = RequestMethod.DELETE, produces = "application/json") + @ResponseBody + public String deleteServiceType(@PathVariable("typeid") String typeid, HttpServletRequest request, + HttpServletResponse response) throws Exception { + preLogAudit(request); + String json = "{\"202\": \"OK\"}"; + try { + InventoryClient inventoryClient = getInventoryClient(request); + inventoryClient.deleteServiceType(typeid); + } catch (ServiceTypeNotFoundException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting service type " + typeid + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteServiceType caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (ServiceTypeAlreadyDeactivatedException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting service type " + typeid + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteServiceType caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting service type " + typeid + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteServiceType caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("deleteDeployment failed", t)); + } finally { + postLogAudit(request); + } + return json; + } + + /** + * Deletes the specified service i.e. deployment from inventory + * + * @param id + * Service ID + * @param request + * HttpServletRequest + * @param response + * HttpServletResponse + * @return status code on success; error on failure. + * @throws Exception + * On serialization failure + */ + @RequestMapping(value = { SERVICES_PATH + "/{serviceId}" }, method = RequestMethod.DELETE, produces = "application/json") + @ResponseBody + public String deleteService(@PathVariable("serviceId") String serviceId, HttpServletRequest request, + HttpServletResponse response) throws Exception { + preLogAudit(request); + String json = "{\"202\": \"OK\"}"; + try { + InventoryClient inventoryClient = getInventoryClient(request); + inventoryClient.deleteService(serviceId); + } catch (ServiceTypeNotFoundException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting service " + serviceId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteServiceType caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (ServiceTypeAlreadyDeactivatedException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting service " + serviceId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteServiceType caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getMessage())); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Deleting service " + serviceId + " failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "deleteServiceType caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("deleteDeployment failed", t)); + } finally { + postLogAudit(request); + } + return json; + } + + /** + * Processes request to update a blueprint currently existing in DCAE Inventory. + * + * @param request + * HttpServletRequest + * @param blueprint + * Cloudify blueprint + * @return Blueprint as uploaded; or error. + * @throws Exception + * on serialization error + */ + @RequestMapping(value = { SERVICE_TYPES_PATH + "/update"}, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public String updateServiceTypeBlueprint(HttpServletRequest request, @RequestBody ServiceType serviceType) + throws Exception { + preLogAudit(request); + String json = "{\"201\": \"OK\"}"; + try { + // Verify that the Service Type can be parsed for inputs. + Blueprint.parse(serviceType.getBlueprintTemplate()); + InventoryClient inventoryClient = getInventoryClient(request); + inventoryClient.addServiceType(serviceType); + } catch (BlueprintParseException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Updating service type failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "updateServiceTypeBlueprint caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("Invalid blueprint format.", e)); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Updating service type failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "updateServiceTypeBlueprint caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getResponseBodyAsString())); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Updating service type failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "updateServiceTypeBlueprint caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("updateServiceTypeBlueprint failed", t)); + } finally { + postLogAudit(request); + } + return json; + } + + /** + * Processes request to update a blueprint currently existing in DCAE Inventory. + * + * @param request + * HttpServletRequest + * @param blueprint + * Cloudify blueprint + * @return Blueprint as uploaded; or error. + * @throws Exception + * on serialization error + */ + @RequestMapping(value = { SERVICE_TYPES_PATH + "/upload" }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public String uploadServiceTypeBlueprint(HttpServletRequest request, + @RequestBody ServiceTypeRequest serviceTypeRequest) + throws Exception { + preLogAudit(request); + String json = "{\"201\": \"OK\"}"; + try { + Blueprint.parse(serviceTypeRequest.getBlueprintTemplate()); + InventoryClient inventoryClient = getInventoryClient(request); + inventoryClient.addServiceType(serviceTypeRequest); + } catch (BlueprintParseException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Updating service type failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "updateServiceTypeBlueprint caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("Invalid blueprint format.", e)); + } catch (HttpStatusCodeException e) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Updating service type failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "updateServiceTypeBlueprint caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError(e.getResponseBodyAsString())); + } catch (Throwable t) { + MDC.put(SystemProperties.STATUS_CODE, "ERROR"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put("ErrorCode", "300"); + MDC.put("ErrorCategory", "ERROR"); + MDC.put("ErrorDescription", "Updating service type failed!"); + logger.error(EELFLoggerDelegate.errorLogger, "updateServiceTypeBlueprint caught exception"); + json = objectMapper.writeValueAsString(new RestResponseError("updateServiceTypeBlueprint failed", t)); + } finally { + postLogAudit(request); + } + return json; + } + + public void preLogAudit(HttpServletRequest request) { + begin = new Date(); + MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, logDateFormat.format(begin)); + MDC.put(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP, logDateFormat.format(begin)); + MDC.put(SystemProperties.STATUS_CODE, "COMPLETE"); + //logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, APP_NAME); + } + + public void postLogAudit(HttpServletRequest request) { + end = new Date(); + MDC.put("AlertSeverity", "0"); + MDC.put("TargetEntity", "DCAE Inventory"); + MDC.put("TargetServiceName", "DCAE Inventory"); + MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, logDateFormat.format(end)); + MDC.put(SystemProperties.METRICSLOG_END_TIMESTAMP, logDateFormat.format(end)); + MDC.put(SystemProperties.MDC_TIMER, Long.toString((end.getTime() - begin.getTime()))); + logger.info(EELFLoggerDelegate.auditLogger, request.getMethod() + request.getRequestURI()); + logger.info(EELFLoggerDelegate.metricsLogger, request.getMethod() + request.getRequestURI()); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/domain/ControllerEndpoint.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/domain/ControllerEndpoint.java index 397f2ed..2905dca 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/domain/ControllerEndpoint.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/domain/ControllerEndpoint.java @@ -1,71 +1,91 @@ -/*******************************************************************************
- * =============LICENSE_START=========================================================
- *
- * =================================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *******************************************************************************/
-package org.onap.ccsdk.dashboard.domain;
-
-import org.onap.portalsdk.core.domain.support.DomainVo;
-
-/**
- * Model for controller endpoint information stored in database. A single row
- * for a user represents a selected endpoint.
- */
-public class ControllerEndpoint extends DomainVo {
-
- private static final long serialVersionUID = 8785223545128054402L;
-
- private long userId;
- private String name;
- private String url;
-
- public ControllerEndpoint() {
- }
-
- public ControllerEndpoint(long userId, String name, String url) {
- this.userId = userId;
- this.name = name;
- this.url = url;
- }
-
- public long getUserId() {
- return userId;
- }
-
- public void setUserId(long userId) {
- this.userId = userId;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
-}
+/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ + +package org.onap.ccsdk.dashboard.domain; + +import org.onap.portalsdk.core.domain.support.DomainVo; + +/** + * Model for controller endpoint information stored in database. A single row + * for a user represents a selected endpoint. + */ +public class ControllerEndpoint extends DomainVo { + + private static final long serialVersionUID = 8785223545128054402L; + + private long userId; + private String name; + private String url; + private String inventoryUrl; + private String dhandlerUrl; + + public ControllerEndpoint() { + } + + public ControllerEndpoint(long userId, String name, String url, String inventoryUrl, String dhandlerUrl) { + this.userId = userId; + this.name = name; + this.url = url; + this.inventoryUrl = inventoryUrl; + this.dhandlerUrl = dhandlerUrl; + } + + public long getUserId() { + return userId; + } + + public void setUserId(long userId) { + this.userId = userId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getInventoryUrl() { + return inventoryUrl; + } + + public void setInventoryUrl(String inventoryUrl) { + this.inventoryUrl = inventoryUrl; + } + + public String getDhandlerUrl() { + return dhandlerUrl; + } + + public void setDhandlerUrl(String dhandlerUrl) { + this.dhandlerUrl = dhandlerUrl; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/domain/EcdComponent.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/domain/EcdComponent.java new file mode 100644 index 0000000..719ad23 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/domain/EcdComponent.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ + +package org.onap.ccsdk.dashboard.domain; + +import org.apache.commons.lang3.StringUtils; +import org.onap.portalsdk.core.domain.support.DomainVo; + +public class EcdComponent extends DomainVo { + + private static final long serialVersionUID = 1L; + + private Long compId; + private String cname; // component name + private String dname; // component display name + public Long getCompId() { + return compId; + } + public void setCompId(Long compId) { + this.compId = compId; + } + public String getCname() { + return cname; + } + public void setCname(String cname) { + this.cname = cname; + } + public String getDname() { + return dname; + } + public void setDname(String dname) { + this.dname = dname; + } + + public boolean contains(String searchString) { + if (StringUtils.containsIgnoreCase(this.getCname(), searchString) || + StringUtils.containsIgnoreCase(this.getDname(), searchString)) { + return true; + } + return false; + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exception/DashboardControllerException.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exception/DashboardControllerException.java deleted file mode 100644 index f288741..0000000 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exception/DashboardControllerException.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.onap.ccsdk.dashboard.exception; - -/** - * A little something to placate the Sonar code-analysis tool. - */ -public class DashboardControllerException extends Exception { - - private static final long serialVersionUID = -1373841666122351816L; - - public DashboardControllerException() { - super(); - } - - public DashboardControllerException(String message) { - super(message); - } - - public DashboardControllerException(String message, Throwable cause) { - super(message, cause); - } - - public DashboardControllerException(Throwable cause) { - super(cause); - } - -} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/BadRequestException.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/BadRequestException.java new file mode 100644 index 0000000..bd75bac --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/BadRequestException.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ + +package org.onap.ccsdk.dashboard.exceptions; + +public class BadRequestException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -8654510668910559419L; + + public BadRequestException (String message) { + super(message); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/DashboardControllerException.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/DashboardControllerException.java new file mode 100644 index 0000000..c1de4fe --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/DashboardControllerException.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.exceptions; + +/** + * A little something to placate the Sonar code-analysis tool. + */ +public class DashboardControllerException extends Exception { + + private static final long serialVersionUID = -1373841666122351816L; + + public DashboardControllerException() { + super(); + } + + public DashboardControllerException(String message) { + super(message); + } + + public DashboardControllerException(String message, Throwable cause) { + super(message, cause); + } + + public DashboardControllerException(Throwable cause) { + super(cause); + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/DeploymentNotFoundException.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/DeploymentNotFoundException.java new file mode 100644 index 0000000..4785823 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/DeploymentNotFoundException.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ + +package org.onap.ccsdk.dashboard.exceptions; + +public class DeploymentNotFoundException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -5983803277201006988L; + + public DeploymentNotFoundException (String message) { + super(message); + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/DownstreamException.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/DownstreamException.java new file mode 100644 index 0000000..72a6dbe --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/DownstreamException.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.exceptions; + +public class DownstreamException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 142869535142369337L; + + public DownstreamException (String message) { + super(message); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/ServerErrorException.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/ServerErrorException.java new file mode 100644 index 0000000..f87dc3e --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/ServerErrorException.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.exceptions; + +public class ServerErrorException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 8366380783861251332L; + + public ServerErrorException(String message) { + super(message); + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/ServiceAlreadyExistsException.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/ServiceAlreadyExistsException.java new file mode 100644 index 0000000..117d506 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/ServiceAlreadyExistsException.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.exceptions; + +public class ServiceAlreadyExistsException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -4696234983451006280L; + + public ServiceAlreadyExistsException (String message) { + super(message); + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/BlueprintParseException.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/BlueprintParseException.java new file mode 100644 index 0000000..2e7f5fe --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/BlueprintParseException.java @@ -0,0 +1,10 @@ +package org.onap.ccsdk.dashboard.exceptions.inventory; + +public class BlueprintParseException extends Exception { + + private static final long serialVersionUID = -6334355506595623685L; + + public BlueprintParseException(Throwable cause) { + super(cause); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceAlreadyDeactivatedException.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceAlreadyDeactivatedException.java new file mode 100644 index 0000000..1b0e2d8 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceAlreadyDeactivatedException.java @@ -0,0 +1,13 @@ +package org.onap.ccsdk.dashboard.exceptions.inventory; + +public class ServiceAlreadyDeactivatedException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 7268552618026889672L; + + public ServiceAlreadyDeactivatedException (String message) { + super(message); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceNotFoundException.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceNotFoundException.java new file mode 100644 index 0000000..de4a549 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceNotFoundException.java @@ -0,0 +1,9 @@ +package org.onap.ccsdk.dashboard.exceptions.inventory; + +public class ServiceNotFoundException extends Exception { + + private static final long serialVersionUID = -8183806298586822720L; + + public ServiceNotFoundException() { super(); } + public ServiceNotFoundException (String message) { super(message); } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeActiveException.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeActiveException.java new file mode 100644 index 0000000..ce799f5 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeActiveException.java @@ -0,0 +1,11 @@ +package org.onap.ccsdk.dashboard.exceptions.inventory; + +public class ServiceTypeActiveException extends Exception { + + private static final long serialVersionUID = 7403567744784579153L; + + public ServiceTypeActiveException() { super(); } + public ServiceTypeActiveException(String msg) { super(msg); } + public ServiceTypeActiveException(Throwable cause) { super(cause); } + public ServiceTypeActiveException(String msg, Throwable cause) { super(msg, cause); } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeAlreadyDeactivatedException.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeAlreadyDeactivatedException.java new file mode 100644 index 0000000..e7d1f8c --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeAlreadyDeactivatedException.java @@ -0,0 +1,13 @@ +package org.onap.ccsdk.dashboard.exceptions.inventory; + +public class ServiceTypeAlreadyDeactivatedException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -4359544421618429774L; + + public ServiceTypeAlreadyDeactivatedException (String message) { + super(message); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeAlreadyExistsException.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeAlreadyExistsException.java new file mode 100644 index 0000000..806d127 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeAlreadyExistsException.java @@ -0,0 +1,11 @@ +package org.onap.ccsdk.dashboard.exceptions.inventory; + +public class ServiceTypeAlreadyExistsException extends Exception { + + private static final long serialVersionUID = 8146558049192514157L; + + public ServiceTypeAlreadyExistsException() { super(); } + public ServiceTypeAlreadyExistsException(String msg) { super(msg); } + public ServiceTypeAlreadyExistsException(Throwable cause) { super(cause); } + public ServiceTypeAlreadyExistsException(String msg, Throwable cause) { super(msg, cause); } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeNotFoundException.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeNotFoundException.java new file mode 100644 index 0000000..54cffcf --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeNotFoundException.java @@ -0,0 +1,12 @@ +package org.onap.ccsdk.dashboard.exceptions.inventory; + +public class ServiceTypeNotFoundException extends Exception { + + private static final long serialVersionUID = 1218738334353236154L; + + public ServiceTypeNotFoundException() { super(); } + + public ServiceTypeNotFoundException (String message) { + super(message); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprint.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprint.java index f66a072..47503f8 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprint.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprint.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprintContent.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprintContent.java index 6b95eaa..2c64efe 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprintContent.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprintContent.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprintList.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprintList.java index a9a98a1..114a823 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprintList.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprintList.java @@ -1,8 +1,9 @@ + /******************************************************************************* * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprintUpload.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprintUpload.java index 70e093b..d7cf0d3 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprintUpload.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprintUpload.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeployedTenant.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeployedTenant.java new file mode 100644 index 0000000..f8b13e0 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeployedTenant.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CloudifyDeployedTenant extends ECTransportModel { + + /** A unique identifier for the deployment. */ + public final String id; + /** tenant where the deployment was done */ + public final String tenant_name; + /** The id of the blueprint the deployment is based on. */ + public final String blueprint_id; + + @JsonCreator + public CloudifyDeployedTenant(@JsonProperty("id") String id, + @JsonProperty("blueprint_id") String blueprint_id, + @JsonProperty("tenant_name") String tenant_name) { + this.id = id; + this.blueprint_id = blueprint_id; + this.tenant_name = tenant_name; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeployedTenantList.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeployedTenantList.java new file mode 100644 index 0000000..8c6a39d --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeployedTenantList.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CloudifyDeployedTenantList extends ECTransportModel { + public final List<CloudifyDeployedTenant> items; + public final Metadata metadata; + + @JsonCreator + public CloudifyDeployedTenantList(@JsonProperty("items") List<CloudifyDeployedTenant> items, @JsonProperty("metadata") Metadata metadata){ + this.items = items; + this.metadata = metadata; + } + + public static final class Metadata { + public final Pagination pagination; + + @JsonCreator + public Metadata(@JsonProperty("pagination") Pagination pagination){ + this.pagination = pagination; + } + + public static final class Pagination { + public final long total; + public final long offset; + public final long size; + + @JsonCreator + public Pagination(@JsonProperty("total") long total, @JsonProperty("offset") long offset, @JsonProperty("size") long size){ + this.total = total; + this.offset = offset; + this.size = size; + } + } + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeployment.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeployment.java index 126fe9c..4e07c1f 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeployment.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeployment.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ public final class CloudifyDeployment extends ECTransportModel { * A dictionary containing key value pairs which represents a deployment * input and its provided value. */ - public final Inputs inputs; + public final Map<String, Object> inputs; /** A dictionary containing policies of a deployment. */ public final Map<String, Object> policy_types; /** A dictionary containing policy triggers of a deployment. */ @@ -60,15 +60,17 @@ public final class CloudifyDeployment extends ECTransportModel { /** A list of workflows that can be executed on a deployment. */ public final List<Workflow> workflows; + public final String tenant_name; + @JsonCreator public CloudifyDeployment(@JsonProperty("description") String description, @JsonProperty("blueprint_id") String blueprint_id, @JsonProperty("created_at") String created_at, @JsonProperty("updated_at") String updated_at, @JsonProperty("id") String id, - @JsonProperty("inputs") Inputs inputs, @JsonProperty("policy_types") Map<String, Object> policy_types, + @JsonProperty("inputs") Map<String, Object> inputs, @JsonProperty("policy_types") Map<String, Object> policy_types, @JsonProperty("policy_triggers") Map<String, Object> policy_triggers, @JsonProperty("outputs") Map<String, Object> outputs, @JsonProperty("groups") Map<String, Object> groups, @JsonProperty("scaling_groups") Map<String, Object> scaling_groups, - @JsonProperty("workflows") List<Workflow> workflows) { + @JsonProperty("workflows") List<Workflow> workflows, @JsonProperty("tenant_name") String tenant_name) { this.description = description; this.blueprint_id = blueprint_id; this.created_at = created_at; @@ -81,6 +83,7 @@ public final class CloudifyDeployment extends ECTransportModel { this.groups = groups; this.scaling_groups = scaling_groups; this.workflows = workflows; + this.tenant_name = tenant_name; } public static final class Inputs { diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentList.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentList.java index 51b6169..4a26767 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentList.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentList.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentRequest.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentRequest.java index 32c7199..92c7ec3 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentRequest.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentRequest.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentUpdateRequest.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentUpdateRequest.java new file mode 100644 index 0000000..cecece3 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentUpdateRequest.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model for message POST-ed to controller to update a Cloudify Deployment: + * + * NOTE: THIS IS NOT HOW THE REQUEST TO CLOUDIFY'S ENDPOINT LOOKS. THE REQUEST IS CONSTRUCTED IN PROPER FORMAT IN THE API HANDLER + * <pre> + * { + "deployment_id" : "deployment-id", + "workflow_name" : "workflow-name", + "allow_custom_parameter" : "true|false", + "force" : "true|false", + "node_instance_id": "node-instance-id", + "limits_cpu": limits_cpu, + "limits_mem": limits_mem, + "image": "image", + "replicas": replicas, + "container_name": "container_name" + } + * </pre> + */ +public final class CloudifyDeploymentUpdateRequest extends ECTransportModel { + + /** A unique identifier for the deployment. */ + public final String deployment_id; + /** A unique identifier for the workflow */ + public final String workflow_name; + public final Boolean allow_custom_parameter; + public final Boolean force; + /** Parameters: retrieve using the GET /deployments */ + //public final Map<String, Object> parameters; + public final String node_instance_id; + public final String limits_cpu; + public final String limits_mem; + public final String image; + public final Number replicas; + public final String container_name; + + @JsonCreator + public CloudifyDeploymentUpdateRequest(@JsonProperty("deployment_id") String deployment_id, + @JsonProperty("workflow_name") String workflow_name, + @JsonProperty("allow_custom_parameter") Boolean allowCustomParameter, + @JsonProperty("force") Boolean force, + @JsonProperty("node_instance_id") String node_instance_id, + @JsonProperty("limits_cpu") String limits_cpu, + @JsonProperty("limits_mem") String limits_mem, + @JsonProperty("image") String image, + @JsonProperty("replicas") Number replicas, + @JsonProperty("container_name") String container_name) { + + this.deployment_id = deployment_id; + this.workflow_name = workflow_name; + this.allow_custom_parameter = allowCustomParameter; + this.force = force; + //this.parameters = parameters; + this.node_instance_id = node_instance_id; + this.limits_cpu = limits_cpu; + this.limits_mem = limits_mem; + this.image = image; + this.replicas = replicas; + this.container_name = container_name; + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentUpdateResponse.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentUpdateResponse.java new file mode 100644 index 0000000..19134a4 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentUpdateResponse.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model with fields only for the top-level attributes. All complex child + * structures are represented simply as generic collections. + */ +public final class CloudifyDeploymentUpdateResponse extends ECTransportModel { + + /** A unique identifier for the execution. */ + public final String id; + /** The executions status. */ + public final String status; + /** The time the execution was queued at. */ + public final String created_at; + /** The id/name of the workflow the execution is of. */ + public final String workflow_id; + /** true if the execution is of a system workflow. */ + public final Boolean is_system_workflow; + /** The id of the blueprint the execution is in the context of. */ + public final String blueprint_id; + /** The id of the deployment the execution is in the context of. */ + public final String deployment_id; + /** The execution’s error message on execution failure. */ + public final String error; + /** A dict of the workflow parameters passed when starting the execution. */ + public final Map<String, Object> parameters; + + public final String tenant_name; + + public final String created_by; + + public final Boolean private_resource; + + public final String resource_availability; + + + @JsonCreator + public CloudifyDeploymentUpdateResponse(@JsonProperty("status") String status, + @JsonProperty("created_at") String created_at, + @JsonProperty("workflow_id") String workflow_id, + @JsonProperty("is_system_workflow") Boolean is_system_workflow, + @JsonProperty("blueprint_id") String blueprint_id, + @JsonProperty("deployment_id") String deployment_id, + @JsonProperty("error") String error, + @JsonProperty("id") String id, + @JsonProperty("parameters") Map<String, Object> parameters, + @JsonProperty("tenant_name") String tenant_name, + @JsonProperty("created_by") String created_by, + @JsonProperty("private_resource") Boolean private_resource, + @JsonProperty("resource_availability") String resource_availability) { + + this.status = status; + this.created_at = created_at; + this.workflow_id = workflow_id; + this.is_system_workflow = is_system_workflow; + this.blueprint_id = blueprint_id; + this.deployment_id = deployment_id; + this.error = error; + this.id = id; + this.parameters = parameters; + this.tenant_name = tenant_name; + this.created_by = created_by; + this.private_resource = private_resource; + this.resource_availability = resource_availability; + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentUpgradeRequest.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentUpgradeRequest.java new file mode 100644 index 0000000..3f3a8fa --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentUpgradeRequest.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model for message POST-ed to controller to execute upgrade workflow on a Cloudify Deployment: + * + * NOTE: THIS IS NOT HOW THE REQUEST TO CLOUDIFY'S ENDPOINT LOOKS. THE REQUEST IS CONSTRUCTED IN PROPER FORMAT IN THE API HANDLER + * <pre> +* { + "config_url": config_url, + "config_format": config_format, + "chartRepo": chartRepo, + "chartVersion": chartVersion + }; + * </pre> + */ +public final class CloudifyDeploymentUpgradeRequest extends ECTransportModel { + + public final String config_url; + public final String config_format; + public final String chartRepo; + public final String chartVersion; + + @JsonCreator + public CloudifyDeploymentUpgradeRequest( + @JsonProperty("config_url") String config_url, + @JsonProperty("config_format") String config_format, + @JsonProperty("chartRepo") String chartRepo, + @JsonProperty("chartVersion") String chartVersion) { + + this.config_url = config_url; + this.config_format = config_format; + this.chartRepo = chartRepo; + this.chartVersion = chartVersion; + } + + public String getConfig_url() { + return config_url; + } + + public String getConfig_format() { + return config_format; + } + + public String getChartRepo() { + return chartRepo; + } + + public String getChartVersion() { + return chartVersion; + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyErrorCause.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyErrorCause.java new file mode 100644 index 0000000..468b62d --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyErrorCause.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CloudifyErrorCause extends ECTransportModel { + + /** Error message */ + public final String message; + + /** Stack trace at the point where the exception was raised */ + public final String traceback; + + /** Exception type */ + public final String type; + + @JsonCreator + public CloudifyErrorCause( + @JsonProperty("message") String message, + @JsonProperty("traceback") String traceback, + @JsonProperty("type") String type) { + + this.message = message; + this.traceback = traceback; + this.type = type; + } + + @Override + public String toString() { + return "CloudifyErrorCause [message=" + message + ", traceback=" + traceback + ", type=" + type + "]"; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyEvent.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyEvent.java new file mode 100644 index 0000000..4910f9f --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyEvent.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import java.util.LinkedList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CloudifyEvent extends ECTransportModel { + + /** The id of the blueprint the execution is in the context of. */ + public final String blueprint_id; + /** The id of the deployment the execution is in the context of. */ + public final String deployment_id; + /** List of errors that happened while executing a given task */ + public final List<CloudifyErrorCause> error_causes; + /** The executions status. */ + public final String event_type; + /** The time the execution was queued at. */ + public final String execution_id; + /** log level */ + public final String level; + /** logger id */ + public final String logger; + /** message text */ + public final String message; + /** node instance id */ + public final String node_instance_id; + /** node name */ + public final String node_name; + /** Operation path */ + public final String operation; + /** time at which the event occurred on the executing machine */ + public final String reported_timestamp; + /** time at which the event was logged on the management machine */ + public final String timestamp; + /** resource is a cloudify_event or a cloudify_log */ + public final String type; + /** The id/name of the workflow the execution is of. */ + public final String workflow_id; + + @JsonCreator + public CloudifyEvent( + @JsonProperty("blueprint_id") String blueprint_id, + @JsonProperty("deployment_id") String deployment_id, + @JsonProperty("error_causes") List<CloudifyErrorCause> error_causes, + @JsonProperty("event_type") String event_type, + @JsonProperty("execution_id") String execution_id, + @JsonProperty("level") String level, + @JsonProperty("logger") String logger, + @JsonProperty("message") String message, + @JsonProperty("node_instance_id") String node_instance_id, + @JsonProperty("node_name") String node_name, + @JsonProperty("operation") String operation, + @JsonProperty("reported_timestamp") String reported_timestamp, + @JsonProperty("timestamp") String timestamp, + @JsonProperty("type") String type, + @JsonProperty("workflow_id") String workflow_id) { + + this.blueprint_id = blueprint_id; + this.deployment_id = deployment_id; + this.error_causes = (error_causes == null) ? new LinkedList<CloudifyErrorCause> () : error_causes; + this.event_type = event_type; + this.execution_id = execution_id; + this.level = level; + this.logger = logger; + this.message = message; + this.node_instance_id = node_instance_id; + this.node_name = node_name; + this.operation = operation; + this.reported_timestamp = reported_timestamp; + this.timestamp = timestamp; + this.type = type; + this.workflow_id = workflow_id; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyEventList.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyEventList.java new file mode 100644 index 0000000..d633faa --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyEventList.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CloudifyEventList extends ECTransportModel { + + public final List<CloudifyEvent> items; + public final Metadata metadata; + + @JsonCreator + public CloudifyEventList(@JsonProperty("items") List<CloudifyEvent> items, @JsonProperty("metadata") Metadata metadata){ + this.items = items; + this.metadata = metadata; + } + + public static final class Metadata { + public final Pagination pagination; + + @JsonCreator + public Metadata(@JsonProperty("pagination") Pagination pagination){ + this.pagination = pagination; + } + + public static final class Pagination { + public final long total; + public final long offset; + public final long size; + + @JsonCreator + public Pagination(@JsonProperty("total") long total, @JsonProperty("offset") long offset, @JsonProperty("size") long size){ + this.total = total; + this.offset = offset; + this.size = size; + } + } + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyExecution.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyExecution.java index 071ef57..e701528 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyExecution.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyExecution.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,18 +46,28 @@ public final class CloudifyExecution extends ECTransportModel { public final String blueprint_id; /** The id of the deployment the execution is in the context of. */ public final String deployment_id; + /** The tenant used to deploy */ + public final String tenant_name; /** The execution’s error message on execution failure. */ public final String error; /** A dict of the workflow parameters passed when starting the execution. */ public final Map<String, Object> parameters; + /** true if helm plugin is used */ + public Boolean is_helm; + /** true if helm status is enabled */ + public Boolean helm_status; @JsonCreator public CloudifyExecution(@JsonProperty("status") String status, @JsonProperty("created_at") String created_at, @JsonProperty("workflow_id") String workflow_id, @JsonProperty("is_system_workflow") Boolean is_system_workflow, - @JsonProperty("blueprint_id") String blueprint_id, @JsonProperty("deployment_id") String deployment_id, + @JsonProperty("blueprint_id") String blueprint_id, + @JsonProperty("deployment_id") String deployment_id, + @JsonProperty("tenant_name") String tenant_name, @JsonProperty("error") String error, @JsonProperty("id") String id, - @JsonProperty("parameters") Map<String, Object> parameters) { + @JsonProperty("parameters") Map<String, Object> parameters, + @JsonProperty("is_helm") Boolean is_helm, + @JsonProperty("helm_status") Boolean helm_status) { this.status = status; this.created_at = created_at; @@ -65,9 +75,12 @@ public final class CloudifyExecution extends ECTransportModel { this.is_system_workflow = is_system_workflow; this.blueprint_id = blueprint_id; this.deployment_id = deployment_id; + this.tenant_name = tenant_name; this.error = error; this.id = id; this.parameters = parameters; + this.is_helm = is_helm; + this.helm_status = helm_status; } } diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyExecutionList.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyExecutionList.java index 5909c62..e493c70 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyExecutionList.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyExecutionList.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyExecutionRequest.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyExecutionRequest.java index d787fec..c333faf 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyExecutionRequest.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyExecutionRequest.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,42 +26,78 @@ import java.util.Map; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -/** - * Model for message POST-ed to controller to create a Cloudify Execution: - * - * <pre> - * { - "deployment_id" : "deployment-id", - "workflow_name" : "workflow-name", - "allow_custom_parameter" : "true|false", - "force" : "true|false", - "parameters": - { - - } - } - * </pre> - */ -public final class CloudifyExecutionRequest extends ECTransportModel { +public class CloudifyExecutionRequest extends ECTransportModel { /** A unique identifier for the deployment. */ - public final String deployment_id; + public String deployment_id; /** A unique identifier for the workflow */ - public final String workflow_name; - public final Boolean allow_custom_parameter; - public final Boolean force; + public String workflow_id; + public Boolean allow_custom_parameters; + public Boolean force; + public String tenant; /** Parameters: retrieve using the GET /deployments */ - public final Map<String, Object> parameters; + public Map<String, Object> parameters; + + public String getDeployment_id() { + return deployment_id; + } + + public String getWorkflow_id() { + return workflow_id; + } + + public Boolean getAllow_custom_parameters() { + return allow_custom_parameters; + } + + public Boolean getForce() { + return force; + } + + public String getTenant() { + return tenant; + } + + public Map<String, Object> getParameters() { + return parameters; + } + + public void setDeployment_id(String deployment_id) { + this.deployment_id = deployment_id; + } + + public void setWorkflow_id(String workflow_id) { + this.workflow_id = workflow_id; + } + + public void setAllow_custom_parameters(Boolean allow_custom_parameters) { + this.allow_custom_parameters = allow_custom_parameters; + } + + public void setForce(Boolean force) { + this.force = force; + } + + public void setTenant(String tenant) { + this.tenant = tenant; + } + + public void setParameters(Map<String, Object> parameters) { + this.parameters = parameters; + } @JsonCreator public CloudifyExecutionRequest(@JsonProperty("deployment_id") String deployment_id, - @JsonProperty("workflow_name") String workflow_name, - @JsonProperty("allow_custom_parameter") Boolean allowCustomParameter, @JsonProperty("force") Boolean force, + @JsonProperty("workflow_id") String workflow_id, + @JsonProperty("allow_custom_parameters") Boolean allowCustomParameters, + @JsonProperty("force") Boolean force, + @JsonProperty("tenant") String tenant, @JsonProperty("parameters") Map<String, Object> parameters) { this.deployment_id = deployment_id; - this.workflow_name = workflow_name; - this.allow_custom_parameter = allowCustomParameter; + this.workflow_id = workflow_id; + this.allow_custom_parameters = allowCustomParameters; this.force = force; + this.tenant = tenant; this.parameters = parameters; } diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeId.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeId.java new file mode 100644 index 0000000..b275466 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeId.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CloudifyNodeId extends ECTransportModel { + /** The id of the node */ + public final String id; + + @JsonCreator + public CloudifyNodeId(@JsonProperty("id") String id) { + this.id = id; + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeIdList.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeIdList.java new file mode 100644 index 0000000..95795d6 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeIdList.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CloudifyNodeIdList { + + public final List<CloudifyNodeId> items; + public final Metadata metadata; + + @JsonCreator + public CloudifyNodeIdList(@JsonProperty("items") List<CloudifyNodeId> items, @JsonProperty("metadata") Metadata metadata){ + this.items = items; + this.metadata = metadata; + } + + public static final class Metadata { + public final Pagination pagination; + + @JsonCreator + public Metadata(@JsonProperty("pagination") Pagination pagination){ + this.pagination = pagination; + } + + public static final class Pagination { + public final long total; + public final long offset; + public final long size; + + @JsonCreator + public Pagination(@JsonProperty("total") long total, @JsonProperty("offset") long offset, @JsonProperty("size") long size){ + this.total = total; + this.offset = offset; + this.size = size; + } + } + } +} diff --git a/ccsdk-app-common/src/test/java/org/onap/fusionapp/service/ProfileServiceTest.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeInstance.java index ce00583..adbc02a 100644 --- a/ccsdk-app-common/src/test/java/org/onap/fusionapp/service/ProfileServiceTest.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeInstance.java @@ -1,58 +1,44 @@ -/*******************************************************************************
- * =============LICENSE_START=========================================================
- *
- * =================================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *******************************************************************************/
-package org.onap.fusionapp.service;
-
-import java.util.List;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.onap.fusion.core.MockApplicationContextTestSuite;
-import org.onap.portalsdk.core.domain.Profile;
-import org.onap.portalsdk.core.domain.User;
-import org.onap.portalsdk.core.service.ProfileService;
-import org.onap.portalsdk.core.service.UserProfileService;
-import org.springframework.beans.factory.annotation.Autowired;
-
-
-public class ProfileServiceTest extends MockApplicationContextTestSuite {
-
- @Autowired
- ProfileService service;
-
- @Autowired
- UserProfileService userProfileService;
-
- @Test
- public void testFindAll() throws Exception {
-
- List<Profile> profiles = service.findAll();
- Assert.assertTrue(profiles.size() > 0);
- }
-
- @Test
- public void testFindAllActive() {
-
- List<User> users = userProfileService.findAllActive();
- List<User> activeUsers = userProfileService.findAllActive();
- Assert.assertTrue(users.size() - activeUsers.size() >= 0);
- }
-}
+/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CloudifyNodeInstance extends ECTransportModel { + + /** The id of the node instance. */ + public final String id; + + /** The runtime properties of the node instance. */ + public final Map<String, Object> runtime_properties; + + @JsonCreator + public CloudifyNodeInstance(@JsonProperty("id") String id, + @JsonProperty("runtime_properties") Map<String, Object> runtime_properties) { + this.id = id; + this.runtime_properties = runtime_properties; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeInstanceId.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeInstanceId.java new file mode 100644 index 0000000..f87d34c --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeInstanceId.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model with fields only for the top-level attributes. All complex child + * structures are represented as generic collections. + */ +public final class CloudifyNodeInstanceId extends ECTransportModel { + + /** The id of the node instance. */ + public final String id; + + + + /** The name of the user that created the node instance */ + //public final String created_by; + /** The id of the deployment the node instance belongs to. */ + //public final String deployment_id; + /** The Compute node instance id the node is contained within. */ + //public final String host_id; + /** The relationships the node has with other nodes. */ + //public final List relationships; + /** The runtime properties of the node instance. */ + //public final String runtime_properties; + /** The node instance state. */ + //public final String state; + /** The name of the tenant that owns the node instance. */ + //public final String tenant_name; + /** A version attribute used for optimistic locking when updating the node instance. */ + //public final String version; + + + @JsonCreator + public CloudifyNodeInstanceId(@JsonProperty("id") String id) { + this.id = id; + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeInstanceIdList.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeInstanceIdList.java new file mode 100644 index 0000000..c5ed092 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeInstanceIdList.java @@ -0,0 +1,63 @@ + +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CloudifyNodeInstanceIdList extends ECTransportModel { + + public final List<CloudifyNodeInstanceId> items; + public final Metadata metadata; + + @JsonCreator + public CloudifyNodeInstanceIdList(@JsonProperty("items") List<CloudifyNodeInstanceId> items, @JsonProperty("metadata") Metadata metadata){ + this.items = items; + this.metadata = metadata; + } + + public static final class Metadata { + public final Pagination pagination; + + @JsonCreator + public Metadata(@JsonProperty("pagination") Pagination pagination){ + this.pagination = pagination; + } + + public static final class Pagination { + public final long total; + public final long offset; + public final long size; + + @JsonCreator + public Pagination(@JsonProperty("total") long total, @JsonProperty("offset") long offset, @JsonProperty("size") long size){ + this.total = total; + this.offset = offset; + this.size = size; + } + } + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeInstanceList.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeInstanceList.java new file mode 100644 index 0000000..4a10457 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeInstanceList.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CloudifyNodeInstanceList extends ECTransportModel { + + public final List<CloudifyNodeInstance> items; + public final Metadata metadata; + + @JsonCreator + public CloudifyNodeInstanceList(@JsonProperty("items") List<CloudifyNodeInstance> items, @JsonProperty("metadata") Metadata metadata){ + this.items = items; + this.metadata = metadata; + } + + public static final class Metadata { + public final Pagination pagination; + + @JsonCreator + public Metadata(@JsonProperty("pagination") Pagination pagination){ + this.pagination = pagination; + } + + public static final class Pagination { + public final long total; + public final long offset; + public final long size; + + @JsonCreator + public Pagination(@JsonProperty("total") long total, @JsonProperty("offset") long offset, @JsonProperty("size") long size){ + this.total = total; + this.offset = offset; + this.size = size; + } + } + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifySecret.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifySecret.java new file mode 100644 index 0000000..b0c876e --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifySecret.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CloudifySecret extends ECTransportModel { + + /** The time when the secret was created */ + public final String created_at; + /** The secret’s key, unique per tenant */ + public final String key; + /** The time the secret was last updated at */ + public final String updated_at; + /** The secret’s value */ + public final String value; + /** Defines who can see the secret. Can be private, tenant or global*/ + public final String visibility; + /** Determines who can see the value of the secret. */ + public final String is_hidden_value; + + @JsonCreator + public CloudifySecret( + @JsonProperty("created_at") String created_at, + @JsonProperty("key") String key, + @JsonProperty("updated_at") String updated_at, + @JsonProperty("value") String value, + @JsonProperty("visibility") String visibility, + @JsonProperty("is_hidden_value") String is_hidden_value) { + this.created_at = created_at; + this.key = key; + this.updated_at = updated_at; + this.value = value; + this.visibility = visibility; + this.is_hidden_value = is_hidden_value; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifySecretList.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifySecretList.java new file mode 100644 index 0000000..3cd53b7 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifySecretList.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CloudifySecretList extends ECTransportModel { + public final List<CloudifySecret> items; + public final Metadata metadata; + + @JsonCreator + public CloudifySecretList(@JsonProperty("items") List<CloudifySecret> items, @JsonProperty("metadata") Metadata metadata){ + this.items = items; + this.metadata = metadata; + } + + public static final class Metadata { + public final Pagination pagination; + + @JsonCreator + public Metadata(@JsonProperty("pagination") Pagination pagination){ + this.pagination = pagination; + } + + public static final class Pagination { + public final long total; + public final long offset; + public final long size; + + @JsonCreator + public Pagination(@JsonProperty("total") long total, @JsonProperty("offset") long offset, @JsonProperty("size") long size){ + this.total = total; + this.offset = offset; + this.size = size; + } + } + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifySecretUpload.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifySecretUpload.java new file mode 100644 index 0000000..b1a3fe5 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifySecretUpload.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CloudifySecretUpload extends ECTransportModel { + + /** The secret's name */ + public final String name; + /** The secret’s value */ + public final String value; + /** Update value if secret already exists */ + public final boolean update_if_exists; + /** Defines who can see the secret. Can be private, tenant or global*/ + public final String visibility; + /** Determines who can see the value of the secret. */ + public final boolean is_hidden_value; + /** The tenant name for this secret */ + public final String tenant; + + @JsonCreator + public CloudifySecretUpload( + @JsonProperty("name") String name, + @JsonProperty("value") String value, + @JsonProperty("update_if_exists") boolean update_if_exists, + @JsonProperty("visibility") String visibility, + @JsonProperty("is_hidden_value") boolean is_hidden_value, + @JsonProperty("tenant") String tenant) { + this.name = name; + this.value = value; + this.update_if_exists = update_if_exists; + this.visibility = visibility; + this.is_hidden_value = is_hidden_value; + this.tenant = tenant; + } +} + diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyTenant.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyTenant.java new file mode 100644 index 0000000..fba4229 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyTenant.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CloudifyTenant extends ECTransportModel { + + /** A unique identifier for the tenant */ + public final String id; + /** The tenant's name. */ + public final String name; + /** tenant display name */ + public String dName; + + @JsonCreator + public CloudifyTenant(@JsonProperty("name") String name, + @JsonProperty("dName") String dName, + @JsonProperty("id") String id) { + this.name = name; + this.dName = dName; + this.id = id; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyTenantList.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyTenantList.java new file mode 100644 index 0000000..f298a28 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyTenantList.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CloudifyTenantList extends ECTransportModel { + public final List<CloudifyTenant> items; + public final Metadata metadata; + + @JsonCreator + public CloudifyTenantList(@JsonProperty("items") List<CloudifyTenant> items, @JsonProperty("metadata") Metadata metadata){ + this.items = items; + this.metadata = metadata; + } + + public static final class Metadata { + public final Pagination pagination; + + @JsonCreator + public Metadata(@JsonProperty("pagination") Pagination pagination){ + this.pagination = pagination; + } + + public static final class Pagination { + public final long total; + public final long offset; + public final long size; + + @JsonCreator + public Pagination(@JsonProperty("total") long total, @JsonProperty("offset") long offset, @JsonProperty("size") long size){ + this.total = total; + this.offset = offset; + this.size = size; + } + } + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulDatacenter.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulDatacenter.java index 7b610b5..47b6cb0 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulDatacenter.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulDatacenter.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulHealthServiceRegistration.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulHealthServiceRegistration.java index f899a8d..801dc56 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulHealthServiceRegistration.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulHealthServiceRegistration.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulNodeInfo.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulNodeInfo.java index b3ba4ae..617830c 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulNodeInfo.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulNodeInfo.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulServiceHealth.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulServiceHealth.java index b609b78..fcf00d8 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulServiceHealth.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulServiceHealth.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; "Name": "Service 'pgaasServer1' check", "Status": "passing", "Notes": "This is a pgaas1_Service_ID health check", - "Output": "HTTP GET http:\/\/1.2.3.4:8000\/healthcheck\/status: 200 OK ..", + "Output": "HTTP GET http:\/\/135.91.224.136:8000\/healthcheck\/status: 200 OK Output: { \"output\": \"Thu Apr 20 19:53:01 UTC 2017|INFO|masters=1 pgaas1.rdm1.cci.att.com|secondaries=0 |maintenance= |down=1 pgaas2.rdm1.cci.att.com| \" }\n", "ServiceID": "pgaas1_Service_ID", "ServiceName": "pgaasServer1", "CreateIndex": 190199, diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulServiceHealthHistory.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulServiceHealthHistory.java index f80b506..3a8a171 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulServiceHealthHistory.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulServiceHealthHistory.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; * <pre> { "Status": "critical", - "Output": "\"Get http://1.2.3.4:8080: dial tcp 2.3.4.5:8080: getsockopt: connection refused\"", + "Output": "\"Get http://135.91.205.200:8080: dial tcp 135.91.205.200:8080: getsockopt: connection refused\"", "Date": "2017-06-01 15:31:58.00-0000" } * </pre> diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulServiceInfo.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulServiceInfo.java index edeb029..f990b1f 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulServiceInfo.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ConsulServiceInfo.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ * * ECOMP is a trademark and service mark of AT&T Intellectual Property. *******************************************************************************/ + package org.onap.ccsdk.dashboard.model; import java.util.List; @@ -31,11 +32,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; * monitoring. This is NOT a model of message returned by Controller. * * The controller API answers a message with a map of String (name) to List of - * String (IP addresses). + * String (addresses). * * <pre> { - "pgaasServer1":["1.2.3.4"] + "pgaasServer1":["135.91.224.136"] } * </pre> */ diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ControllerEndpointCredentials.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ControllerEndpointCredentials.java index 7af9e49..abbfd52 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ControllerEndpointCredentials.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ControllerEndpointCredentials.java @@ -1,116 +1,103 @@ -/*******************************************************************************
- * =============LICENSE_START=========================================================
- *
- * =================================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *******************************************************************************/
-package org.onap.ccsdk.dashboard.model;
-
-import org.onap.ccsdk.dashboard.exception.DashboardControllerException;
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.onap.portalsdk.core.onboarding.util.CipherUtil;
-
-/**
- * Model with Controller username and password for use only within the back end;
- * never serialized as JSON.
- */
-public class ControllerEndpointCredentials extends ControllerEndpointTransport {
-
- private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ControllerEndpointCredentials.class);
-
- public String username;
- public String password;
- public boolean isEncryptedPass;
-
- public ControllerEndpointCredentials(boolean selected, String name, String url, String username, String password,
- boolean isEncryptedPass) {
- super(selected, name, url);
- this.username = username;
- this.password = password;
- this.isEncryptedPass = isEncryptedPass;
- }
-
- public String getUsername() {
- return username;
- }
-
- public void setUsername(String username) {
- this.username = username;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public boolean getEncryptedPassword() {
- return isEncryptedPass;
- }
-
- public void setEncryptedPassword(boolean isEncryptedPass) {
- this.isEncryptedPass = isEncryptedPass;
- }
-
- /**
- * Convenience method to yield a ControllerEndpointTransport object.
- *
- * @return ControllerEndpoint with copy of the non-privileged data
- */
- public ControllerEndpointTransport toControllerEndpointTransport() {
- return new ControllerEndpointTransport(getSelected(), getName(), getUrl());
- }
-
- /**
- * Accepts clear text and stores an encrypted value; as a side effect, sets the
- * encrypted flag to true.
- *
- * @param plainText
- * Clear-text password
- * @throws DashboardControllerException
- * If encryption fails
- */
- public void encryptPassword(final String plainText) throws DashboardControllerException {
- try {
- this.password = CipherUtil.encrypt(plainText);
- this.isEncryptedPass = true;
- } catch (Exception ex) {
- logger.error("encryptPassword failed", ex);
- throw new DashboardControllerException(ex);
- }
- }
-
- /**
- * Client should call this method if {@link #getEncryptedPassword()} returns
- * true.
- *
- * @return Clear-text password.
- * @throws DashboardControllerException
- * If decryption fails
- */
- public String decryptPassword() throws DashboardControllerException {
- try {
- return CipherUtil.decrypt(password);
- } catch (Exception ex) {
- logger.error("decryptPassword failed", ex);
- throw new DashboardControllerException(ex);
- }
- }
+/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +import org.onap.portalsdk.core.onboarding.util.CipherUtil; + +/** + * Model with Controller username and password for use only within the back end; + * never serialized as JSON. + */ +public class ControllerEndpointCredentials extends ControllerEndpointTransport { + + public String username; + public String password; + public boolean isEncryptedPass; + + public ControllerEndpointCredentials(boolean selected, String name, String url, String inventoryUrl, String dhandlerUrl, + String consulUrl, String username, String password, boolean isEncryptedPass) { + super(selected, name, url, inventoryUrl, dhandlerUrl, consulUrl); + this.username = username; + this.password = password; + this.isEncryptedPass = isEncryptedPass; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public boolean getEncryptedPassword() { + return isEncryptedPass; + } + + public void setEncryptedPassword(boolean isEncryptedPass) { + this.isEncryptedPass = isEncryptedPass; + } + + /** + * Convenience method to yield a ControllerEndpointTransport object. + * + * @return ControllerEndpoint with copy of the non-privileged data + */ + public ControllerEndpointTransport toControllerEndpointTransport() { + return new ControllerEndpointTransport(getSelected(), getName(), getUrl(), + getInventoryUrl(), getDhandlerUrl(), getConsulUrl()); + } + + /** + * Accepts clear text and stores an encrypted value; as a side effect, sets + * the encrypted flag to true. + * + * @param plainText + * Clear-text password + * @throws Exception + * If encryption fails + */ + public void encryptPassword(final String plainText) throws Exception { + this.password = CipherUtil.encrypt(plainText); + this.isEncryptedPass = true; + } + + /** + * Client should call this method if {@link #getEncryptedPassword()} returns + * true. + * + * @return Clear-text password. + * @throws Exception + * If decryption fails + */ + public String decryptPassword() throws Exception { + return CipherUtil.decrypt(password); + } }
\ No newline at end of file diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ControllerEndpointTransport.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ControllerEndpointTransport.java index 0a2f529..e297782 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ControllerEndpointTransport.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ControllerEndpointTransport.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,13 +29,20 @@ public class ControllerEndpointTransport extends ECTransportModel { private boolean selected; private String name; private String url; + private String inventoryUrl; + private String dhandlerUrl; + private String consulUrl; public ControllerEndpointTransport() {} - public ControllerEndpointTransport(boolean selected, String name, String url) { + public ControllerEndpointTransport(boolean selected, String name, + String url, String inventoryUrl, String dhandlerUrl, String consulUrl) { this.selected = selected; this.name = name; this.url = url; + this.inventoryUrl = inventoryUrl; + this.dhandlerUrl = dhandlerUrl; + this.consulUrl = consulUrl; } public boolean getSelected() { @@ -62,4 +69,27 @@ public class ControllerEndpointTransport extends ECTransportModel { this.url = url; } + public String getInventoryUrl() { + return inventoryUrl; + } + + public void setInventoryUrl(String inventoryUrl) { + this.inventoryUrl = inventoryUrl; + } + + public String getDhandlerUrl() { + return dhandlerUrl; + } + + public void setDhandlerUrl(String dhandlerUrl) { + this.dhandlerUrl = dhandlerUrl; + } + + public String getConsulUrl() { + return consulUrl; + } + + public void setConsulUrl(String consulUrl) { + this.consulUrl = consulUrl; + } } diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ControllerOpsTools.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ControllerOpsTools.java new file mode 100644 index 0000000..0f752a7 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ControllerOpsTools.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ +package org.onap.ccsdk.dashboard.model; + +/** + * Model for message passed by backend to frontend about OPS Tools URLs. + */ +public class ControllerOpsTools extends ECTransportModel { + + private String id; + private String url; + + public ControllerOpsTools() {} + + public ControllerOpsTools(String id, String url) { + this.setId(id); + this.setUrl(url); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ECTransportModel.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ECTransportModel.java index 3e0baa1..946a4ec 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ECTransportModel.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/ECTransportModel.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ccsdk-app-common/src/test/java/org/onap/fusionapp/SanityTest.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/EcdAppComponent.java index c859c28..a507515 100644 --- a/ccsdk-app-common/src/test/java/org/onap/fusionapp/SanityTest.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/EcdAppComponent.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,23 +19,26 @@ * * ECOMP is a trademark and service mark of AT&T Intellectual Property. *******************************************************************************/ -package org.onap.fusionapp; +package org.onap.ccsdk.dashboard.model; -import org.junit.Assert; -import org.junit.Test; -import org.onap.fusion.core.MockApplicationContextTestSuite; -import org.springframework.test.web.servlet.ResultActions; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import java.util.List; -public class SanityTest extends MockApplicationContextTestSuite { +import org.onap.ccsdk.dashboard.domain.EcdComponent; + +public class EcdAppComponent { - @Test - public void testGetAvailableRoles() throws Exception { - - ResultActions ra =getMockMvc().perform(MockMvcRequestBuilders.get("/api/roles")); - //Assert.assertEquals(UrlAccessRestrictedException.class,ra.andReturn().getResolvedException().getClass()); - Assert.assertEquals("application/json",ra.andReturn().getResponse().getContentType()); - } + public String app; - + public List<EcdComponent> comps; +/* + @JsonCreator + public EcdAppComponent(@JsonProperty("app") String app, + @JsonProperty("comps") List<EcdComponent> comps) { + this(app, comps); + } + */ + public EcdAppComponent(String app, List<EcdComponent> comps) { + this.app = app; + this.comps = comps; + } } diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/HealthStatus.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/HealthStatus.java index 93d072f..1b72e7c 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/HealthStatus.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/HealthStatus.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ package org.onap.ccsdk.dashboard.model; * Model for JSON response with health-check results. */ public class HealthStatus { - // Either 200 or 500 + // Either 200 or 503 public int statusCode; // Additional detail in case of error, empty in case of success. public String message; diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/RestResponseError.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/RestResponseError.java index 64e0d71..8027f92 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/RestResponseError.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/RestResponseError.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/RestResponsePage.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/RestResponsePage.java index 0902fb0..5e9c963 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/RestResponsePage.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/RestResponsePage.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/RestResponseSuccess.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/RestResponseSuccess.java index 145c1cd..4eba0d8 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/RestResponseSuccess.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/RestResponseSuccess.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentErrorResponse.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentErrorResponse.java new file mode 100644 index 0000000..06a516c --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentErrorResponse.java @@ -0,0 +1,40 @@ +package org.onap.ccsdk.dashboard.model.deploymenthandler; + +import java.util.Collection; +import java.util.Optional; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class DeploymentErrorResponse { + + /** HTTP status code for the response */ + private final int status; + + /** Human-readable description of the reason for the error */ + private final String message; + + /** exception stack trace */ + private final Optional<Collection<String>> stack; + + @JsonCreator + public DeploymentErrorResponse(@JsonProperty("status") int status, + @JsonProperty("message") String message, + @JsonProperty("stack") Optional<Collection<String>> stack) { + this.status = status; + this.message = message; + this.stack = stack; + } + + public int getStatus() { + return status; + } + + public String getMessage() { + return message; + } + + public Optional<Collection<String>> getStack() { + return stack; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentInput.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentInput.java new file mode 100644 index 0000000..75f97ee --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentInput.java @@ -0,0 +1,102 @@ +package org.onap.ccsdk.dashboard.model.deploymenthandler; + +import java.util.Map; +import java.util.Optional; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model for message POST-ed to controller to create a Deployment via the Deployment Handler API: + * + * <pre> + { + "component" : "comp", + "deploymentTag" : "tag", + "blueprintName" : "name", + "blueprintVersion" : "version", + "blueprintId" : "bp_id", + "inputs" : + { + "input1" : "parameter1", + "input2" : "parameter2", + ... + "inputn" : "parametern" + }, + "tenant" : "tenant_name" + } + * </pre> + * + * THIS OBJECT INCLUDES THE DEPLOYMENTID CREATED BY THE USER! + */ +public class DeploymentInput { + + /** component or namespace for the service */ + private final String component; + + /** tag to identify the deployment */ + private final String tag; + + /** The blueprint name for the service to be deployed. */ + private final String blueprintName; + + /** blueprint version for the service to be deployed */ + private final Optional<Integer> blueprintVersion; + + /** blueprint typeId from inventory */ + private final Optional<String> blueprintId; + + /** The cloudify tenant name for the deployment */ + private final String tenant; + /** + * Object containing inputs needed by the service blueprint to create an instance of the service. + * Content of the object depends on the service being deployed. + */ + private final Map<String, Object> inputs; + + @JsonCreator + public DeploymentInput( + @JsonProperty("component") String component, + @JsonProperty("tag") String tag, + @JsonProperty("blueprintName") String blueprintName, + @JsonProperty("blueprintVersion") Integer blueprintVersion, + @JsonProperty("blueprintId") String blueprintId, + @JsonProperty("inputs") Map<String, Object> inputs, + @JsonProperty("tenant") String tenant) { + this.component = component; + this.tag = tag; + this.blueprintName = blueprintName; + this.blueprintVersion = Optional.ofNullable(blueprintVersion); + this.blueprintId = Optional.ofNullable(blueprintId); + this.inputs = inputs; + this.tenant = tenant; + } + + public String getBlueprintName() { + return this.blueprintName; + } + + public Map<String, Object> getInputs() { + return this.inputs; + } + + public String getTenant() { + return this.tenant; + } + + public Optional<Integer> getBlueprintVersion() { + return blueprintVersion; + } + + public String getTag() { + return tag; + } + + public String getComponent() { + return component; + } + + public Optional<String> getBlueprintId() { + return blueprintId; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentLink.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentLink.java new file mode 100644 index 0000000..b715a2d --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentLink.java @@ -0,0 +1,19 @@ +package org.onap.ccsdk.dashboard.model.deploymenthandler; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class DeploymentLink { + + /** URL for the service Deployment */ + private String href; + + @JsonCreator + public DeploymentLink (@JsonProperty("href") String href) { + this.href = href; + } + + public String getHref() { + return this.href; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentRequest.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentRequest.java new file mode 100644 index 0000000..9d6a3b7 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentRequest.java @@ -0,0 +1,49 @@ +package org.onap.ccsdk.dashboard.model.deploymenthandler; + +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model for message POST-ed to controller to create a Deployment via the Deployment Handler API: + * + * <pre> + { + "serviceTypeId" : "serviceTypeId", + "inputs" : + { + "input1" : "parameter1" + "input2" : "parameter2" + ... + "inputn" : "parametern" + } + } + * </pre> + */ +public class DeploymentRequest { + + /** The service type identifier (a unique ID assigned by DCAE inventory) for the service to be deployed. */ + private final String serviceTypeId; + + /** + * Object containing inputs needed by the service blueprint to create an instance of the service. + * Content of the object depends on the service being deployed. + */ + private final Map<String, Object> inputs; + + @JsonCreator + public DeploymentRequest(@JsonProperty("serviceTypeId") String serviceTypeId, + @JsonProperty("inputs") Map<String, Object> inputs) { + this.serviceTypeId = serviceTypeId; + this.inputs = inputs; + } + + public String getServiceTypeId() { + return this.serviceTypeId; + } + + public Map<String, Object> getInputs() { + return this.inputs; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentRequestObject.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentRequestObject.java new file mode 100644 index 0000000..a0606c7 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentRequestObject.java @@ -0,0 +1,78 @@ +package org.onap.ccsdk.dashboard.model.deploymenthandler; + +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model for message POST-ed to controller to create a Deployment via the Deployment Handler API: + * + * <pre> + { + "serviceTypeId" : "serviceTypeId", + "type" : "install/update", + "inputs" : + { + "input1" : "parameter1" + "input2" : "parameter2" + ... + "inputn" : "parametern" + } + } + * </pre> + * + * THIS OBJECT INCLUDES THE DEPLOYMENTID CREATED BY THE USER! + */ +public class DeploymentRequestObject { + + /** Unique deployment identifier assigned by the API client. */ + private final String deploymentId; + + /** type of deployment request */ + private final String method; + + /** The service type identifier (a unique ID assigned by DCAE inventory) for the service to be deployed. */ + private final String serviceTypeId; + + /** The cloudify tenant name for the deployment */ + private final String tenant; + /** + * Object containing inputs needed by the service blueprint to create an instance of the service. + * Content of the object depends on the service being deployed. + */ + private final Map<String, Object> inputs; + + @JsonCreator + public DeploymentRequestObject(@JsonProperty("deploymentId") String deploymentId, + @JsonProperty("serviceTypeId") String serviceTypeId, + @JsonProperty("inputs") Map<String, Object> inputs, + @JsonProperty("tenant") String tenant, + @JsonProperty("method") String method) { + this.deploymentId = deploymentId; + this.serviceTypeId = serviceTypeId; + this.inputs = inputs; + this.tenant = tenant; + this.method = method; + } + + public String getDeploymentId() { + return this.deploymentId; + } + + public String getServiceTypeId() { + return this.serviceTypeId; + } + + public Map<String, Object> getInputs() { + return this.inputs; + } + + public String getTenant() { + return this.tenant; + } + + public String getMethod() { + return method; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentResource.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentResource.java new file mode 100644 index 0000000..513b673 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentResource.java @@ -0,0 +1,32 @@ +package org.onap.ccsdk.dashboard.model.deploymenthandler; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class DeploymentResource { + /** Unique Identifier for the resource */ + private String deploymentId; + + public String getDeploymentId() { + return deploymentId; + } + + public void setDeploymentId(String deploymentId) { + this.deploymentId = deploymentId; + } + + /** Links that the API client can access */ + private DeploymentResourceLinks links; + + @JsonCreator + public DeploymentResource(@JsonProperty("deployment_id") String deploymentId, + @JsonProperty("links") DeploymentResourceLinks links) { + this.deploymentId = deploymentId; + this.links = links; + } + + public DeploymentResourceLinks getLinks() { + return this.links; + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentResourceLinks.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentResourceLinks.java new file mode 100644 index 0000000..0dd9f9e --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentResourceLinks.java @@ -0,0 +1,37 @@ +package org.onap.ccsdk.dashboard.model.deploymenthandler; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class DeploymentResourceLinks { + /** Link used to retrieve information about the service being deployed. */ + private final String self; + + /** Link used to retrieve information about deployment outcome */ + private final String outcome; + + /** Link used to retrieve information about the status of the installation workflow. */ + private final String status; + + @JsonCreator + public DeploymentResourceLinks( + @JsonProperty("self") String self, + @JsonProperty("outcome") String outcome, + @JsonProperty("status") String status) { + this.self = self; + this.outcome = outcome; + this.status = status; + } + + public String getSelf() { + return this.self; + } + + public String getStatus() { + return this.status; + } + + public String getOutcome() { + return outcome; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentResponse.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentResponse.java new file mode 100644 index 0000000..cd81a0b --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentResponse.java @@ -0,0 +1,32 @@ +package org.onap.ccsdk.dashboard.model.deploymenthandler; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Response body for a PUT or DELETE to /dcae-deployments/{deploymentId} + * + */ +public class DeploymentResponse { + + /** Unique Identifier for the request */ + private String requestId; + + /** Links that the API client can access */ + private DeploymentResponseLinks links; + + @JsonCreator + public DeploymentResponse(@JsonProperty("requestId") String requestId, + @JsonProperty("links") DeploymentResponseLinks links) { + this.requestId = requestId; + this.links = links; + } + + public String getRequestId() { + return this.requestId; + } + + public DeploymentResponseLinks getLinks() { + return this.links; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentResponseLinks.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentResponseLinks.java new file mode 100644 index 0000000..c0b27b6 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentResponseLinks.java @@ -0,0 +1,32 @@ +package org.onap.ccsdk.dashboard.model.deploymenthandler; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Links that the API client can access + * + */ +public class DeploymentResponseLinks { + + /** Link used to retrieve information about the service being deployed. */ + private final String self; + + /** Link used to retrieve information about the status of the installation workflow. */ + private final String status; + + @JsonCreator + public DeploymentResponseLinks(@JsonProperty("self") String self, + @JsonProperty("status") String status) { + this.self = self; + this.status = status; + } + + public String getSelf() { + return this.self; + } + + public String getStatus() { + return this.status; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentsListResponse.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentsListResponse.java new file mode 100644 index 0000000..5b3b456 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/DeploymentsListResponse.java @@ -0,0 +1,34 @@ +package org.onap.ccsdk.dashboard.model.deploymenthandler; + +import java.util.Collection; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Object providing a list of deployments + * + */ +public class DeploymentsListResponse { + + /** Unique identifier for the request */ + private final String requestId; + + /** Stream object containing links to all deployments known to the orchestrator. */ + private final Collection<DeploymentLink> deployments; + + @JsonCreator + public DeploymentsListResponse (@JsonProperty("requestId") String requestId, + @JsonProperty("deployments") Collection<DeploymentLink> deployments) { + this.requestId = requestId; + this.deployments = deployments; + } + + public String getRequestId() { + return this.requestId; + } + + public Collection<DeploymentLink> getDeployments() { + return this.deployments; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/InventoryDeploymentRequest.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/InventoryDeploymentRequest.java new file mode 100644 index 0000000..564d4b3 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/deploymenthandler/InventoryDeploymentRequest.java @@ -0,0 +1,63 @@ +package org.onap.ccsdk.dashboard.model.deploymenthandler; + +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model for message used by the controller to create a DeploymentRequest for + * the Deployment Handler API. + * + * <pre> + { + "deploymentId" : "deploymentId", + "body" : + { + "serviceTypeId" : "serviceTypeId", + "inputs" : + { + "input1" : "parameter1" + "input2" : "parameter2" + ... + "inputn" : "parametern" + } + } + } + * </pre> + */ +public final class InventoryDeploymentRequest { + + /** Unique deployment identifier assigned by the API client. */ + private final String deploymentId; + + /** The service type identifier (a unique ID assigned by DCAE inventory) for the service to be deployed. */ + private final String serviceTypeId; + + /** + * Object containing inputs needed by the service blueprint to create an instance of the service. + * Content of the object depends on the service being deployed. + */ + private final Map<String, Object> inputs; + + @JsonCreator + public InventoryDeploymentRequest(@JsonProperty("deploymentId") String deploymentId, + @JsonProperty("serviceTypeId") String serviceTypeId, + @JsonProperty("inputs") Map<String, Object> inputs) { + this.deploymentId = deploymentId; + this.serviceTypeId = serviceTypeId; + this.inputs = inputs; + } + + public String getDeploymentId() { + return this.deploymentId; + } + + public String getServiceTypeId() { + return this.serviceTypeId; + } + + public Map<String, Object> getInputs() { + return this.inputs; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ApiResponseMessage.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ApiResponseMessage.java new file mode 100644 index 0000000..a2c1c20 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ApiResponseMessage.java @@ -0,0 +1,23 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ApiResponseMessage { + + /** Response Code */ + public Integer code; + /** Response Type */ + public String type; + /** Response Message */ + public String message; + + @JsonCreator + public ApiResponseMessage (@JsonProperty("code") Integer code, + @JsonProperty("type") String type, + @JsonProperty("message") String message){ + this.code = code; + this.type = type; + this.message = message; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/Blueprint.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/Blueprint.java new file mode 100644 index 0000000..c0b7b37 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/Blueprint.java @@ -0,0 +1,70 @@ +package org.onap.ccsdk.dashboard.model.inventory; +import java.io.File; +import java.io.IOException; +import java.util.Map; +import java.util.Scanner; + +import org.onap.ccsdk.dashboard.exceptions.inventory.BlueprintParseException; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class Blueprint { + + private static final ObjectMapper YAML_MAPPER = new ObjectMapper(new YAMLFactory()); + + static { + YAML_MAPPER.registerModule(new Jdk8Module()); + } + + @JsonProperty("inputs") + private Map<String, BlueprintInput> inputs; + @JsonProperty("description") + private String description; + + public static Blueprint parse(String blueprint) throws BlueprintParseException { + try { + return getYamlMapper().readValue(blueprint, Blueprint.class); + } catch (IOException e) { + throw new BlueprintParseException(e); + } + } + + private static ObjectMapper getYamlMapper() { + return YAML_MAPPER; + } + + public Map<String, BlueprintInput> getInputs() { + return inputs; + } + + public String getDescription() { + return description; + } + + @Override + public String toString() { + return "inputs: " + ((getInputs() != null) ? getInputs().toString() : "{}"); + } + + public static void main(String args[]) throws Exception { + + File file = new File("C:\\Temp\\testBP.yaml"); + StringBuilder fileContents = new StringBuilder((int)file.length()); + Scanner scanner = new Scanner(file); + String lineSeparator = System.getProperty("line.separator"); + try { + while(scanner.hasNextLine()) { + fileContents.append(scanner.nextLine() + lineSeparator); + } + Blueprint bp = Blueprint.parse(fileContents.toString()); + System.out.println("blueprint contents: " + bp.toString()); + } finally { + scanner.close(); + } + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/BlueprintInput.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/BlueprintInput.java new file mode 100644 index 0000000..596438b --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/BlueprintInput.java @@ -0,0 +1,119 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import java.util.Optional; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Compliance with the schema spec'd here: http://docs.getcloudify.org/3.4.0/blueprints/spec-inputs/ + */ +@JsonInclude(Include.NON_NULL) +public class BlueprintInput { + + private final BlueprintInput.Type type; + private final Optional<Object> defaultValue; + private final Optional<String> description; + + public static enum Type { + @JsonProperty("any") + ANY, + + @JsonProperty("string") + STRING, + + @JsonProperty("integer") + INTEGER, + + @JsonProperty("boolean") + BOOLEAN + } + + @JsonCreator + public BlueprintInput( + @JsonProperty("type") String type, + @JsonProperty("default") Object defaultValue, + @JsonProperty("description") String description) { + + // Case where there is no default and no type --> Type should be ANY + if (defaultValue == null && type == null) { + this.type = BlueprintInput.Type.ANY; + } + + // Case where there is a default but no type --> Type should be ANY + else if (defaultValue != null && type == null) { + this.type = BlueprintInput.Type.ANY; + } + + // Case where there is a type but no default --> Type should be the specified type. + else if (defaultValue == null && type != null) { + this.type = BlueprintInput.Type.valueOf(type.toString().toUpperCase()); + } + + // Cases where there is a default and a type + else { + switch (BlueprintInput.Type.valueOf(type.toString().toUpperCase())) { + case ANY: + throw new IllegalArgumentException("Cannot specify type ANY (leave blank instead to get ANY type)"); + case BOOLEAN: + if (defaultValue != null && !(defaultValue instanceof Boolean)) throw new IllegalArgumentException("default value does not match specified type"); + this.type = BlueprintInput.Type.BOOLEAN; + break; + case INTEGER: + if (defaultValue != null && !(defaultValue instanceof Integer)) throw new IllegalArgumentException("default value does not match specified type"); + this.type = BlueprintInput.Type.INTEGER; + break; + case STRING: + if (defaultValue != null && !(defaultValue instanceof String)) throw new IllegalArgumentException("default value does not match specified type"); + + this.type = BlueprintInput.Type.STRING; + break; + default: + this.type = Type.ANY; + break; + } + } + + this.defaultValue = Optional.ofNullable(defaultValue); + this.description = Optional.ofNullable(description); + } + + public BlueprintInput.Type getType() { return type; } + + @JsonIgnore + public Optional<Object> getDefault() { return defaultValue; } + + @JsonProperty("defaultValue") + public Object getDefaultValue() { return defaultValue.orElse(null); } + + @JsonIgnore + public Optional<String> getDescription() { return description; } + + @JsonProperty("description") + public String getDescriptionValue() { return description.orElse(null); } + + @Override + public boolean equals(Object o) { + if (o instanceof BlueprintInput) { + final BlueprintInput obj = (BlueprintInput) o; + + return obj.getDefaultValue().equals(getDefaultValue()) && + obj.getDescriptionValue().equals(getDescriptionValue()) && + obj.getType().equals(getType()); + } + + return false; + } + + @Override + public String toString() { + return "{" + + "type: " + getType() + + ",default: " + getDefault() + + ",description: " + getDescription() + + "}"; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/BlueprintResponse.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/BlueprintResponse.java new file mode 100644 index 0000000..fdec86d --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/BlueprintResponse.java @@ -0,0 +1,58 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class BlueprintResponse { + + public BlueprintResponse() { + } + + /** Name of the ServiceType */ + private String typeName; + + /** Version number for this ServiceType */ + private Integer typeVersion; + + /** Unique identifier for this ServiceType */ + private String typeId; + + @JsonCreator + public BlueprintResponse(@JsonProperty("typeName") String typeName, + @JsonProperty("typeVersion") Integer typeVersion, + @JsonProperty("typeId") String typeId) { + + this.typeName = typeName; + this.typeVersion = typeVersion; + this.typeId = typeId; + } + + public String getTypeName() { + return typeName; + } + + public Integer getTypeVersion() { + return typeVersion; + } + + public String getTypeId() { + return typeId; + } + + public void setTypeName(String typeName) { + this.typeName = typeName; + } + + public void setTypeVersion(Integer typeVersion) { + this.typeVersion = typeVersion; + } + + public void setTypeId(String typeId) { + this.typeId = typeId; + } + + @Override + public String toString() { + return "BlueprintResponse [typeName=" + typeName + ", typeVersion=" + typeVersion + ", typeId=" + typeId + "]"; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/InventoryProperty.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/InventoryProperty.java new file mode 100644 index 0000000..3856deb --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/InventoryProperty.java @@ -0,0 +1,23 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class InventoryProperty { + + /** Number of Service objects */ + public Integer count; + /** Service property value */ + public String propertyValue; + /** Link to a list of Services that all have this property value */ + public Link dcaeServiceQueryLink; + + @JsonCreator + public InventoryProperty (@JsonProperty("count") Integer count, + @JsonProperty("propertyValue") String propertyValue, + @JsonProperty("dcaeServiceQueryLink") Link dcaeServiceQueryLink) { + this.count = count; + this.propertyValue = propertyValue; + this.dcaeServiceQueryLink = dcaeServiceQueryLink; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/Link.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/Link.java new file mode 100644 index 0000000..42d4e47 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/Link.java @@ -0,0 +1,40 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import java.util.Collection; +import java.util.Map; + +import javax.ws.rs.core.UriBuilder; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Link { + + public String title; + public String href; + public String rel; + public String uri; + public UriBuilder uriBuilder; + public Collection<String> rels; + public Map<String, String> params; + public String type; + + @JsonCreator + public Link (@JsonProperty("title") String title, + @JsonProperty("href") String href, + @JsonProperty("rel") String rel, + @JsonProperty("uri") String uri, + @JsonProperty("uriBuilder") UriBuilder uriBuilder, + @JsonProperty("rels") Collection<String> rels, + @JsonProperty("params") Map<String, String> params, + @JsonProperty("type") String type) { + this.title = title; + this.href = href; + this.rel = rel; + this.uri = uri; + this.uriBuilder = uriBuilder; + this.rels = rels; + this.params = params; + this.type = type; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/Service.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/Service.java new file mode 100644 index 0000000..928f176 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/Service.java @@ -0,0 +1,162 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import java.util.Collection; +import java.util.Optional; + +import org.apache.commons.lang3.StringUtils; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Service { + + /** Service ID of the Service */ + private final String serviceId; + /** Link to the Service */ + private final Link selfLink; + /** Creation date of the Service */ + private final String created; + /** Last modified date of the Service */ + private final String modified; + /** Link to the Service Type */ + private final Link typeLink; + /** vnfId of the Service */ + private final String vnfId; + /** Link to the vnf of the Service */ + private final Link vnfLink; + /** vnfType of the Service */ + private final String vnfType; + /** vnfLocation of the Service */ + private final String vnfLocation; + /** Reference to a Cloudify deployment */ + private final String deploymentRef; + /** Collection of ServiceComponent */ + private final Collection<ServiceComponent> components; + /** internal role based setting */ + private Optional<Boolean> canDeploy; + /** tenant name for this service */ + private String tenant; + + @JsonCreator + public Service (@JsonProperty("serviceId") String serviceId, + @JsonProperty("selfLink") Link selfLink, + @JsonProperty("created") String created, + @JsonProperty("modified") String modified, + @JsonProperty("typeLink") Link typeLink, + @JsonProperty("vnfId") String vnfId, + @JsonProperty("vnfLink") Link vnfLink, + @JsonProperty("vnfType") String vnfType, + @JsonProperty("vnfLocation") String vnfLocation, + @JsonProperty("deploymentRef") String deploymentRef, + @JsonProperty("components") Collection<ServiceComponent> components) { + this.serviceId = serviceId; + this.selfLink = selfLink; + this.created = created; + this.modified = modified; + this.typeLink = typeLink; + this.vnfId = vnfId; + this.vnfLink = vnfLink; + this.vnfType = vnfType; + this.vnfLocation = vnfLocation; + this.deploymentRef = deploymentRef; + this.components = components; + } + + public String getServiceId() { + return serviceId; + } + + public Link getSelfLink() { + return selfLink; + } + + public String getCreated() { + return created; + } + + public String getModified() { + return modified; + } + + public Link getTypeLink() { + return typeLink; + } + + public String getVnfId() { + return vnfId; + } + + public Link getVnfLink() { + return vnfLink; + } + + public String getVnfType() { + return vnfType; + } + + public String getVnfLocation() { + return vnfLocation; + } + + public String getDeploymentRef() { + return deploymentRef; + } + + public Collection<ServiceComponent> getComponents() { + return components; + } + + // Used for back end search, only searches the fields displayed in the front end. + public boolean contains(String searchString) { + if (StringUtils.containsIgnoreCase(this.getDeploymentRef(), searchString) || + StringUtils.containsIgnoreCase(this.getServiceId(), searchString) || + StringUtils.containsIgnoreCase(this.getCreated(), searchString) || + StringUtils.containsIgnoreCase(this.getModified(), searchString) || + StringUtils.containsIgnoreCase(this.getTenant(), searchString)) { + return true; + } + return false; + } + + public Optional<Boolean> getCanDeploy() { + return canDeploy; + } + + public void setCanDeploy(Optional<Boolean> canDeploy) { + this.canDeploy = canDeploy; + } + + public String getTenant() { + return tenant; + } + + public void setTenant(String tenant) { + this.tenant = tenant; + } + + public ServiceRef createServiceRef() { + return new ServiceRef(serviceId, + created, + modified); + } + /* + public static class ServiceRefBuilder { + private String serviceId; + private String created; + private String modified; + + public ServiceRefBuilder mapFromService(Service srvc) { + this.serviceId = srvc.getServiceId(); + this.created = srvc.getCreated(); + this.modified = srvc.getModified(); + return this; + } + + public ServiceRef build() { + return new ServiceRef(serviceId, + created, + modified); + } + } + */ +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceComponent.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceComponent.java new file mode 100644 index 0000000..e7d247b --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceComponent.java @@ -0,0 +1,47 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ServiceComponent { + + /** Component ID of the Service Component */ + public String componentId; + /** Link to the Service Component */ + public Link componentLink; + /** Creation date of the Service Component */ + public String created; + /** Last modified date of the Service Component */ + public String modified; + /** Component Type of the Service Component */ + public String componentType; + /** Specifies the name of the underlying source service responsible for this component */ + public String componentSource; + /** Status of the Service Component */ + public String status; + /** Location of the Service Component */ + public String location; + /** Used to determine of this component can be shared amongst different Services */ + public Integer shareable; + + @JsonCreator + public ServiceComponent(@JsonProperty("componentId") String componentId, + @JsonProperty("componentLink") Link componentLink, + @JsonProperty("created") String created, + @JsonProperty("modified") String modified, + @JsonProperty("componentType") String componentType, + @JsonProperty("componentSource") String componentSource, + @JsonProperty("status") String status, + @JsonProperty("location") String location, + @JsonProperty("shareable") Integer shareable) { + this.componentId = componentId; + this.componentLink = componentLink; + this.created = created; + this.modified = modified; + this.componentType = componentType; + this.componentSource = componentSource; + this.status = status; + this.location = location; + this.shareable = shareable; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceComponentRequest.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceComponentRequest.java new file mode 100644 index 0000000..c4c2fd9 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceComponentRequest.java @@ -0,0 +1,31 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ServiceComponentRequest { + + /** Component ID of the Service Component */ + public String componentId; + /** Component Type of the Service Component */ + public String componentType; + /** Specifies the name of the underlying source service responsible for this component */ + public String componentSource; + /** Used to determine if this component can be shared amongst different Services */ + public Integer shareable; + + @JsonCreator + public ServiceComponentRequest (@JsonProperty("componentId") String componentId, + @JsonProperty("componentType") String componentType, + @JsonProperty("componentSource") String componentSource, + @JsonProperty("shareable") Integer shareable) { + this.componentId = componentId; + this.componentType = componentType; + this.componentSource = componentSource; + this.shareable = shareable; + } + + public static ServiceComponentRequest from(ServiceComponent sc) { + return new ServiceComponentRequest(sc.componentId, sc.componentType, sc.componentSource, sc.shareable); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceGroupByResults.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceGroupByResults.java new file mode 100644 index 0000000..0bf6858 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceGroupByResults.java @@ -0,0 +1,21 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import java.util.Set; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ServiceGroupByResults { + + /** Property name of the service that the group by operation was performed on */ + public String propertyName; + /** Set of Service objects that have the aforementioned propertyName */ + public Set<InventoryProperty> propertyValues; + + @JsonCreator + public ServiceGroupByResults (@JsonProperty("propertyName") String propertyName, + @JsonProperty("propertyValues") Set<InventoryProperty> propertyValues) { + this.propertyName = propertyName; + this.propertyValues = propertyValues; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceList.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceList.java new file mode 100644 index 0000000..71f786a --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceList.java @@ -0,0 +1,40 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import java.util.Collection; + +import org.onap.ccsdk.dashboard.model.ECTransportModel; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ServiceList extends ECTransportModel { + + /** Number of Service objects */ + public final Integer totalCount; + /** Collection containing all of the returned Service objects */ + public final Collection<Service> items; + /** Links to the previous and next page of items */ + public final PaginationLinks paginationLinks; + + @JsonCreator + public ServiceList(@JsonProperty("items") Collection<Service> items, + @JsonProperty("totalCount") Integer totalCount, + @JsonProperty("links") PaginationLinks paginationLinks) { + this.items = items; + this.totalCount = totalCount; + this.paginationLinks = paginationLinks; + } + + /** Inline200ResponseLinks */ + public static final class PaginationLinks { + public final Link previousLink; + public final Link nextLink; + + @JsonCreator + public PaginationLinks (@JsonProperty("previousLink") Link previousLink, + @JsonProperty("nextLink") Link nextLink) { + this.previousLink = previousLink; + this.nextLink = nextLink; + } + } +}
\ No newline at end of file diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceQueryParams.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceQueryParams.java new file mode 100644 index 0000000..c24f86b --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceQueryParams.java @@ -0,0 +1,122 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +public class ServiceQueryParams { + + private final String typeId; + private final String vnfId; + private final String vnfType; + private final String vnfLocation; + private final String componentType; + private final Boolean shareable; + private final String created; + + // Non-instantiable + private ServiceQueryParams() { + this.typeId = null; + this.vnfId = null; + this.vnfType = null; + this.vnfLocation = null; + this.componentType = null; + this.shareable = null; + this.created = null; + } + + private ServiceQueryParams(String typeId, + String vnfId, + String vnfType, + String vnfLocation, + String componentType, + Boolean shareable, + String created) { + this.typeId = typeId; + this.vnfId = vnfId; + this.vnfType = vnfType; + this.vnfLocation = vnfLocation; + this.componentType = componentType; + this.shareable = shareable; + this.created = created; + } + + public static class Builder { + private String typeId; + private String vnfId; + private String vnfType; + private String vnfLocation; + private String componentType; + private Boolean shareable; + private String created; + + public Builder typeId(String typeId) { + this.typeId = typeId; + return this; + } + + public Builder vnfId(String vnfId) { + this.vnfId = vnfId; + return this; + } + + public Builder vnfType(String vnfType) { + this.vnfType = vnfType; + return this; + } + + public Builder vnfLocation(String vnfLocation) { + this.vnfLocation = vnfLocation; + return this; + } + + public Builder componentType(String componentType) { + this.componentType = componentType; + return this; + } + + public Builder shareable(Boolean shareable) { + this.shareable = shareable; + return this; + } + + public Builder created(String created) { + this.created = created; + return this; + } + + public ServiceQueryParams build() { + return new ServiceQueryParams(typeId, + vnfId, + vnfType, + vnfLocation, + componentType, + shareable, + created); + } + } + + public String getTypeId() { + return this.typeId; + } + + public String getVnfId() { + return this.vnfId; + } + + public String getVnfType() { + return this.vnfType; + } + + public String getVnfLocation() { + return this.vnfLocation; + } + + public String getComponentType() { + return this.componentType; + } + + public Boolean getShareable() { + return this.shareable; + } + + public String getCreated() { + return this.created; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceRef.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceRef.java new file mode 100644 index 0000000..dd7acd1 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceRef.java @@ -0,0 +1,50 @@ +package org.onap.ccsdk.dashboard.model.inventory; + + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ServiceRef { + + /** Service ID of the Service */ + private final String serviceId; + /** Creation date of the Service */ + private final String created; + /** Last modified date of the Service */ + private final String modified; + + + @JsonCreator + public ServiceRef (@JsonProperty("serviceId") String serviceId, + @JsonProperty("created") String created, + @JsonProperty("modified") String modified) { + this.serviceId = serviceId; + this.created = created; + this.modified = modified; + + } + + public String getServiceId() { + return serviceId; + } + + public String getCreated() { + return created; + } + + public String getModified() { + return modified; + } + + /* + private ServiceRef ( + String serviceId, + String created, + String modified) { + this.serviceId = serviceId; + this.created = created; + this.modified = modified; + } + */ + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceRefList.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceRefList.java new file mode 100644 index 0000000..8524115 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceRefList.java @@ -0,0 +1,22 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import java.util.Collection; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ServiceRefList { + /** Number of Service objects */ + public final Integer totalCount; + /** Collection containing all of the returned Service objects */ + public final Collection<ServiceRef> items; + + + @JsonCreator + public ServiceRefList(@JsonProperty("items") Collection<ServiceRef> items, + @JsonProperty("totalCount") Integer totalCount) { + this.items = items; + this.totalCount = totalCount; + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceRequest.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceRequest.java new file mode 100644 index 0000000..036c9ae --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceRequest.java @@ -0,0 +1,57 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import java.util.ArrayList; +import java.util.Collection; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ServiceRequest { + + /** ID of the associated service type */ + public String typeId; + /** Id of the associated VNF that this service is monitoring */ + public String vnfId; + /** The type of the associated VNF that this service is monitoring */ + public String vnfType; + /** Location identifier of the associated VNF that this service is monitoring */ + public String vnfLocation; + /** Reference to a Cloudify deployment */ + public String deploymentRef; + /** Collection of ServiceComponentRequest objects that this service is composed of */ + public Collection<ServiceComponentRequest> components; + + @JsonCreator + public ServiceRequest(@JsonProperty("typeId") String typeId, + @JsonProperty("vnfId") String vnfId, + @JsonProperty("vnfType") String vnfType, + @JsonProperty("vnfLocation") String vnfLocation, + @JsonProperty("deploymentRef") String deploymentRef, + @JsonProperty("components") Collection<ServiceComponentRequest> components) { + this.typeId = typeId; + this.vnfId = vnfId; + this.vnfType = vnfType; + this.vnfLocation = vnfLocation; + this.deploymentRef = deploymentRef; + this.components = components; + } + + public static ServiceRequest from(String typeId, Service service) { + + // Convert the Collection<ServiceComponent> in service to Collection<ServiceComponentRequest> for serviceRequest + final Collection<ServiceComponent> serviceComponents = service.getComponents(); + final Collection<ServiceComponentRequest> serviceComponentRequests = new ArrayList<ServiceComponentRequest> (); + + for (ServiceComponent sc : serviceComponents) { + serviceComponentRequests.add(ServiceComponentRequest.from(sc)); + } + + return new ServiceRequest(typeId, + service.getVnfId(), + service.getVnfType(), + service.getVnfLocation(), + service.getDeploymentRef(), + serviceComponentRequests + ); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceType.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceType.java new file mode 100644 index 0000000..f6f26ba --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceType.java @@ -0,0 +1,340 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; +import java.util.Optional; + +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.dashboard.exceptions.inventory.BlueprintParseException; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ServiceType { + + /** Owner of the ServiceType */ + private final String owner; + + /** Name of the ServiceType */ + private final String typeName; + + /** Version number for this ServiceType */ + private final Integer typeVersion; + + /** String representation of a Cloudify blueprint with unbound variables */ + private final String blueprintTemplate; + + /** controller application name */ + private final String application; + /** onboarding component name */ + private final String component; + /** + * List of service ids used to associate with this ServiceType. + * ServiceTypes with this property as null or empty means they apply for every service id. + */ + private final Collection<String> serviceIds; + + /** Collection of vnfTypes associated with this ServiceType */ + private final Collection<String> vnfTypes; + + /** + * List of service locations used to associate with this ServiceType. + * ServiceTypes with this property as null or empty means they apply for every service location. + */ + private final Collection<String> serviceLocations; + + /** + * Id of service this ServiceType is associated with. + * Value source is from ASDC's notification event's field 'serviceInvariantUUID'. + */ + private final Optional<String> asdcServiceId; + + /** + * Id of vf/vnf instance this ServiceType is associated with. + * Value source is from ASDC's notification event's field 'resourceInvariantUUID'. + */ + private final Optional<String> asdcResourceId; + + /** URL to the ASDC service model */ + private final Optional<String> asdcServiceURL; + + /** Unique identifier for this ServiceType */ + private final Optional<String> typeId; + + /** Link to the ServiceType */ + private final Optional<Link> selfLink; + + /** Creation date of the ServiceType */ + private final Optional<String> created; + + /** Deactivated timestamp for this ServiceType */ + private final Optional<String> deactivated; + + /** Map that stores the inputs for a Blueprint */ + private final Map<String, BlueprintInput> blueprintInputs; + + /** Description of a blueprint */ + private final String blueprintDescription; + + /** internal role based setting */ + private Optional<Boolean> canDeploy; + + public static class Builder { + private final String blueprintTemplate; + private final String owner; + private final String typeName; + private final Integer typeVersion; + private final String application; + private final String component; + + private Optional<String> asdcResourceId = Optional.empty(); + private Optional<String> asdcServiceId = Optional.empty(); + private Optional<String> asdcServiceURL = Optional.empty(); + private Optional<String> created = Optional.empty(); + private Optional<String> deactivated = Optional.empty(); + private Optional<Link> selfLink = Optional.empty(); + private Optional<String> typeId = Optional.empty(); + private Collection<String> serviceIds = new LinkedList<String> (); + private Collection<String> serviceLocations = new LinkedList<String> (); + private Collection<String> vnfTypes = new LinkedList<String> (); + private Map<String, BlueprintInput> blueprintInputs = new HashMap<String, BlueprintInput> (); + private final String blueprintDescription; + private Optional<Boolean> canDeploy = Optional.of(true); + + public Builder(String owner, String typeName, Integer typeVersion, String blueprintTemplate, String blueprintDescription, String application, String component) { + this.owner = owner; + this.typeName = typeName; + this.typeVersion = typeVersion; + this.blueprintTemplate = blueprintTemplate; + this.blueprintDescription = blueprintDescription; + this.application = application; + this.component = component; + } + + public Builder(ServiceType clone) { + this.asdcResourceId = clone.getAsdcResourceId(); + this.asdcServiceId = clone.getAsdcServiceId(); + this.asdcServiceURL = clone.getAsdcServiceURL(); + this.blueprintTemplate = clone.getBlueprintTemplate(); + this.created = clone.getCreated(); + this.deactivated = clone.getDeactivated(); + this.owner = clone.getOwner(); + this.selfLink = clone.getSelfLink(); + this.serviceIds = clone.getServiceIds(); + this.serviceLocations = clone.getServiceLocations(); + this.typeId = clone.getTypeId(); + this.typeName = clone.getTypeName(); + this.typeVersion = clone.getTypeVersion(); + this.vnfTypes = clone.getVnfTypes(); + this.blueprintInputs = clone.getBlueprintInputs(); + this.blueprintDescription = clone.getBlueprintDescription(); + this.canDeploy = clone.getCanDeploy(); + this.application = clone.getApplication(); + this.component = clone.getComponent(); + } + + public Builder typeId(String typeId) { + this.typeId = Optional.of(typeId); + return this; + } + + public ServiceType build() { + return new ServiceType(this); + } + } + + private ServiceType(Builder builder) { + this.owner = builder.owner; + this.typeName = builder.typeName; + this.typeVersion = builder.typeVersion; + this.blueprintTemplate = builder.blueprintTemplate; + this.application = builder.application; + this.component = builder.component; + this.serviceIds = builder.serviceIds; + this.vnfTypes = builder.vnfTypes; + this.serviceLocations = builder.serviceLocations; + + this.asdcServiceId = builder.asdcServiceId; + this.asdcResourceId = builder.asdcResourceId; + this.asdcServiceURL = builder.asdcServiceURL; + this.typeId = builder.typeId; + this.selfLink = builder.selfLink; + this.created = builder.created; + this.deactivated = builder.deactivated; + this.blueprintInputs = builder.blueprintInputs; + this.blueprintDescription = builder.blueprintDescription; + this.canDeploy = builder.canDeploy; + } + + @JsonCreator + public ServiceType(@JsonProperty("owner") String owner, + @JsonProperty("typeName") String typeName, + @JsonProperty("typeVersion") Integer typeVersion, + @JsonProperty("blueprintTemplate") String blueprintTemplate, + @JsonProperty("application") String application, + @JsonProperty("component") String component, + @JsonProperty("serviceIds") Collection<String> serviceIds, + @JsonProperty("vnfTypes") Collection<String> vnfTypes, + @JsonProperty("serviceLocations") Collection<String> serviceLocations, + @JsonProperty("asdcServiceId") String asdcServiceId, + @JsonProperty("asdcResourceId") String asdcResourceId, + @JsonProperty("asdcServiceURL") String asdcServiceURL, + @JsonProperty("typeId") String typeId, + @JsonProperty("selfLink") Link selfLink, + @JsonProperty("created") String created, + @JsonProperty("deactivated") String deactivated, + @JsonProperty("canDeploy") Boolean canDeploy) { + + if (owner == null) throw new IllegalArgumentException("owner cannot be null"); + if (typeName == null) throw new IllegalArgumentException("typeName cannot be null"); + if (typeVersion == null) throw new IllegalArgumentException("typeVersion cannot be null"); + if (blueprintTemplate == null) throw new IllegalArgumentException("blueprintTemplate cannot be null"); + + this.owner = owner; + this.typeName = typeName; + this.typeVersion = typeVersion; + this.blueprintTemplate = blueprintTemplate; + this.application = application; + this.component = component; + + this.serviceIds = (serviceIds == null) ? new LinkedList<String> () : serviceIds; + this.vnfTypes = (vnfTypes == null) ? new LinkedList<String> () : vnfTypes; + this.serviceLocations = (serviceLocations == null) ? new LinkedList<String> () : serviceLocations; + + this.asdcServiceId = Optional.ofNullable(asdcServiceId); + this.asdcResourceId = Optional.ofNullable(asdcResourceId); + this.asdcServiceURL = Optional.ofNullable(asdcServiceURL); + this.typeId = Optional.ofNullable(typeId); + this.selfLink = Optional.ofNullable(selfLink); + this.created = Optional.ofNullable(created); + this.deactivated = Optional.ofNullable(deactivated); + this.canDeploy = Optional.of(false); + try { + this.blueprintInputs = Blueprint.parse(blueprintTemplate).getInputs(); + this.blueprintDescription = Blueprint.parse(blueprintTemplate).getDescription(); + } catch (BlueprintParseException e) { + throw new RuntimeException("Error while parsing blueprint template for " + this.typeName + " " + this.typeVersion, e); + } + } + + public String getOwner() { + return owner; + } + + public String getTypeName() { + return typeName; + } + + public Integer getTypeVersion() { + return typeVersion; + } + + public String getBlueprintTemplate() { + return blueprintTemplate; + } + + public Collection<String> getServiceIds() { + return serviceIds; + } + + public Collection<String> getVnfTypes() { + return vnfTypes; + } + + public Collection<String> getServiceLocations() { + return serviceLocations; + } + + public Optional<String> getAsdcServiceId() { + return asdcServiceId; + } + + public Optional<String> getAsdcResourceId() { + return asdcResourceId; + } + + public Optional<String> getAsdcServiceURL() { + return asdcServiceURL; + } + + public Optional<String> getTypeId() { + return typeId; + } + + public Optional<Link> getSelfLink() { + return selfLink; + } + + public Optional<String> getCreated() { + return created; + } + + public Optional<String> getDeactivated() { + return deactivated; + } + + public Map<String, BlueprintInput> getBlueprintInputs() { + return blueprintInputs; + } + + public String getBlueprintDescription() { + return blueprintDescription; + } + + public Optional<Boolean> getCanDeploy() { + return canDeploy; + } + + public String getApplication() { + return application; + } + + public String getComponent() { + return component; + } + + public void setCanDeploy(Optional<Boolean> canDeploy) { + this.canDeploy = canDeploy; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ServiceType)) return false; + + final ServiceType serviceType = (ServiceType) obj; + + return (serviceType.getAsdcResourceId().equals(getAsdcResourceId()) && + serviceType.getAsdcServiceId().equals(getAsdcServiceId()) && + serviceType.getAsdcServiceURL().equals(getAsdcServiceURL()) && + serviceType.getBlueprintTemplate().equals(getBlueprintTemplate()) && + serviceType.getCreated().equals(getCreated()) && + serviceType.getDeactivated().equals(getDeactivated()) && + serviceType.getOwner().equals(getOwner()) && + serviceType.getSelfLink().equals(getSelfLink()) && + serviceType.getServiceIds().equals(getServiceIds()) && + serviceType.getServiceLocations().equals(getServiceLocations()) && + serviceType.getTypeId().equals(getTypeId()) && + serviceType.getTypeName().equals(getTypeName()) && + serviceType.getTypeVersion().equals(getTypeVersion()) && + serviceType.getVnfTypes().equals(getVnfTypes()) && + serviceType.getApplication().equals(getApplication()) && + serviceType.getComponent().equals(getComponent())); + } + + // Used for back end search, only searches the fields displayed in the front end. + public boolean contains(String searchString) { + if (StringUtils.containsIgnoreCase(this.getOwner(), searchString) || + StringUtils.containsIgnoreCase(this.getBlueprintDescription(), searchString) || + StringUtils.containsIgnoreCase(this.getTypeId().get(), searchString) || + StringUtils.containsIgnoreCase(this.getTypeName(), searchString) || + StringUtils.containsIgnoreCase(Integer.toString(this.getTypeVersion()), searchString) || + StringUtils.containsIgnoreCase(this.getCreated().get(), searchString) || + StringUtils.containsIgnoreCase(this.getComponent(), searchString) || + StringUtils.containsIgnoreCase(this.getApplication(), searchString) ) { + return true; + } + return false; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceTypeList.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceTypeList.java new file mode 100644 index 0000000..28cddf6 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceTypeList.java @@ -0,0 +1,40 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import java.util.Collection; + +import org.onap.ccsdk.dashboard.model.ECTransportModel; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ServiceTypeList extends ECTransportModel { + + /** Number of ServiceType objects */ + public final Integer totalCount; + /** Collection containing all of the returned ServiceType objects */ + public final Collection<ServiceType> items; + /** Links to the previous and next page of items */ + public final PaginationLinks paginationLinks; + + @JsonCreator + public ServiceTypeList(@JsonProperty("items") Collection<ServiceType> items, + @JsonProperty("totalCount") Integer totalCount, + @JsonProperty("links") PaginationLinks paginationLinks) { + this.items = items; + this.totalCount = totalCount; + this.paginationLinks = paginationLinks; + } + + /** InlineResponse200Links */ + public static final class PaginationLinks { + public final Link previousLink; + public final Link nextLink; + + @JsonCreator + public PaginationLinks (@JsonProperty("previousLink") Link previousLink, + @JsonProperty("nextLink") Link nextLink) { + this.previousLink = previousLink; + this.nextLink = nextLink; + } + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceTypeQueryParams.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceTypeQueryParams.java new file mode 100644 index 0000000..f9d1b6f --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceTypeQueryParams.java @@ -0,0 +1,157 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +public class ServiceTypeQueryParams { + + private final String typeName; + private final Boolean onlyLatest; + private final Boolean onlyActive; + private final String vnfType; + private final String serviceId; + private final String serviceLocation; + private final String asdcServiceId; + private final String asdcResourceId; + private final String application; + private final String component; + + // Non-instantiable + private ServiceTypeQueryParams() { + this.typeName = null; + this.onlyLatest = null; + this.onlyActive = null; + this.vnfType = null; + this.serviceId = null; + this.serviceLocation = null; + this.asdcServiceId = null; + this.asdcResourceId = null; + this.application = null; + this.component = null; + } + + private ServiceTypeQueryParams(String typeName, + Boolean onlyLatest, + Boolean onlyActive, + String vnfType, + String serviceId, + String serviceLocation, + String asdcServiceId, + String asdcResourceId, + String application, + String component) { + this.typeName = typeName; + this.onlyLatest = onlyLatest; + this.onlyActive = onlyActive; + this.vnfType = vnfType; + this.serviceId = serviceId; + this.serviceLocation = serviceLocation; + this.asdcServiceId = asdcServiceId; + this.asdcResourceId = asdcResourceId; + this.application = application; + this.component = component; + } + + public static class Builder { + private String typeName; + private Boolean onlyLatest; + private Boolean onlyActive; + private String vnfType; + private String serviceId; + private String serviceLocation; + private String asdcServiceId; + private String asdcResourceId; + private String application; + private String component; + + public Builder typeName(String typeName) { + this.typeName = typeName; + return this; + } + + public Builder onlyLatest(Boolean onlyLatest) { + this.onlyLatest = onlyLatest; + return this; + } + + public Builder onlyActive(Boolean onlyActive) { + this.onlyActive = onlyActive; + return this; + } + + public Builder vnfType(String vnfType) { + this.vnfType = vnfType; + return this; + } + + public Builder serviceId(String serviceId) { + this.serviceId = serviceId; + return this; + } + + public Builder serviceLocation(String serviceLocation) { + this.serviceLocation = serviceLocation; + return this; + } + + public Builder asdcServiceId(String asdcServiceId) { + this.asdcServiceId = asdcServiceId; + return this; + } + + public Builder asdcResourceId(String asdcResourceId) { + this.asdcResourceId = asdcResourceId; + return this; + } + + public ServiceTypeQueryParams build() { + return new ServiceTypeQueryParams(typeName, + onlyLatest, + onlyActive, + vnfType, + serviceId, + serviceLocation, + asdcServiceId, + asdcResourceId, + application, + component); + } + } + + public String getTypeName() { + return this.typeName; + } + + public Boolean getOnlyLatest() { + return this.onlyLatest; + } + + public Boolean getOnlyActive() { + return this.onlyActive; + } + + public String getVnfType() { + return this.vnfType; + } + + public String getServiceId() { + return this.serviceId; + } + + public String getServiceLocation() { + return this.serviceLocation; + } + + public String getAsdcServiceId() { + return this.asdcServiceId; + } + + public String getAsdcResourceId() { + return this.asdcResourceId; + } + + public String getApplication() { + return this.application; + } + + public String getComponent() { + return this.component; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceTypeRequest.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceTypeRequest.java new file mode 100644 index 0000000..42dd018 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceTypeRequest.java @@ -0,0 +1,115 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import java.util.Collection; +import java.util.Optional; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ServiceTypeRequest { + + /** Owner of the Service Type */ + public String owner; + /** Name of the Service Type */ + public String typeName; + /** Version number of the Service Type */ + public Integer typeVersion; + /** String representation of a Cloudify blueprint with unbound variables */ + public String blueprintTemplate; + /** controller application name */ + public String application; + /** onboarding component name */ + public String component; + /** + * Collection of service ids used to associate with the Service Type. + * Service Types with this property as null or empty means they apply for every service id. + */ + public Collection<String> serviceIds; + /** Collection of vnfTypes associated with the Service Type */ + public Collection<String> vnfTypes; + /** + * Collection of service locations that are used to associate with the Service Type. + * Service Types with this property as null or empty means they apply for every service location. + */ + public Collection<String> serviceLocations; + /** + * Id of the service this Service Type is associated with. + * Value source is from ASDC's notification event's field 'serviceInvariantUUID'." + * */ + public Optional<String> asdcServiceId; + /** + * Id of the vf/vnf instance this Service Type is associated with. + * Value source is from ASDC's notification event's field 'resourceInvariantUUID'." + */ + public Optional<String> asdcResourceId; + /** URL to the ASDC Service Model */ + public Optional<String> asdcServiceURL; + + @JsonCreator + public ServiceTypeRequest (@JsonProperty("owner") String owner, + @JsonProperty("typeName") String typeName, + @JsonProperty("typeVersion") Integer typeVersion, + @JsonProperty("blueprintTemplate") String blueprintTemplate, + @JsonProperty("application") String application, + @JsonProperty("component") String component, + @JsonProperty("serviceIds") Collection<String> serviceIds, + @JsonProperty("vnfTypes") Collection<String> vnfTypes, + @JsonProperty("serviceLocations") Collection<String> serviceLocations, + @JsonProperty("asdcServiceId") String asdcServiceId, + @JsonProperty("asdcResourceId") String asdcResourceId, + @JsonProperty("asdcServiceURL") String asdcServiceURL) { + this(owner, typeName, typeVersion, blueprintTemplate, + application, component, + serviceIds, vnfTypes, serviceLocations, + Optional.ofNullable(asdcServiceId), + Optional.ofNullable(asdcResourceId), + Optional.ofNullable(asdcServiceURL)); + } + + public ServiceTypeRequest(String owner, + String typeName, + Integer typeVersion, + String blueprintTemplate, + String application, + String component, + Collection<String> serviceIds, + Collection<String> vnfTypes, + Collection<String> serviceLocations, + Optional<String> asdcServiceId, + Optional<String> asdcResourceId, + Optional<String> asdcServiceURL) { + this.owner = owner; + this.typeName = typeName; + this.typeVersion = typeVersion; + this.blueprintTemplate = blueprintTemplate; + this.application = application; + this.component = component; + this.serviceIds = serviceIds; + this.vnfTypes = vnfTypes; + this.serviceLocations = serviceLocations; + this.asdcServiceId = asdcServiceId; + this.asdcResourceId = asdcResourceId; + this.asdcServiceURL = asdcServiceURL; + } + + public static ServiceTypeRequest from(ServiceType serviceType) { + return new ServiceTypeRequest( + serviceType.getOwner(), + serviceType.getTypeName(), + serviceType.getTypeVersion(), + serviceType.getBlueprintTemplate(), + serviceType.getApplication(), + serviceType.getComponent(), + serviceType.getServiceIds(), + serviceType.getVnfTypes(), + serviceType.getServiceLocations(), + serviceType.getAsdcServiceId(), + serviceType.getAsdcResourceId(), + serviceType.getAsdcServiceURL() + ); + } + + public String getBlueprintTemplate() { + return this.blueprintTemplate; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceTypeServiceMap.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceTypeServiceMap.java new file mode 100644 index 0000000..292773a --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceTypeServiceMap.java @@ -0,0 +1,26 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ServiceTypeServiceMap { + + private final String serviceTypeId; + + private final ServiceRefList serviceRefList; + + @JsonCreator + public ServiceTypeServiceMap (@JsonProperty("serviceTypeId") String serviceTypeId, + @JsonProperty("created") ServiceRefList serviceRefList) { + this.serviceTypeId = serviceTypeId; + this.serviceRefList = serviceRefList; + } + + public String getServiceTypeId() { + return serviceTypeId; + } + + public ServiceRefList getServiceRefList() { + return serviceRefList; + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceTypeUploadRequest.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceTypeUploadRequest.java new file mode 100644 index 0000000..3ef334f --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/inventory/ServiceTypeUploadRequest.java @@ -0,0 +1,48 @@ +package org.onap.ccsdk.dashboard.model.inventory; + +import java.util.Collection; +import java.util.Optional; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ServiceTypeUploadRequest { + + /** Owner of the Service Type */ + public String owner; + /** Name of the Service Type */ + public String typeName; + /** Version number of the Service Type */ + public Integer typeVersion; + /** String representation of a Cloudify blueprint with unbound variables */ + public String blueprintTemplate; + /** Application controller name */ + public String application; + /** onboarding component name */ + public String component; + + @JsonCreator + public ServiceTypeUploadRequest(@JsonProperty("owner") String owner, + @JsonProperty("typeName") String typeName, + @JsonProperty("typeVersion") Integer typeVersion, + @JsonProperty("blueprintTemplate") String blueprintTemplate, + @JsonProperty("application") String application, + @JsonProperty("component") String component ) { + this.owner = owner; + this.typeName = typeName; + this.typeVersion = typeVersion; + this.blueprintTemplate = blueprintTemplate; + this.application = application; + this.component = component; + } + + public static ServiceTypeUploadRequest from(ServiceType serviceType) { + return new ServiceTypeUploadRequest(serviceType.getOwner(), serviceType.getTypeName(), + serviceType.getTypeVersion(), serviceType.getBlueprintTemplate(), + serviceType.getApplication(), serviceType.getComponent()); + } + public String getBlueprintTemplate() { + return this.blueprintTemplate; + + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/CloudifyClient.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/CloudifyClient.java new file mode 100644 index 0000000..56fb9ee --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/CloudifyClient.java @@ -0,0 +1,247 @@ +/** + * + */ +package org.onap.ccsdk.dashboard.rest; + +import java.util.Map; + +import org.onap.ccsdk.dashboard.model.CloudifyBlueprintContent; +import org.onap.ccsdk.dashboard.model.CloudifyBlueprintList; +import org.onap.ccsdk.dashboard.model.CloudifyBlueprintUpload; +import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenantList; +import org.onap.ccsdk.dashboard.model.CloudifyDeploymentList; +import org.onap.ccsdk.dashboard.model.CloudifyDeploymentRequest; +import org.onap.ccsdk.dashboard.model.CloudifyDeploymentUpdateRequest; +import org.onap.ccsdk.dashboard.model.CloudifyDeploymentUpdateResponse; +import org.onap.ccsdk.dashboard.model.CloudifyEventList; +import org.onap.ccsdk.dashboard.model.CloudifyExecution; +import org.onap.ccsdk.dashboard.model.CloudifyExecutionList; +import org.onap.ccsdk.dashboard.model.CloudifyExecutionRequest; +import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceIdList; +import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceList; +import org.onap.ccsdk.dashboard.model.CloudifySecret; +import org.onap.ccsdk.dashboard.model.CloudifyTenantList; + +/** + * @author rp5662 + * + */ +public interface CloudifyClient { + + /** + * Get the execution logs + * + */ + public CloudifyEventList getEventlogs(String execution_id, String tenant); + /** + * Gets the list of Cloudify tenants. + * + * @return CloudifyBlueprintList + */ + public CloudifyTenantList getTenants(); + + /** + * 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 CloudifyExecution cancelExecution(final String executionId, Map<String, String> parameters, + final String tenant); + + /** + * Get the node-instance-id. + * + * @param deploymentId + * deployment ID + * @param nodeId + * node ID + * @param tenant + * tenant name + * @return CloudifyNodeInstanceList + */ + public CloudifyNodeInstanceIdList getNodeInstanceId(String deploymentId, String nodeId, String tenant); + /** + * Gets all the deployments with include filters for tenant name + * + * @return List of CloudifyDeployedTenant objects + */ + public CloudifyDeployedTenantList getTenantInfoFromDeploy(String tenant); + + /** + * Get the node-instance-id. + * + * @param deploymentId + * deployment ID + * @param tenant + * tenant name + * + * @return CloudifyNodeInstanceList + */ + public CloudifyNodeInstanceIdList getNodeInstanceId(String id, String tenant); + + /** + * Query execution information for a deployment ID and execution ID passed as inputs + * + * @param executionId + * @param deploymentId + * @return + */ + public CloudifyExecutionList getExecution(String executionId, String deploymentId); + + /** + * Initiate a deployment update in cloudify + * + * @param execution + * @return + */ + public CloudifyDeploymentUpdateResponse updateDeployment(CloudifyDeploymentUpdateRequest execution); + + /** + * Query execution information for a deployment ID passed as input + * + * @param deploymentId + * @param tenant + * @return + */ + public CloudifyExecutionList getExecutions(final String deploymentId, final String tenant); + + /** + * Query execution summary for a deployment ID passed as input + * + * @param deploymentId + * @param tenant + * @return + */ + public CloudifyExecutionList getExecutionsSummary(final String deploymentId, final String tenant); + + /** + * Get cloudify node-instance-revisions. + * + * @param deploymentId + * deployment ID + * @param nodeId + * node ID + * @param tenant + * tenant name + * @return CloudifyNodeInstanceList + */ + public CloudifyNodeInstanceList getNodeInstanceVersion(String deploymentId, String nodeId, String tenant); + + /** + * Get cloudify node-instance-revisions + * + * @param bp_id + * @param tenant + * @return + */ + public CloudifyNodeInstanceList getNodeInstanceVersion(String bp_id, String tenant); + + /** + * Start Uninstall execution workflow in cloudify + * @param id + * @param ignoreLiveNodes + * @return + */ + public int deleteDeployment(String id, boolean ignoreLiveNodes); + + /** + * Start install execution workflow in cloudify + * + * @param deployment + * @return + */ + public CloudifyDeploymentList createDeployment(CloudifyDeploymentRequest deployment); + + /** + * Query deployment object from cloudify + * + * @param id + * @param tenant + * @return + */ + public CloudifyDeploymentList getDeployment(String id, String tenant); + + /** + * Query deployment object from cloudify + * + * @param id + * @return + */ + public CloudifyDeploymentList getDeployment(String id); + /** + * Query deployments from cloudify + * + */ + public CloudifyDeploymentList getDeployments(); + + /** + * Remove blueprint referred by ID from cloudify + * + * @param id + * @return + */ + public int deleteBlueprint(String id); + + /** + * Upload blueprint into cloudify + * + * @param blueprint + * @return + */ + public CloudifyBlueprintList uploadBlueprint(CloudifyBlueprintUpload blueprint); + + /** + * View blueprint YAML text + * + * @param id + * @return + */ + public CloudifyBlueprintContent viewBlueprint(String id); + + /** + * Query a blueprint object matching the blueprint ID in cloudify + * + * @param id + * @param tenant + * @return + */ + public CloudifyBlueprintList getBlueprint(String id, String tenant); + /** + * Query all the blueprints in cloudify + * @return + */ + public CloudifyBlueprintList getBlueprints(); + + /** + * Query deployment inputs for a deployment ID in the cloudify tenant + * + * @param id + * @param tenant + * @return + */ + public CloudifyDeploymentList getDeploymentInputs(String id, String tenant); + + /** + * Query a secret object matching the input secret name in the cloudify tenant + * + * @param secretName + * @param tenant + * @return + */ + public CloudifySecret getSecret(String secretName, String tenant); +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/CloudifyMockClientImpl.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/CloudifyMockClientImpl.java new file mode 100644 index 0000000..a433908 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/CloudifyMockClientImpl.java @@ -0,0 +1,205 @@ +package org.onap.ccsdk.dashboard.rest; + +import java.io.InputStream; +import java.util.Map; +import java.util.Scanner; + +import org.onap.ccsdk.dashboard.model.CloudifyBlueprintContent; +import org.onap.ccsdk.dashboard.model.CloudifyBlueprintList; +import org.onap.ccsdk.dashboard.model.CloudifyBlueprintUpload; +import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenantList; +import org.onap.ccsdk.dashboard.model.CloudifyDeploymentList; +import org.onap.ccsdk.dashboard.model.CloudifyDeploymentRequest; +import org.onap.ccsdk.dashboard.model.CloudifyDeploymentUpdateRequest; +import org.onap.ccsdk.dashboard.model.CloudifyDeploymentUpdateResponse; +import org.onap.ccsdk.dashboard.model.CloudifyEventList; +import org.onap.ccsdk.dashboard.model.CloudifyExecution; +import org.onap.ccsdk.dashboard.model.CloudifyExecutionList; +import org.onap.ccsdk.dashboard.model.CloudifyExecutionRequest; +import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceIdList; +import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceList; +import org.onap.ccsdk.dashboard.model.CloudifySecret; +import org.onap.ccsdk.dashboard.model.CloudifyTenantList; +import org.onap.ccsdk.dashboard.model.ECTransportModel; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Provides mock implementations that return contents of files on the classpath. + */ +public class CloudifyMockClientImpl implements CloudifyClient { + + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CloudifyMockClientImpl.class); + + /** + * For mock outputs + */ + private final ObjectMapper objectMapper = new ObjectMapper(); + + private String getMockDataContent(final String path) { + String result = null; + try { + InputStream is = getClass().getResourceAsStream(path); + if (is == null) + throw new Exception("Failed to find resource at path " + path); + Scanner scanner = new Scanner(is, "UTF-8"); + result = scanner.useDelimiter("\\A").next(); + scanner.close(); + is.close(); + } catch (Exception ex) { + logger.error("getMockDataContent failed", ex); + throw new RuntimeException(ex); + } + return result; + } + + /** + * Creates an input stream using the specified path and requests the mapper + * create an object of the specified type. + * + * @param modelClass + * Model class + * @param path + * Path to classpath resource + * @return Instance of modelClass + */ + private ECTransportModel getMockData(final Class<? extends ECTransportModel> modelClass, final String path) { + ECTransportModel result = null; + String json = getMockDataContent(path); + try { + result = (ECTransportModel) objectMapper.readValue(json, modelClass); + } catch (Exception ex) { + logger.error("getMockData failed", ex); + throw new RuntimeException(ex); + } + return result; + } + + @Override + public CloudifyTenantList getTenants() { + return (CloudifyTenantList) getMockData(CloudifyTenantList.class, "/tenantsList.json"); + } + + @Override + public CloudifyDeployedTenantList getTenantInfoFromDeploy(String tenant) { + return (CloudifyDeployedTenantList) getMockData(CloudifyDeployedTenantList.class, "/serviceTenantList.json"); + + } + + @Override + public CloudifyNodeInstanceIdList getNodeInstanceId(String deploymentId, String nodeId, String tenant) { + return null; + } + + @Override + public CloudifyNodeInstanceIdList getNodeInstanceId(String deploymentId, String tenant) { + return null; + } + + @Override + public CloudifyNodeInstanceList getNodeInstanceVersion(String bpId, String tenant) { + return null; + } + @Override + public CloudifyNodeInstanceList getNodeInstanceVersion(String deploymentId, String nodeId, String tenant) { + return null; + } + + @Override + public CloudifyDeploymentUpdateResponse updateDeployment(CloudifyDeploymentUpdateRequest execution) { + return null; + } + @Override + public CloudifyEventList getEventlogs(String executionId, String tenant) { + return null; + } + + public CloudifyDeploymentList createDeployment(CloudifyDeploymentRequest deployment) { + logger.debug(EELFLoggerDelegate.debugLogger, "createDeployment: {}", deployment.toString()); + return new CloudifyDeploymentList(null, null); + } + + @Override + public CloudifyExecutionList getExecutions(final String deploymentId, final String tenant) { + return (CloudifyExecutionList) getMockData(CloudifyExecutionList.class, "/listExecutionForDeploymentID.json"); + } + + @Override + public CloudifyExecutionList getExecutionsSummary(final String deploymentId, final String tenant) { + return (CloudifyExecutionList) getMockData(CloudifyExecutionList.class, "/listExecutionForDeploymentID.json"); + } + + @Override + public CloudifyExecutionList getExecution(String executionId, String deploymentId) { + return (CloudifyExecutionList) getMockData(CloudifyExecutionList.class, "/listExecutionForDeploymentID.json"); + } + + @Override + public CloudifyExecution startExecution(CloudifyExecutionRequest execution) { + logger.debug(EELFLoggerDelegate.debugLogger, "startExecution: {}", execution.toString()); + return new CloudifyExecution(null, null, null, null, null, null, null, null, null, null,null, null); + } + + @Override + public CloudifyExecution cancelExecution(final String executionId, Map<String, String> parameters, final String tenant) { + return null; + } + + public int deleteDeployment(String id, boolean ignoreLiveNodes) { + return 0; + } + public CloudifyDeploymentList getDeployment(String id, String tenant) { + return null; + } + public CloudifyDeploymentList getDeployment(String id) { + return null; + } + public CloudifyDeploymentList getDeployments() { + return null; + } + public int deleteBlueprint(String id) { + return 0; + } + public CloudifyBlueprintList uploadBlueprint(CloudifyBlueprintUpload blueprint) { + return null; + } + public CloudifyBlueprintContent viewBlueprint(String id) { + return null; + } + public CloudifyBlueprintList getBlueprint(String id, String tenant) { + return null; + } + public CloudifyBlueprintList getBlueprints() { + return null; + } + + /** + * Get the a cloudify secret + * + * @return CloudifySecret + */ + @Override + public CloudifySecret getSecret(String secretName, String tenant) { + return null; + } + + /** + * Simple test + * + * @param args + * blueprint ID + * @throws Exception + * On any failure + */ + public static void main(String[] args) throws Exception { + System.out.println("Testing paths and parsing mock data"); + } + + @Override + public CloudifyDeploymentList getDeploymentInputs(String id, String tenant) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/CloudifyRestClientImpl.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/CloudifyRestClientImpl.java new file mode 100644 index 0000000..1854577 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/CloudifyRestClientImpl.java @@ -0,0 +1,350 @@ +package org.onap.ccsdk.dashboard.rest; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Map; + +import org.json.JSONObject; +import org.onap.ccsdk.dashboard.model.CloudifyBlueprintContent; +import org.onap.ccsdk.dashboard.model.CloudifyBlueprintList; +import org.onap.ccsdk.dashboard.model.CloudifyBlueprintUpload; +import org.onap.ccsdk.dashboard.model.CloudifyDeployedTenantList; +import org.onap.ccsdk.dashboard.model.CloudifyDeploymentList; +import org.onap.ccsdk.dashboard.model.CloudifyDeploymentRequest; +import org.onap.ccsdk.dashboard.model.CloudifyDeploymentUpdateRequest; +import org.onap.ccsdk.dashboard.model.CloudifyDeploymentUpdateResponse; +import org.onap.ccsdk.dashboard.model.CloudifyEventList; +import org.onap.ccsdk.dashboard.model.CloudifyExecution; +import org.onap.ccsdk.dashboard.model.CloudifyExecutionList; +import org.onap.ccsdk.dashboard.model.CloudifyExecutionRequest; +import org.onap.ccsdk.dashboard.model.CloudifyNodeIdList; +import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceIdList; +import org.onap.ccsdk.dashboard.model.CloudifyNodeInstanceList; +import org.onap.ccsdk.dashboard.model.CloudifySecret; +import org.onap.ccsdk.dashboard.model.CloudifyTenantList; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class CloudifyRestClientImpl extends RestClientBase implements CloudifyClient { + + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CloudifyRestClientImpl.class); + private final String baseUrl; + private final ObjectMapper objectMapper = new ObjectMapper(); + + private static final String BLUEPRINTS = "blueprints"; + private static final String VIEW_BLUEPRINTS = "viewblueprints"; + private static final String DEPLOYMENTS = "deployments"; + private static final String EXECUTIONS = "executions"; + private static final String TENANTS = "tenants"; + private static final String NODES = "nodes"; + private static final String NODE_INSTANCES = "node-instances"; + private static final String UPDATE_DEPLOYMENT = "update-deployment"; + private static final String SECRETS = "secrets"; + private static final String EVENTS = "events"; + private static final String TENANT = "tenant_name"; + + public CloudifyRestClientImpl(String webapiUrl, String user, String pass) { + super(); + if (webapiUrl == null) + throw new IllegalArgumentException("Null URL not permitted"); + + URL url = null; + String urlScheme = "http"; + try { + url = new URL(webapiUrl); + baseUrl = url.toExternalForm(); + } catch (MalformedURLException ex) { + throw new RuntimeException("Failed to parse URL", ex); + } + + urlScheme = webapiUrl.split(":")[0]; + createRestTemplate(url, user, pass, urlScheme); + } + + @Override + public CloudifyTenantList getTenants() { + String url = buildUrl(new String[] { baseUrl, TENANTS }, null); + logger.debug(EELFLoggerDelegate.debugLogger, "getTenants: url {}", url); + ResponseEntity<CloudifyTenantList> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<CloudifyTenantList>() { + }); + return response.getBody(); + } + + @Override + public CloudifyEventList getEventlogs(String executionId, String tenant) { + String url = buildUrl(new String[] { baseUrl, EVENTS }, + new String[] { "execution_id", executionId }); + logger.debug(EELFLoggerDelegate.debugLogger, "getEventlogs: url {}", url); + HttpEntity<String> entity = getTenantHeader(tenant); + ResponseEntity<CloudifyEventList> response = restTemplate.exchange(url, HttpMethod.GET, entity, + new ParameterizedTypeReference<CloudifyEventList>() { + }); + return response.getBody(); + } + + @Override + public CloudifyNodeInstanceIdList getNodeInstanceId(String deploymentId, String nodeId, String tenant) { + String url = buildUrl(new String[] { baseUrl, NODE_INSTANCES }, new String[] + { "deployment_id", deploymentId, "node_id", nodeId, "_include", "id"}); + logger.debug(EELFLoggerDelegate.debugLogger, "getNodeInstanceId: url {}", url); + HttpEntity<String> entity = getTenantHeader(tenant); + ResponseEntity<CloudifyNodeInstanceIdList> response = restTemplate.exchange(url, HttpMethod.GET, entity, + new ParameterizedTypeReference<CloudifyNodeInstanceIdList>() { + }); + return response.getBody(); + } + + @Override + public CloudifyNodeInstanceList getNodeInstanceVersion(String deploymentId, String nodeId, String tenant) { + String url = buildUrl(new String[] { baseUrl, NODE_INSTANCES }, new String[] + { "deployment_id", deploymentId, "node_id", nodeId, "_include", "runtime_properties,id"}); + logger.debug(EELFLoggerDelegate.debugLogger, "getNodeInstanceVersion: url {}", url); + HttpEntity<String> entity = getTenantHeader(tenant); + ResponseEntity<CloudifyNodeInstanceList> response = restTemplate.exchange(url, HttpMethod.GET, entity, + new ParameterizedTypeReference<CloudifyNodeInstanceList>() { + }); + return response.getBody(); + } + + @Override + public CloudifyNodeInstanceList getNodeInstanceVersion(String bpId, String tenant) { + String url = buildUrl(new String[] { baseUrl, NODES }, + new String[] { "deployment_id", bpId, "type", "onap.nodes.component", "_include", "id"}); + logger.debug(EELFLoggerDelegate.debugLogger, "getNodeInstanceId: url {}", url); + HttpEntity<String> entity = getTenantHeader(tenant); + ResponseEntity<CloudifyNodeIdList> response = restTemplate.exchange(url, HttpMethod.GET, entity, + new ParameterizedTypeReference<CloudifyNodeIdList>() { + }); + CloudifyNodeIdList result = response.getBody(); + String nodeId = result.items.get(0).id; + return getNodeInstanceVersion(bpId, nodeId, tenant); + } + + @Override + public CloudifyNodeInstanceIdList getNodeInstanceId(final String bpId, String tenant) { + // GET /api/v3.1/nodes?deployment_id=clamp_967&type=onap.nodes.component&_include=id + String url = buildUrl(new String[] { baseUrl, NODES }, + new String[] { "deployment_id", bpId, "type", "onap.nodes.component", "_include", "id" }); + logger.debug(EELFLoggerDelegate.debugLogger, "getNodeInstanceId: url {}", url); + HttpEntity<String> entity = getTenantHeader(tenant); + ResponseEntity<CloudifyNodeIdList> response = restTemplate.exchange(url, HttpMethod.GET, entity, + new ParameterizedTypeReference<CloudifyNodeIdList>() { + }); + CloudifyNodeIdList result = response.getBody(); + String nodeId = result.items.get(0).id; + return getNodeInstanceId(bpId, nodeId, tenant); + } + + @Override + public CloudifyDeployedTenantList getTenantInfoFromDeploy(String tenant) { + String url = buildUrl(new String[] { baseUrl, DEPLOYMENTS }, new String[] {"_include", "id,blueprint_id,tenant_name" }); + logger.debug(EELFLoggerDelegate.debugLogger, "getTenantInfoFromDeploy: url {}", url); + HttpEntity<String> entity = getTenantHeader(tenant); + + ResponseEntity<CloudifyDeployedTenantList> response = restTemplate.exchange(url, HttpMethod.GET, entity, + new ParameterizedTypeReference<CloudifyDeployedTenantList>() { + }); + return response.getBody(); + } + + @Override + public CloudifyExecutionList getExecutions(final String deploymentId, final String tenant) { + String url = buildUrl(new String[] { baseUrl, EXECUTIONS }, new String[] { "deployment_id", deploymentId }); + logger.debug(EELFLoggerDelegate.debugLogger, "getExecutions: url {}", url); + HttpEntity<String> entity = getTenantHeader(tenant); + ResponseEntity<CloudifyExecutionList> response = restTemplate.exchange(url, HttpMethod.GET, entity, + new ParameterizedTypeReference<CloudifyExecutionList>() { + }); + return response.getBody(); + } + + @Override + public CloudifyExecutionList getExecutionsSummary(final String deploymentId, final String tenant) { + String url = buildUrl(new String[] { baseUrl, EXECUTIONS }, new String[] { "deployment_id", deploymentId, "_include", "deployment_id,id,status,workflow_id,tenant_name,created_at"}); + logger.debug(EELFLoggerDelegate.debugLogger, "getExecutions: url {}", url); + HttpEntity<String> entity = getTenantHeader(tenant); + ResponseEntity<CloudifyExecutionList> response = restTemplate.exchange(url, HttpMethod.GET, entity, + new ParameterizedTypeReference<CloudifyExecutionList>() { + }); + return response.getBody(); + } + + @Override + public CloudifyExecutionList getExecution(String executionId, String deploymentId) { + String url = buildUrl(new String[] { baseUrl, EXECUTIONS, executionId }, + new String[] { "deployment_id", deploymentId }); + logger.debug(EELFLoggerDelegate.debugLogger, "getExecution: url {}", url); + + ResponseEntity<CloudifyExecutionList> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<CloudifyExecutionList>() { + }); + return response.getBody(); + } + + @Override + public CloudifyExecution startExecution(CloudifyExecutionRequest execution) { + String url = buildUrl(new String[] { baseUrl, EXECUTIONS }, null); + logger.debug(EELFLoggerDelegate.debugLogger, "startExecution: url {}", url); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.set("Tenant", execution.tenant); + HttpEntity<CloudifyExecutionRequest> entity = new HttpEntity<CloudifyExecutionRequest>(execution, headers); + return restTemplate.postForObject(url, entity, CloudifyExecution.class); + } + + @Override + public CloudifyDeploymentUpdateResponse updateDeployment(CloudifyDeploymentUpdateRequest execution) { + String url = buildUrl(new String[] { baseUrl, UPDATE_DEPLOYMENT }, null); + logger.debug(EELFLoggerDelegate.debugLogger, "updateDeployment: url {}", url); + return restTemplate.postForObject(url, execution, CloudifyDeploymentUpdateResponse.class); + } + + @Override + public CloudifyExecution cancelExecution(final String executionId, Map<String, String> parameters, final String tenant) { + String url = buildUrl(new String[] { baseUrl, EXECUTIONS, executionId }, null); + logger.debug(EELFLoggerDelegate.debugLogger, "deleteExecution: url {}", url); + JSONObject requestJson = new JSONObject(parameters); + + // set headers + HttpHeaders headers = new HttpHeaders(); + headers.set("Tenant", tenant); + headers.set("Content-Type", "application/json"); + HttpEntity<String> entity = new HttpEntity<String>(requestJson.toString(), headers); + ResponseEntity<CloudifyExecution> response = restTemplate.exchange(url, HttpMethod.POST, entity, + new ParameterizedTypeReference<CloudifyExecution>() { + }); + return response.getBody(); //getStatusCode().value(); + } + + @Override + public CloudifyBlueprintList getBlueprints() { + String url = buildUrl(new String[] { baseUrl, BLUEPRINTS }, null); + logger.debug(EELFLoggerDelegate.debugLogger, "getBlueprints: url {}", url); + ResponseEntity<CloudifyBlueprintList> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<CloudifyBlueprintList>() { + }); + return response.getBody(); + } + + @Override + public CloudifyBlueprintList getBlueprint(final String id, String tenant) { + String url = buildUrl(new String[] { baseUrl, BLUEPRINTS }, new String[] { "id", id}); + logger.debug(EELFLoggerDelegate.debugLogger, "getBlueprint: url {}", url); + HttpEntity<String> entity = getTenantHeader(tenant); + ResponseEntity<CloudifyBlueprintList> response = restTemplate.exchange(url, HttpMethod.GET, entity, + new ParameterizedTypeReference<CloudifyBlueprintList>() { + }); + return response.getBody(); + } + + @Override + public CloudifyBlueprintContent viewBlueprint(final String id) { + String url = buildUrl(new String[] { baseUrl, VIEW_BLUEPRINTS }, new String[] { "id", id }); + logger.debug(EELFLoggerDelegate.debugLogger, "viewBlueprint: url {}", url); + ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, null, String.class); + String yaml = response.getBody(); + return new CloudifyBlueprintContent(id, yaml); + } + + @Override + public CloudifyBlueprintList uploadBlueprint(CloudifyBlueprintUpload blueprint) { + String url = buildUrl(new String[] { baseUrl, BLUEPRINTS }, null); + logger.debug(EELFLoggerDelegate.debugLogger, "uploadBlueprint: url {}", url); + return restTemplate.postForObject(url, blueprint, CloudifyBlueprintList.class); + } + + @Override + public int deleteBlueprint(final String id) { + String url = buildUrl(new String[] { baseUrl, BLUEPRINTS, id }, null); + logger.debug(EELFLoggerDelegate.debugLogger, "deleteBlueprint: url {}", url); + ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.DELETE, null, + new ParameterizedTypeReference<String>() { + }); + return response.getStatusCode().value(); + } + + @Override + public CloudifyDeploymentList getDeployments() { + String url = buildUrl(new String[] { baseUrl, DEPLOYMENTS }, null); + logger.debug(EELFLoggerDelegate.debugLogger, "getDeployments: url {}", url); + ResponseEntity<CloudifyDeploymentList> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<CloudifyDeploymentList>() { + }); + return response.getBody(); + } + + @Override + public CloudifyDeploymentList getDeployment(final String id) { + String url = buildUrl(new String[] { baseUrl, DEPLOYMENTS }, new String[] { "id", id }); + logger.debug(EELFLoggerDelegate.debugLogger, "getDeployment: url {}", url); + ResponseEntity<CloudifyDeploymentList> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<CloudifyDeploymentList>() { + }); + return response.getBody(); + } + + @Override + public CloudifyDeploymentList getDeployment(final String id, final String tenant) { + String url = buildUrl(new String[] { baseUrl, DEPLOYMENTS }, new String[] { "id", id, TENANT, tenant }); + logger.debug(EELFLoggerDelegate.debugLogger, "getDeployment: url {}", url); + HttpEntity<String> entity = getTenantHeader(tenant); + ResponseEntity<CloudifyDeploymentList> response = restTemplate.exchange(url, HttpMethod.GET, entity, + new ParameterizedTypeReference<CloudifyDeploymentList>() { + }); + return response.getBody(); + } + + @Override + public CloudifyDeploymentList getDeploymentInputs(final String id, final String tenant) { + String url = buildUrl(new String[] { baseUrl, DEPLOYMENTS }, new String[] { "id", id, "_include", "inputs" }); + logger.debug(EELFLoggerDelegate.debugLogger, "getDeployment: url {}", url); + HttpEntity<String> entity = getTenantHeader(tenant); + ResponseEntity<CloudifyDeploymentList> response = restTemplate.exchange(url, HttpMethod.GET, entity, + new ParameterizedTypeReference<CloudifyDeploymentList>() { + }); + return response.getBody(); + } + + @Override + public CloudifyDeploymentList createDeployment(CloudifyDeploymentRequest deployment) { + String url = buildUrl(new String[] { baseUrl, DEPLOYMENTS }, null); + logger.debug(EELFLoggerDelegate.debugLogger, "createDeployment: url {}", url); + return restTemplate.postForObject(url, deployment, CloudifyDeploymentList.class); + } + + @Override + public int deleteDeployment(final String id, boolean ignoreLiveNodes) { + String url = buildUrl(new String[] { baseUrl, DEPLOYMENTS, id }, + new String[] { "ignore_live_nodes", Boolean.toString(ignoreLiveNodes) }); + logger.debug(EELFLoggerDelegate.debugLogger, "deleteDeployment: url {}", url); + ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.DELETE, null, + new ParameterizedTypeReference<String>() { + }); + return response.getStatusCode().value(); + } + + /** + * Get a cloudify secret + * + * @return CloudifySecret + */ + @Override + public CloudifySecret getSecret(String secretName, String tenant) { + String url = buildUrl(new String[] { baseUrl, SECRETS, secretName }, new String[] { TENANT, tenant }); + logger.debug(EELFLoggerDelegate.debugLogger, "getSecrets: url {}", url); + ResponseEntity<CloudifySecret> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<CloudifySecret>() { + }); + return response.getBody(); + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/ConsulClient.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/ConsulClient.java new file mode 100644 index 0000000..f8daaf5 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/ConsulClient.java @@ -0,0 +1,74 @@ +package org.onap.ccsdk.dashboard.rest; + +import java.util.List; + +import org.onap.ccsdk.dashboard.model.ConsulDatacenter; +import org.onap.ccsdk.dashboard.model.ConsulHealthServiceRegistration; +import org.onap.ccsdk.dashboard.model.ConsulNodeInfo; +import org.onap.ccsdk.dashboard.model.ConsulServiceHealth; +import org.onap.ccsdk.dashboard.model.ConsulServiceInfo; + +/** + * Defines the interface of the Consul REST client. + */ +public interface ConsulClient { + + /** + * Gets all the services that are monitored by Consul. + * + * @return List of ConsulServiceHealth + */ + public List<ConsulServiceInfo> getServices(String datacenter); + + /** + * Gets the status for the specified service on all nodes. + * + * @param serviceName + * Service name + * @return List of ConsulServiceHealth + */ + public List<ConsulServiceHealth> getServiceHealth(String datacenter, String srvcName); + + /** + * Gets all the nodes that are monitored by Consul. + * + * @return List of ConsulNodeHealth + */ + public List<ConsulNodeInfo> getNodes(String datacenter); + + /** + * 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 datacenter, String nodeId); + + /** + * Gets all the data centers that are monitored by Consul. + * + * @return List of ConsulDatacenter objects + */ + public List<ConsulDatacenter> getDatacenters(); + + /** + * Registers a service with Consul for health check. + * + * @param registration + * Details about the service to be registered. + * @return Result of registering a service + */ + public String 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); + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/ConsulMockClientImpl.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/ConsulMockClientImpl.java new file mode 100644 index 0000000..82095c2 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/ConsulMockClientImpl.java @@ -0,0 +1,107 @@ +package org.onap.ccsdk.dashboard.rest; + +import java.io.InputStream; +import java.util.List; +import java.util.Scanner; + +import org.onap.ccsdk.dashboard.model.ConsulDatacenter; +import org.onap.ccsdk.dashboard.model.ConsulHealthServiceRegistration; +import org.onap.ccsdk.dashboard.model.ConsulNodeInfo; +import org.onap.ccsdk.dashboard.model.ConsulServiceHealth; +import org.onap.ccsdk.dashboard.model.ConsulServiceInfo; +import org.onap.ccsdk.dashboard.model.ECTransportModel; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ConsulMockClientImpl implements ConsulClient { + + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ConsulMockClientImpl.class); + + /** + * For mock outputs + */ + private final ObjectMapper objectMapper = new ObjectMapper(); + + private String getMockDataContent(final String path) { + String result = null; + try { + InputStream is = getClass().getResourceAsStream(path); + if (is == null) + throw new Exception("Failed to find resource at path " + path); + Scanner scanner = new Scanner(is, "UTF-8"); + result = scanner.useDelimiter("\\A").next(); + scanner.close(); + is.close(); + } catch (Exception ex) { + logger.error("getMockDataContent failed", ex); + throw new RuntimeException(ex); + } + return result; + } + + /** + * Creates an input stream using the specified path and requests the mapper + * create an object of the specified type. + * + * @param modelClass + * Model class + * @param path + * Path to classpath resource + * @return Instance of modelClass + */ + private ECTransportModel getMockData(final Class<? extends ECTransportModel> modelClass, final String path) { + ECTransportModel result = null; + String json = getMockDataContent(path); + try { + result = (ECTransportModel) objectMapper.readValue(json, modelClass); + } catch (Exception ex) { + logger.error("getMockData failed", ex); + throw new RuntimeException(ex); + } + return result; + } + + @Override + public List<ConsulServiceInfo> getServices(String datacenter) { + + return null; + } + + @Override + public List<ConsulServiceHealth> getServiceHealth(String datacenter, String srvcName) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List<ConsulNodeInfo> getNodes(String datacenter) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List<ConsulServiceHealth> getNodeServicesHealth(String datacenter, String nodeId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List<ConsulDatacenter> getDatacenters() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String registerService(ConsulHealthServiceRegistration registration) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int deregisterService(String serviceName) { + // TODO Auto-generated method stub + return 0; + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/ConsulRestClientImpl.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/ConsulRestClientImpl.java new file mode 100644 index 0000000..32311a8 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/ConsulRestClientImpl.java @@ -0,0 +1,191 @@ +package org.onap.ccsdk.dashboard.rest; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.onap.ccsdk.dashboard.model.ConsulDatacenter; +import org.onap.ccsdk.dashboard.model.ConsulHealthServiceRegistration; +import org.onap.ccsdk.dashboard.model.ConsulHealthServiceRegistration.EndpointCheck; +import org.onap.ccsdk.dashboard.model.ConsulNodeInfo; +import org.onap.ccsdk.dashboard.model.ConsulServiceHealth; +import org.onap.ccsdk.dashboard.model.ConsulServiceInfo; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ConsulRestClientImpl extends RestClientBase implements ConsulClient { + + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ConsulRestClientImpl.class); + private final String baseUrl; + private final ObjectMapper objectMapper = new ObjectMapper(); + + private static final String API_VER = "v1"; + private static final String CATALOG = "catalog"; + private static final String SERVICES = "services"; + private static final String HEALTH = "health"; + private static final String CHECKS = "checks"; + private static final String HEALTH_SERVICES = "healthservices"; + + public ConsulRestClientImpl(String webapiUrl, String user, String pass) { + super(); + if (webapiUrl == null) + throw new IllegalArgumentException("Null URL not permitted"); + + URL url = null; + String urlScheme = "http"; + try { + url = new URL(webapiUrl); + baseUrl = url.toExternalForm(); + } catch (MalformedURLException ex) { + throw new RuntimeException("Failed to parse URL", ex); + } + + urlScheme = webapiUrl.split(":")[0]; + createRestTemplate(url, user, pass, urlScheme); + } + + @Override + public List<ConsulServiceHealth> getServiceHealth(String dc, String srvc) { + String url = buildUrl(new String[] { baseUrl, API_VER, HEALTH, CHECKS, srvc}, new String[] {"dc", dc}); + logger.debug(EELFLoggerDelegate.debugLogger, "getServiceHealth: url {}", url); + ResponseEntity<List<ConsulServiceHealth>> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<List<ConsulServiceHealth>>() { + }); + return response.getBody(); + } + + @Override + public List<ConsulServiceInfo> getServices(String dc) { + String url = buildUrl(new String[] { baseUrl, API_VER, CATALOG, SERVICES}, new String[] {"dc", dc}); + logger.debug(EELFLoggerDelegate.debugLogger, "getServices: url {}", url); + ResponseEntity<Map<String, Object>> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<Map<String, Object>>() { + }); + Map<String, Object> serviceInfo = response.getBody(); + List<ConsulServiceInfo> list = new ArrayList<>(); + for (Map.Entry<String, Object> entry : serviceInfo.entrySet()) { + // Be defensive + List<String> addrs = null; + if (entry.getValue() instanceof List<?>) + addrs = (List<String>) entry.getValue(); + else + addrs = new ArrayList<>(); + list.add(new ConsulServiceInfo(entry.getKey(), addrs)); + } + return list; + } + + @Override + public List<ConsulNodeInfo> getNodes(String dc) { + String url = buildUrl(new String[] { baseUrl, API_VER, CATALOG, "nodes" }, new String[] {"dc", dc}); + logger.debug(EELFLoggerDelegate.debugLogger, "getNodesHealth: url {}", url); + ResponseEntity<List<ConsulNodeInfo>> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<List<ConsulNodeInfo>>() { + }); + return response.getBody(); + } + + @Override + public List<ConsulServiceHealth> getNodeServicesHealth(String dc, String nodeId) { + String url = buildUrl(new String[] { baseUrl, API_VER, HEALTH, "node", nodeId }, new String[] {"dc", dc}); + logger.debug(EELFLoggerDelegate.debugLogger, "getNodeServicesHealth: url {}", url); + ResponseEntity<List<ConsulServiceHealth>> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<List<ConsulServiceHealth>>() { + }); + return response.getBody(); + } + + @Override + public List<ConsulDatacenter> getDatacenters() { + String url = buildUrl(new String[] { baseUrl, API_VER, CATALOG, "datacenters" }, null); + logger.debug(EELFLoggerDelegate.debugLogger, "getDatacentersHealth: url {}", url); + ResponseEntity<List<String>> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<List<String>>() { + }); + List<String> list = response.getBody(); + List<ConsulDatacenter> result = new ArrayList<>(); + for (String dc : list) + result.add(new ConsulDatacenter(dc)); + return result; + } + + @Override + public String registerService(ConsulHealthServiceRegistration registration) { + String url = buildUrl(new String[] { baseUrl, API_VER, "/agent/service/register" }, null); + logger.debug(EELFLoggerDelegate.debugLogger, "registerService: url {}", url); + String resultStr = ""; + JSONObject outputJson = new JSONObject(); + JSONObject checkObject = new JSONObject(); + List<EndpointCheck> checks = registration.services.get(0).checks; + String service_name = registration.services.get(0).name; + String service_port = registration.services.get(0).port; + String service_address = registration.services.get(0).address; + List<String> tags = registration.services.get(0).tags; + + outputJson.put("Name", service_name); + outputJson.put("ID", service_name); + outputJson.put("Port", Integer.parseInt(service_port)); + outputJson.put("Address", service_address); + outputJson.put("Tags", tags); + + if (checks.size() == 1) { + checkObject.put("HTTP", checks.get(0).endpoint); + checkObject.put("Interval", checks.get(0).interval); + if (!checks.get(0).description.isEmpty()) + checkObject.put("Notes", checks.get(0).description); + checkObject.put("ServiceID", service_name); + outputJson.put("Check", checkObject); + } else { + JSONArray checks_new = new JSONArray(); + for (EndpointCheck check : checks) { + checkObject.put("HTTP", check.endpoint); + checkObject.put("Interval", check.endpoint); + if (!check.description.isEmpty()) + checkObject.put("Notes", check.description); + checkObject.put("ServiceID", service_name); + checks_new.put(checkObject); + } + outputJson.put("Checks", checks_new); + } + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity<String> entity = new HttpEntity<String>(outputJson.toString(), headers); + ResponseEntity<JSONObject> result = + restTemplate.exchange(url, HttpMethod.PUT, entity, + new ParameterizedTypeReference<JSONObject>() {}); + try { + resultStr = objectMapper.writeValueAsString(result); + } catch (JsonProcessingException e) { + + } finally { + } + return resultStr; + + } + + @Override + public int deregisterService(String serviceName) { + String url = buildUrl(new String[] { baseUrl, API_VER, "/agent/service/deregister", serviceName}, null); + logger.debug(EELFLoggerDelegate.debugLogger, "deregisterService: url {}", url); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity<String> entity = new HttpEntity<String>(headers); + ResponseEntity<JSONObject> result = + restTemplate.exchange(url, HttpMethod.PUT, entity, + new ParameterizedTypeReference<JSONObject>() {}); + return result.getStatusCode().value(); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/ControllerRestClientImpl.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/ControllerRestClientImpl.java deleted file mode 100644 index 2e28ad2..0000000 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/ControllerRestClientImpl.java +++ /dev/null @@ -1,412 +0,0 @@ -/*******************************************************************************
- * =============LICENSE_START=========================================================
- *
- * =================================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *******************************************************************************/
-package org.onap.ccsdk.dashboard.rest;
-
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URL;
-import java.time.Instant;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.http.HttpHost;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.CredentialsProvider;
-import org.apache.http.impl.client.BasicCredentialsProvider;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.onap.ccsdk.dashboard.model.CloudifyBlueprintContent;
-import org.onap.ccsdk.dashboard.model.CloudifyBlueprintList;
-import org.onap.ccsdk.dashboard.model.CloudifyBlueprintUpload;
-import org.onap.ccsdk.dashboard.model.CloudifyDeploymentList;
-import org.onap.ccsdk.dashboard.model.CloudifyDeploymentRequest;
-import org.onap.ccsdk.dashboard.model.CloudifyExecution;
-import org.onap.ccsdk.dashboard.model.CloudifyExecutionList;
-import org.onap.ccsdk.dashboard.model.CloudifyExecutionRequest;
-import org.onap.ccsdk.dashboard.model.ConsulDatacenter;
-import org.onap.ccsdk.dashboard.model.ConsulHealthServiceRegistration;
-import org.onap.ccsdk.dashboard.model.ConsulNodeInfo;
-import org.onap.ccsdk.dashboard.model.ConsulServiceHealth;
-import org.onap.ccsdk.dashboard.model.ConsulServiceHealthHistory;
-import org.onap.ccsdk.dashboard.model.ConsulServiceInfo;
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.springframework.core.ParameterizedTypeReference;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.client.RestTemplate;
-
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-/**
- * Provides methods for accessing the ECOMP Controller API via REST. Most
- * methods are just simple proxies. Only the methods that fetch one page of data
- * have to do any real work.
- *
- * Implemented using Spring RestTemplate. Supports basic HTTP authentication.
- *
- */
-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;
- private final ObjectMapper objectMapper = new ObjectMapper();
-
- /**
- * Builds a restTemplate. If username and password are supplied, uses basic
- * HTTP authentication.
- *
- * @param webapiUrl
- * URL of the web endpoint
- * @param user
- * user name; ignored if null
- * @param pass
- * password
- */
- public ControllerRestClientImpl(String webapiUrl, String user, String pass) {
- if (webapiUrl == null)
- throw new IllegalArgumentException("Null URL not permitted");
-
- URL url = null;
- try {
- url = new URL(webapiUrl);
- baseUrl = url.toExternalForm();
- } catch (MalformedURLException ex) {
- throw new RuntimeException("Failed to parse URL", ex);
- }
- final HttpHost httpHost = new HttpHost(url.getHost(), url.getPort());
-
- // Build a client with a credentials provider
- CloseableHttpClient httpClient = null;
- if (user != null && pass != null) {
- CredentialsProvider credsProvider = new BasicCredentialsProvider();
- credsProvider.setCredentials(new AuthScope(httpHost), new UsernamePasswordCredentials(user, pass));
- httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build();
- } else {
- httpClient = HttpClientBuilder.create().build();
- }
- // Create request factory
- HttpComponentsClientHttpRequestFactoryBasicAuth requestFactory = new HttpComponentsClientHttpRequestFactoryBasicAuth(
- httpHost);
- requestFactory.setHttpClient(httpClient);
-
- // Put the factory in the template
- this.restTemplate = new RestTemplate();
- restTemplate.setRequestFactory(requestFactory);
- }
-
- /**
- * Builds URL ensuring appropriate separators. The base comes from
- * properties file so could have many problems.
- *
- * @param base
- * @param suffix
- * @param queryParams
- * key-value pairs; i.e. must have an even number of entries.
- * Ignored if null.
- * @return
- */
- private String buildUrl(final String[] path, final String[] queryParams) {
- StringBuilder sb = new StringBuilder(path[0]);
- for (int p = 1; p < path.length; ++p) {
- if (!path[p - 1].endsWith("/") && !path[p].startsWith("/"))
- sb.append('/');
- sb.append(path[p]);
- }
- if (queryParams != null && queryParams.length > 0) {
- sb.append('?');
- int i = 0;
- while (i < queryParams.length) {
- if (i > 0)
- sb.append('&');
- sb.append(queryParams[i]);
- sb.append('=');
- sb.append(queryParams[i + 1]);
- i += 2;
- }
- }
- return sb.toString();
- }
-
- @Override
- public CloudifyBlueprintList getBlueprints() {
- String url = buildUrl(new String[] { baseUrl, blueprintsPath }, null);
- logger.debug(EELFLoggerDelegate.debugLogger, "getBlueprints: url {}", url);
- ResponseEntity<CloudifyBlueprintList> response = restTemplate.exchange(url, HttpMethod.GET, null,
- new ParameterizedTypeReference<CloudifyBlueprintList>() {
- });
- return response.getBody();
- }
-
- @Override
- public CloudifyBlueprintList getBlueprint(final String id) {
- String url = buildUrl(new String[] { baseUrl, blueprintsPath }, new String[] { "id", id });
- logger.debug(EELFLoggerDelegate.debugLogger, "getBlueprint: url {}", url);
- ResponseEntity<CloudifyBlueprintList> response = restTemplate.exchange(url, HttpMethod.GET, null,
- new ParameterizedTypeReference<CloudifyBlueprintList>() {
- });
- return response.getBody();
- }
-
- @Override
- public CloudifyBlueprintContent viewBlueprint(final String id) {
- String url = buildUrl(new String[] { baseUrl, viewBlueprintsPath }, new String[] { "id", id });
- logger.debug(EELFLoggerDelegate.debugLogger, "viewBlueprint: url {}", url);
- ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, null, String.class);
- String yaml = response.getBody();
- 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);
- return restTemplate.postForObject(url, blueprint, CloudifyBlueprintList.class);
- }
-
- @Override
- public int deleteBlueprint(final String id) {
- String url = buildUrl(new String[] { baseUrl, blueprintsPath, id }, null);
- logger.debug(EELFLoggerDelegate.debugLogger, "deleteBlueprint: url {}", url);
- ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.DELETE, null,
- new ParameterizedTypeReference<String>() {
- });
- return response.getStatusCode().value();
- }
-
- @Override
- public CloudifyDeploymentList getDeployments() {
- String url = buildUrl(new String[] { baseUrl, deploymentsPath }, null);
- logger.debug(EELFLoggerDelegate.debugLogger, "getDeployments: url {}", url);
- ResponseEntity<CloudifyDeploymentList> response = restTemplate.exchange(url, HttpMethod.GET, null,
- new ParameterizedTypeReference<CloudifyDeploymentList>() {
- });
- return response.getBody();
- }
-
- @Override
- public CloudifyDeploymentList getDeployment(final String id) {
- String url = buildUrl(new String[] { baseUrl, deploymentsPath }, new String[] { "id", id });
- logger.debug(EELFLoggerDelegate.debugLogger, "getDeployment: url {}", url);
- ResponseEntity<CloudifyDeploymentList> response = restTemplate.exchange(url, HttpMethod.GET, null,
- new ParameterizedTypeReference<CloudifyDeploymentList>() {
- });
- return response.getBody();
- }
-
- @Override
- public CloudifyDeploymentList createDeployment(CloudifyDeploymentRequest deployment) {
- String url = buildUrl(new String[] { baseUrl, deploymentsPath }, null);
- logger.debug(EELFLoggerDelegate.debugLogger, "createDeployment: url {}", url);
- return restTemplate.postForObject(url, deployment, CloudifyDeploymentList.class);
- }
-
- @Override
- public int deleteDeployment(final String id, boolean ignoreLiveNodes) {
- String url = buildUrl(new String[] { baseUrl, deploymentsPath, id },
- new String[] { "ignore_live_nodes", Boolean.toString(ignoreLiveNodes) });
- logger.debug(EELFLoggerDelegate.debugLogger, "deleteDeployment: url {}", url);
- ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.DELETE, null,
- new ParameterizedTypeReference<String>() {
- });
- return response.getStatusCode().value();
- }
-
- @Override
- public CloudifyExecutionList getExecutions(final String 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>() {
- });
- return response.getBody();
- }
-
- @Override
- public CloudifyExecutionList getExecution(String executionId, String deploymentId) {
- String url = buildUrl(new String[] { baseUrl, executionsPath, executionId },
- new String[]{DEPLOYMENT_ID, deploymentId});
- logger.debug(EELFLoggerDelegate.debugLogger, "getExecution: url {}", url);
- ResponseEntity<CloudifyExecutionList> response = restTemplate.exchange(url, HttpMethod.GET, null,
- new ParameterizedTypeReference<CloudifyExecutionList>() {
- });
- return response.getBody();
- }
-
- @Override
- public CloudifyExecution startExecution(CloudifyExecutionRequest execution) {
- String url = buildUrl(new String[] { baseUrl, executionsPath }, null);
- logger.debug(EELFLoggerDelegate.debugLogger, "startExecution: url {}", url);
- 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});
- logger.debug(EELFLoggerDelegate.debugLogger, "deleteExecution: url {}", url);
- ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.DELETE, null,
- new ParameterizedTypeReference<String>() {
- });
- return response.getStatusCode().value();
- }
-
- @Override
- public URI registerService(ConsulHealthServiceRegistration registration) {
- String url = buildUrl(new String[] { baseUrl, healthServicesPath, "register" }, null);
- logger.debug(EELFLoggerDelegate.debugLogger, "registerService: url {}", url);
- return restTemplate.postForLocation(url, registration);
- }
-
- @Override
- public int deregisterService(String serviceName) {
- String url = buildUrl(new String[] { baseUrl, healthServicesPath, "deregister" , serviceName}, null);
- logger.debug(EELFLoggerDelegate.debugLogger, "deregisterService: url {}", url);
- ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, null,
- new ParameterizedTypeReference<String>() {
- });
- return response.getStatusCode().value();
- }
-
- /**
- * Translates the awkward map of String-to-List of IP into a list of
- * ConsulServiceInfo objects
- */
- @SuppressWarnings("unchecked")
- @Override
- public List<ConsulServiceInfo> getServices() {
- String url = buildUrl(new String[] { baseUrl, healthServicesPath, "services" }, null);
- logger.debug(EELFLoggerDelegate.debugLogger, "getServicesHealth: url {}", url);
- ResponseEntity<Map<String, Object>> response = restTemplate.exchange(url, HttpMethod.GET, null,
- new ParameterizedTypeReference<Map<String, Object>>() {
- });
- Map<String, Object> serviceInfo = response.getBody();
- List<ConsulServiceInfo> list = new ArrayList<>();
- for (Map.Entry<String, Object> entry : serviceInfo.entrySet()) {
- // Be defensive
- List<String> addrs;
- if (entry.getValue() instanceof List<?>)
- addrs = (List<String>) entry.getValue();
- else
- addrs = new ArrayList<>();
- list.add(new ConsulServiceInfo(entry.getKey(), addrs));
- }
- return list;
- }
-
- @Override
- public List<ConsulServiceHealth> getServiceHealth(String serviceName) {
- String url = buildUrl(new String[] { baseUrl, healthServicesPath, "services", serviceName }, null);
- logger.debug(EELFLoggerDelegate.debugLogger, "getServiceHealth: url {}", url);
- ResponseEntity<List<ConsulServiceHealth>> response = restTemplate.exchange(url, HttpMethod.GET, null,
- new ParameterizedTypeReference<List<ConsulServiceHealth>>() {
- });
- return response.getBody();
- }
-
- @Override
- public List<ConsulServiceHealthHistory> getServiceHealthHistory(String serviceName, Instant start,
- Instant end) {
- String url = buildUrl(new String[] { baseUrl, healthServicesPath, "svchist", serviceName },
- new String[] { "start", start.toString(), "end", end.toString() });
- logger.debug(EELFLoggerDelegate.debugLogger, "getServiceHealthHistory: url {}", url);
- // Hack around an odd interface that returns non-JSON on error:
- // "No health Data found for the selected dates or service"
- ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, null,
- new ParameterizedTypeReference<String>() { });
- if (response.getBody().startsWith("No health"))
- throw new RuntimeException(response.getBody());
- List<ConsulServiceHealthHistory> result = null;
- try {
- TypeReference<List<ConsulServiceHealthHistory>> typeRef = new TypeReference<List<ConsulServiceHealthHistory>>() { };
- result = objectMapper.readValue(response.getBody(), typeRef);
- } catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "getServiceHealthHistory failed to parse response body", ex);
- }
- return result;
- }
-
- @Override
- public List<ConsulNodeInfo> getNodes() {
- String url = buildUrl(new String[] { baseUrl, healthServicesPath, "nodes" }, null);
- logger.debug(EELFLoggerDelegate.debugLogger, "getNodesHealth: url {}", url);
- ResponseEntity<List<ConsulNodeInfo>> response = restTemplate.exchange(url, HttpMethod.GET, null,
- new ParameterizedTypeReference<List<ConsulNodeInfo>>() {
- });
- return response.getBody();
- }
-
- @Override
- public List<ConsulServiceHealth> getNodeServicesHealth(String nodeId) {
- String url = buildUrl(new String[] { baseUrl, healthServicesPath, "nodes", nodeId }, null);
- logger.debug(EELFLoggerDelegate.debugLogger, "getNodeServicesHealth: url {}", url);
- ResponseEntity<List<ConsulServiceHealth>> response = restTemplate.exchange(url, HttpMethod.GET, null,
- new ParameterizedTypeReference<List<ConsulServiceHealth>>() {
- });
- return response.getBody();
- }
-
- @Override
- public List<ConsulDatacenter> getDatacenters() {
- String url = buildUrl(new String[] { baseUrl, healthServicesPath, "datacenters" }, null);
- logger.debug(EELFLoggerDelegate.debugLogger, "getDatacentersHealth: url {}", url);
- ResponseEntity<List<String>> response = restTemplate.exchange(url, HttpMethod.GET, null,
- new ParameterizedTypeReference<List<String>>() {
- });
- List<String> list = response.getBody();
- List<ConsulDatacenter> result = new ArrayList<>();
- for (String dc : list)
- result.add(new ConsulDatacenter(dc));
- return result;
- }
-
- /**
- * Simple test
- *
- * @param args
- * blueprint ID
- * @throws IllegalArgumentException
- * On bad arguments
- */
- public static void main(String[] args) throws IllegalArgumentException {
- if (args.length != 1)
- throw new IllegalArgumentException("Single argument expected: blueprint-id");
- ControllerRestClientImpl client = new ControllerRestClientImpl("http://localhost:8081/controller", "dbus_user",
- "dbus_pass");
- final String id = args[0];
- logger.info("Requesting blueprint for " + id);
- CloudifyBlueprintList list = client.getBlueprint(id);
- if (list == null)
- logger.error("Received null");
- else
- for (int i = 0; i < list.items.size(); ++i) {
- logger.info("Blueprint " + Integer.toString(i));
- logger.info(list.items.get(i).toString());
- }
- }
-
-}
diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/ControllerRestClientMockImpl.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/ControllerRestClientMockImpl.java deleted file mode 100644 index 6b0f3d0..0000000 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/ControllerRestClientMockImpl.java +++ /dev/null @@ -1,311 +0,0 @@ -/*******************************************************************************
- * =============LICENSE_START=========================================================
- *
- * =================================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *******************************************************************************/
-package org.onap.ccsdk.dashboard.rest;
-
-import java.io.InputStream;
-import java.net.URI;
-import java.time.Instant;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Scanner;
-
-import org.onap.ccsdk.dashboard.exception.DashboardControllerException;
-import org.onap.ccsdk.dashboard.model.CloudifyBlueprintContent;
-import org.onap.ccsdk.dashboard.model.CloudifyBlueprintList;
-import org.onap.ccsdk.dashboard.model.CloudifyBlueprintUpload;
-import org.onap.ccsdk.dashboard.model.CloudifyDeploymentList;
-import org.onap.ccsdk.dashboard.model.CloudifyDeploymentRequest;
-import org.onap.ccsdk.dashboard.model.CloudifyExecution;
-import org.onap.ccsdk.dashboard.model.CloudifyExecutionList;
-import org.onap.ccsdk.dashboard.model.CloudifyExecutionRequest;
-import org.onap.ccsdk.dashboard.model.ConsulDatacenter;
-import org.onap.ccsdk.dashboard.model.ConsulHealthServiceRegistration;
-import org.onap.ccsdk.dashboard.model.ConsulNodeInfo;
-import org.onap.ccsdk.dashboard.model.ConsulServiceHealth;
-import org.onap.ccsdk.dashboard.model.ConsulServiceHealthHistory;
-import org.onap.ccsdk.dashboard.model.ConsulServiceInfo;
-import org.onap.ccsdk.dashboard.model.ECTransportModel;
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-/**
- * Provides mock implementations that return contents of files on the classpath.
- */
-public class ControllerRestClientMockImpl implements IControllerRestClient {
-
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ControllerRestClientMockImpl.class);
-
- /**
- * For mock outputs
- */
- private final ObjectMapper objectMapper = new ObjectMapper();
-
- /**
- * No-arg constructor
- */
- public ControllerRestClientMockImpl() {
- }
-
- private String getMockDataContent(final String path) {
- String result = null;
- try {
- InputStream is = getClass().getResourceAsStream(path);
- if (is == null)
- throw new DashboardControllerException("Failed to find resource at path " + path);
- Scanner scanner = new Scanner(is, "UTF-8");
- result = scanner.useDelimiter("\\A").next();
- scanner.close();
- is.close();
- } catch (Exception ex) {
- logger.error("getMockDataContent failed", ex);
- throw new RuntimeException(ex);
- }
- return result;
- }
-
- /**
- * Creates an input stream using the specified path and requests the mapper
- * create an object of the specified type.
- *
- * @param modelClass
- * Model class
- * @param path
- * Path to classpath resource
- * @return Instance of modelClass
- */
- private ECTransportModel getMockData(final Class<? extends ECTransportModel> modelClass, final String path) {
- ECTransportModel result;
- String json = getMockDataContent(path);
- try {
- result = objectMapper.readValue(json, modelClass);
- } catch (Exception ex) {
- logger.error("getMockData failed", ex);
- throw new RuntimeException(ex);
- }
- return result;
- }
-
- @Override
- public CloudifyBlueprintList getBlueprints() {
- return (CloudifyBlueprintList) getMockData(CloudifyBlueprintList.class, "/blueprintList.json");
- }
-
- @Override
- public CloudifyBlueprintList getBlueprint(final String id) {
- return (CloudifyBlueprintList) getMockData(CloudifyBlueprintList.class, "/blueprintByID.json");
- }
-
- @Override
- public CloudifyBlueprintContent viewBlueprint(final String id) {
- String yaml = getMockDataContent("/blueprintContent.yaml");
- return new CloudifyBlueprintContent(id, yaml);
- }
-
- @Override
- public CloudifyBlueprintList uploadBlueprint(CloudifyBlueprintUpload blueprint) {
- logger.debug(EELFLoggerDelegate.debugLogger, "uploadBlueprint: {}", blueprint.toString());
- return new CloudifyBlueprintList(null, null);
- }
-
- @Override
- public int deleteBlueprint(final String id) {
- logger.debug(EELFLoggerDelegate.debugLogger, "deleteBlueprint: {}", id);
- return 204;
- }
-
- @Override
- public CloudifyDeploymentList getDeployments() {
- return (CloudifyDeploymentList) getMockData(CloudifyDeploymentList.class, "/deploymentList.json");
- }
-
- @Override
- public CloudifyDeploymentList getDeployment(final String id) {
- return (CloudifyDeploymentList) getMockData(CloudifyDeploymentList.class, "/deploymentByID.json");
- }
-
- public CloudifyDeploymentList createDeployment(CloudifyDeploymentRequest deployment) {
- logger.debug(EELFLoggerDelegate.debugLogger, "createDeployment: {}", deployment.toString());
- return new CloudifyDeploymentList(null, null);
- }
-
- @Override
- public int deleteDeployment(final String id, boolean ignoreLiveNodes) {
- logger.debug(EELFLoggerDelegate.debugLogger, "deleteDeployment: id {}, ignoreLiveNodes", id, ignoreLiveNodes);
- return 204;
- }
-
- @Override
- public CloudifyExecutionList getExecutions(final String deploymentId) {
- return (CloudifyExecutionList) getMockData(CloudifyExecutionList.class, "/listExecutionForDeploymentID.json");
- }
-
- @Override
- public CloudifyExecutionList getExecution(String executionId, String deploymentId) {
- return (CloudifyExecutionList) getMockData(CloudifyExecutionList.class, "/listExecutionForDeploymentID.json");
- }
-
- @Override
- public CloudifyExecution startExecution(CloudifyExecutionRequest execution) {
- logger.debug(EELFLoggerDelegate.debugLogger, "startExecution: {}", execution.toString());
- return new CloudifyExecution(null, null, null, null, null, null, null, null, null);
- }
-
- @Override
- public int cancelExecution(String executionId, String deploymentId, String action) {
- logger.debug(EELFLoggerDelegate.debugLogger, "deleteExecution: executionId {}, deploymentId {}, action {}",
- executionId, deploymentId, action);
- return 204;
- }
-
- @Override
- public URI registerService(ConsulHealthServiceRegistration registration) {
- logger.debug(EELFLoggerDelegate.debugLogger, "registerService: {}", registration);
- return null;
- }
-
- @Override
- public int deregisterService(String serviceName) {
- logger.debug(EELFLoggerDelegate.debugLogger, "deregisterService: {}", serviceName);
- return 200;
- }
-
- @Override
- public List<ConsulServiceHealth> getServiceHealth(String serviceName) {
- logger.debug(EELFLoggerDelegate.debugLogger, "getServiceHealth: serviceName={}", serviceName);
- String json = getMockDataContent("/serviceHealth.json");
- TypeReference<List<ConsulServiceHealth>> typeRef = new TypeReference<List<ConsulServiceHealth>>() {
- };
- List<ConsulServiceHealth> result = null;
- try {
- result = objectMapper.readValue(json, typeRef);
- } catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "getServiceHealth failed", ex);
- }
- return result;
- }
-
- @Override
- public List<ConsulServiceHealthHistory> getServiceHealthHistory(String serviceName, Instant start, Instant end) {
- logger.debug(EELFLoggerDelegate.debugLogger, "getServiceHealthHistory: serviceName={}", serviceName);
- String json = getMockDataContent("/serviceHealthHistory.json");
- TypeReference<List<ConsulServiceHealthHistory>> typeRef = new TypeReference<List<ConsulServiceHealthHistory>>() {
- };
- List<ConsulServiceHealthHistory> result = null;
- try {
- result = objectMapper.readValue(json, typeRef);
- } catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "getServiceHealthHistory failed", ex);
- }
- return result;
- }
-
- @Override
- public List<ConsulServiceHealth> getNodeServicesHealth(String nodeId) {
- logger.debug(EELFLoggerDelegate.debugLogger, "getNodeServicesHealth: nodeId={}", nodeId);
- String json = getMockDataContent("/nodeServicesHealth.json");
- TypeReference<List<ConsulServiceHealth>> typeRef = new TypeReference<List<ConsulServiceHealth>>() {
- };
- List<ConsulServiceHealth> result = null;
- try {
- result = objectMapper.readValue(json, typeRef);
- } catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "getNodeServicesHealth failed", ex);
- }
- return result;
- }
-
- @Override
- public List<ConsulServiceInfo> getServices() {
- logger.debug(EELFLoggerDelegate.debugLogger, "getServices");
- String json = getMockDataContent("/services.json");
- TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() {
- };
- HashMap<String, Object> map = null;
- try {
- map = objectMapper.readValue(json, typeRef);
- } catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "getNode failed", ex);
- }
- ArrayList<ConsulServiceInfo> result = new ArrayList<>();
- 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;
- }
-
- @Override
- public List<ConsulNodeInfo> getNodes() {
- logger.debug(EELFLoggerDelegate.debugLogger, "getNodes");
- String json = getMockDataContent("/nodesHealth.json");
- TypeReference<List<ConsulNodeInfo>> typeRef = new TypeReference<List<ConsulNodeInfo>>() {
- };
- List<ConsulNodeInfo> result = null;
- try {
- result = objectMapper.readValue(json, typeRef);
- } catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "getNode failed", ex);
-
- }
- return result;
- }
-
- @Override
- public List<ConsulDatacenter> getDatacenters() {
- logger.debug(EELFLoggerDelegate.debugLogger, "getDatacentersHealth");
- return null;
- }
-
- /**
- * Simple test
- *
- * @param args
- * blueprint ID
- * @throws DashboardControllerException
- * On any failure
- */
- public static void main(String[] args) throws DashboardControllerException {
- logger.info("Testing paths and parsing mock data");
- ControllerRestClientMockImpl client = new ControllerRestClientMockImpl();
- CloudifyBlueprintList list1 = client.getBlueprints();
- CloudifyBlueprintList list2 = client.getBlueprint("mock");
- CloudifyDeploymentList list3 = client.getDeployments();
- CloudifyDeploymentList list4 = client.getDeployment("mock");
- CloudifyExecutionList list5 = client.getExecutions("mock");
- List<ConsulServiceInfo> list6 = client.getServices();
- List<ConsulNodeInfo> list7 = client.getNodes();
- List<ConsulServiceHealth> list8 = client.getServiceHealth("mock");
- List<ConsulServiceHealthHistory> list9 = client.getServiceHealthHistory("mock", Instant.now(), Instant.now());
- if (list1 == null || list2 == null || list3 == null || list4 == null || list5 == null || list6 == null
- || list7 == null || list8 == null || list9 == null)
- throw new DashboardControllerException("Failed");
- logger.info("Pass.");
- }
-
-}
diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/DeploymentHandlerClient.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/DeploymentHandlerClient.java new file mode 100644 index 0000000..2599a27 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/DeploymentHandlerClient.java @@ -0,0 +1,88 @@ +package org.onap.ccsdk.dashboard.rest; + +import java.util.stream.Stream; + +import org.onap.ccsdk.dashboard.exceptions.BadRequestException; +import org.onap.ccsdk.dashboard.exceptions.DeploymentNotFoundException; +import org.onap.ccsdk.dashboard.exceptions.DownstreamException; +import org.onap.ccsdk.dashboard.exceptions.ServerErrorException; +import org.onap.ccsdk.dashboard.exceptions.ServiceAlreadyExistsException; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentLink; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentRequest; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentResponse; + +public interface DeploymentHandlerClient { + + + + /** + * Gets a list of all service deployments known to the orchestrator. + * + * @return Stream<String> + */ + public Stream<DeploymentLink> getDeployments(); + + /** + * Gets a list of all service deployments known to the orchestrator, + * restricted to a single service type. + * + * @param serviceTypeId + * Service type identifier for the type whose deployments are to be listed. + * + * @return Stream<String> + */ + public Stream<DeploymentLink> getDeployments(String serviceTypeId); + + /** + * Request deployment of a DCAE Service. + * + * @param deploymentId + * Unique deployment identifier assigned by the API client. + * + * @param deploymentRequest + * Deployment request object that contains the necessary fields for service deployment. + * + * @return DeploymentResponse + * Response body for a PUT or DELETE to /dcae-deployments/{deploymentId} + * + */ + public DeploymentResponse putDeployment(String deploymentId, String tenant, + DeploymentRequest deploymentRequest) throws + BadRequestException, + ServiceAlreadyExistsException, + ServerErrorException, + DownstreamException; + /** + * Initiate update for a deployment + * + * @param deploymentId + * Unique deployment identifier assigned by the API client. + * + * @param tenant + * Cloudify tenant where the deployment should be done + * + * @param deploymentRequest + * Deployment request object that contains the necessary fields for service deployment. + * + * @return DeploymentResponse + * Response body for a PUT or DELETE to /dcae-deployments/{deploymentId} + * + */ + public DeploymentResponse updateDeployment(String deploymentId, String tenant, + DeploymentRequest deploymentRequest) throws BadRequestException, + ServiceAlreadyExistsException, + ServerErrorException, + DownstreamException; + + /** + * Uninstall the DCAE service and remove all associated data from the orchestrator. + * + * @param deploymentId + * Unique deployment identifier assigned by the API client. + * + */ + public void deleteDeployment(String deploymentId, String tenant) throws BadRequestException, + ServerErrorException, + DownstreamException, + DeploymentNotFoundException; +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/DeploymentHandlerClientImpl.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/DeploymentHandlerClientImpl.java new file mode 100644 index 0000000..168c28b --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/DeploymentHandlerClientImpl.java @@ -0,0 +1,213 @@ +package org.onap.ccsdk.dashboard.rest; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.stream.Stream; + +import org.onap.ccsdk.dashboard.exceptions.BadRequestException; +import org.onap.ccsdk.dashboard.exceptions.DeploymentNotFoundException; +import org.onap.ccsdk.dashboard.exceptions.DownstreamException; +import org.onap.ccsdk.dashboard.exceptions.ServerErrorException; +import org.onap.ccsdk.dashboard.exceptions.ServiceAlreadyExistsException; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentErrorResponse; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentLink; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentRequest; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentResponse; +import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentsListResponse; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpServerErrorException; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; + +public class DeploymentHandlerClientImpl extends RestClientBase implements DeploymentHandlerClient { + + private final String baseUrl; + //private final RestTemplate restTemplate; + private static final String DEPLOYMENTS = "dcae-deployments"; + private static final String UPDATE_PATH = "dcae-deployment-update"; + + protected final ObjectMapper objectMapper = new ObjectMapper(); + + public DeploymentHandlerClientImpl(String webapiUrl) { + this(webapiUrl, null, null); + } + + /** + * Builds a restTemplate. If username and password are supplied, uses basic + * HTTP authentication. + * + * @param webapiUrl + * URL of the web endpoint + * @param user + * user name; ignored if null + * @param pass + * password + */ + public DeploymentHandlerClientImpl(String webapiUrl, String user, String pass) { + super(); + if (webapiUrl == null) + throw new IllegalArgumentException("Null URL not permitted"); + URL url = null; + String urlScheme = "http"; + try { + url = new URL(webapiUrl); + baseUrl = url.toExternalForm(); + } catch (MalformedURLException ex) { + throw new RuntimeException("Failed to parse URL", ex); + } + urlScheme = webapiUrl.split(":")[0]; + createRestTemplate(url, user, pass, urlScheme); + // Do not serialize null values + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + // Register Jdk8Module() for Stream and Optional types + objectMapper.registerModule(new Jdk8Module()); + } + + public Stream<DeploymentLink> getDeployments() { + String url = buildUrl(new String[] {baseUrl, DEPLOYMENTS}, null); + ResponseEntity<DeploymentsListResponse> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<DeploymentsListResponse>() { + }); + DeploymentsListResponse result = response.getBody(); + return result.getDeployments().stream(); + } + + @Override + public Stream<DeploymentLink> getDeployments(String serviceTypeId) { + String url = buildUrl(new String[] {baseUrl, DEPLOYMENTS}, new String[] {"serviceTypeId", serviceTypeId}); + ResponseEntity<DeploymentsListResponse> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<DeploymentsListResponse>() { + }); + DeploymentsListResponse result = response.getBody(); + return result.getDeployments().stream(); + } + + @Override + public DeploymentResponse putDeployment(String deploymentId, String tenant, DeploymentRequest deploymentRequest) + throws BadRequestException, ServiceAlreadyExistsException, ServerErrorException, DownstreamException { + String url = buildUrl(new String[] {baseUrl, DEPLOYMENTS, deploymentId}, new String[] {"cfy_tenant_name",tenant}); + try { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + ResponseEntity<DeploymentResponse> result = restTemplate.exchange(url, HttpMethod.PUT, new HttpEntity<DeploymentRequest>(deploymentRequest, headers), + new ParameterizedTypeReference<DeploymentResponse>() { + }); + return result.getBody(); + } catch(HttpServerErrorException | HttpClientErrorException e) { + DeploymentErrorResponse errBody = null; + String errMsg = ""; + try { + errBody = objectMapper.readValue(e.getResponseBodyAsString(), DeploymentErrorResponse.class); + } catch (IOException e1) { + errBody = null; + } + if (errBody != null) { + errMsg = errBody.getMessage(); + } + StringBuilder errDetails = new StringBuilder(); + errDetails.append(e.getMessage()).append(" ").append(errMsg); + if (e.getStatusCode().value() == 400 || e.getStatusCode().value() == 415 || e.getStatusCode().value() == 404) { + throw new BadRequestException(errDetails.toString()); + } + else if(e.getStatusCode().value() == 409) { + throw new ServiceAlreadyExistsException(errDetails.toString()); + } + else if(e.getStatusCode().value() == 500) { + throw new ServerErrorException(errDetails.toString()); + } + else if(e.getStatusCode().value() == 502 || e.getStatusCode().value() == 504) { + throw new DownstreamException(errDetails.toString()); + } + } + return null; + } + + @Override + public DeploymentResponse updateDeployment(String deploymentId, String tenant, + DeploymentRequest deploymentRequest) throws BadRequestException, + ServiceAlreadyExistsException, + ServerErrorException, + DownstreamException { + String url = buildUrl(new String[] {baseUrl, UPDATE_PATH, deploymentId}, new String[] {"cfy_tenant_name",tenant}); + try { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + ResponseEntity<DeploymentResponse> result = restTemplate.exchange(url, HttpMethod.PUT, new HttpEntity<DeploymentRequest>(deploymentRequest, headers), + new ParameterizedTypeReference<DeploymentResponse>() { + }); + return result.getBody(); + } catch(HttpServerErrorException | HttpClientErrorException e) { + DeploymentErrorResponse errBody = null; + String errMsg = ""; + try { + errBody = objectMapper.readValue(e.getResponseBodyAsString(), DeploymentErrorResponse.class); + } catch (IOException e1) { + errBody = null; + } + if (errBody != null) { + errMsg = errBody.getMessage(); + } + StringBuilder errDetails = new StringBuilder(); + errDetails.append(e.getMessage()).append(" ").append(errMsg); + if (e.getStatusCode().value() == 400 || e.getStatusCode().value() == 415 || e.getStatusCode().value() == 404) { + throw new BadRequestException(errDetails.toString()); + } + else if(e.getStatusCode().value() == 409) { + throw new ServiceAlreadyExistsException(errDetails.toString()); + } + else if(e.getStatusCode().value() == 500) { + throw new ServerErrorException(errDetails.toString()); + } + else if(e.getStatusCode().value() == 502 || e.getStatusCode().value() == 504) { + throw new DownstreamException(errDetails.toString()); + } + } + return null; // Perhaps this should be a proper JSON error response. + } + + + @Override + public void deleteDeployment(String deploymentId, String tenant) + throws BadRequestException, ServerErrorException, DownstreamException, DeploymentNotFoundException { + String url = buildUrl(new String[] {baseUrl, DEPLOYMENTS, deploymentId}, new String[] {"cfy_tenant_name",tenant, "ignore_failure", "true"}); + try { + restTemplate.exchange(url, HttpMethod.DELETE, null, + new ParameterizedTypeReference<DeploymentResponse>() { + }); + } catch(HttpServerErrorException | HttpClientErrorException e) { + DeploymentErrorResponse errBody = null; + String errMsg = ""; + try { + errBody = objectMapper.readValue(e.getResponseBodyAsString(), DeploymentErrorResponse.class); + } catch (IOException e1) { + errBody = null; + } + if (errBody != null) { + errMsg = errBody.getMessage(); + } + StringBuilder errDetails = new StringBuilder(); + errDetails.append(e.getMessage()).append(" ").append(errMsg); + if (e.getStatusCode().value() == 400 || e.getStatusCode().value() == 415) { + throw new BadRequestException(errDetails.toString()); + } + else if (e.getStatusCode().value() == 404) { + throw new DeploymentNotFoundException(e.getMessage()); + } + else if(e.getStatusCode().value() == 500) { + throw new ServerErrorException(errDetails.toString()); + } + else if(e.getStatusCode().value() == 502 || e.getStatusCode().value() == 504) { + throw new DownstreamException(errDetails.toString()); + } + } + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/HttpComponentsClientHttpRequestFactoryBasicAuth.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/HttpComponentsClientHttpRequestFactoryBasicAuth.java index 77ccda0..7af5a20 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/HttpComponentsClientHttpRequestFactoryBasicAuth.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/HttpComponentsClientHttpRequestFactoryBasicAuth.java @@ -1,24 +1,3 @@ -/******************************************************************************* - * =============LICENSE_START========================================================= - * - * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - *******************************************************************************/ package org.onap.ccsdk.dashboard.rest; import java.net.URI; @@ -52,10 +31,9 @@ public class HttpComponentsClientHttpRequestFactoryBasicAuth extends HttpCompone this.host = host; } - @Override - protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { - return createHttpContext(); - } + protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { + return createHttpContext(); + } private HttpContext createHttpContext() { // Create AuthCache instance diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/IControllerRestClient.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/IControllerRestClient.java deleted file mode 100644 index 5e060e9..0000000 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/IControllerRestClient.java +++ /dev/null @@ -1,247 +0,0 @@ -/******************************************************************************* - * =============LICENSE_START========================================================= - * - * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - *******************************************************************************/ -package org.onap.ccsdk.dashboard.rest; - -import java.net.URI; -import java.time.Instant; -import java.util.List; - -import org.onap.ccsdk.dashboard.model.CloudifyBlueprintContent; -import org.onap.ccsdk.dashboard.model.CloudifyBlueprintList; -import org.onap.ccsdk.dashboard.model.CloudifyBlueprintUpload; -import org.onap.ccsdk.dashboard.model.CloudifyDeploymentList; -import org.onap.ccsdk.dashboard.model.CloudifyDeploymentRequest; -import org.onap.ccsdk.dashboard.model.CloudifyExecution; -import org.onap.ccsdk.dashboard.model.CloudifyExecutionList; -import org.onap.ccsdk.dashboard.model.CloudifyExecutionRequest; -import org.onap.ccsdk.dashboard.model.ConsulDatacenter; -import org.onap.ccsdk.dashboard.model.ConsulHealthServiceRegistration; -import org.onap.ccsdk.dashboard.model.ConsulNodeInfo; -import org.onap.ccsdk.dashboard.model.ConsulServiceHealth; -import org.onap.ccsdk.dashboard.model.ConsulServiceHealthHistory; -import org.onap.ccsdk.dashboard.model.ConsulServiceInfo; - -/** - * Defines the interface of the Controller REST client. - */ -public interface IControllerRestClient { - - 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(); -} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/InventoryClient.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/InventoryClient.java new file mode 100644 index 0000000..d9f03ad --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/InventoryClient.java @@ -0,0 +1,167 @@ +package org.onap.ccsdk.dashboard.rest; + +import java.util.Optional; +import java.util.Set; +import java.util.stream.Stream; + +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceAlreadyDeactivatedException; +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceNotFoundException; +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeActiveException; +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeAlreadyDeactivatedException; +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeNotFoundException; +import org.onap.ccsdk.dashboard.model.inventory.InventoryProperty; +import org.onap.ccsdk.dashboard.model.inventory.Service; +import org.onap.ccsdk.dashboard.model.inventory.ServiceQueryParams; +import org.onap.ccsdk.dashboard.model.inventory.ServiceRefList; +import org.onap.ccsdk.dashboard.model.inventory.ServiceType; +import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeQueryParams; +import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeRequest; + +/** + * Defines the interface of the Inventory Client. + */ +public interface InventoryClient { + + /** + * Gets a list of all DCAE Service Type objects. + * + * @return Collection<ServiceType> + */ + public Stream<ServiceType> getServiceTypes(); + + /** + * Gets a list of all DCAE Service Type objects that fall under a specified filter. + * + * @param serviceTypeQueryParams + * ServiceTypeQueryParams object containing query parameters. + * + * @return Collection<ServiceType> + */ + public Stream<ServiceType> getServiceTypes(ServiceTypeQueryParams serviceTypeQueryParams); + + /** + * Inserts a new DCAE Service Type, or updates an existing instance associated with the name typeName. + * Updates are only allowed iff there are no running DCAE services of the requested type. + * + * @param serviceType + * Service Type to be uploaded. + * + * @return ServiceType + * + * @throws ServiceTypeActiveException if the service type exists and has active instances + */ + public ServiceType addServiceType(ServiceType serviceType) throws ServiceTypeActiveException; + + /** + * Inserts a new DCAE Service Type, or updates an existing instance associated with the name typeName. + * Updates are only allowed iff there are no running DCAE services of the requested type. + * + * @param serviceType + * Service Type to be uploaded. + * @return + * + * @throws ServiceTypeActiveException if the service type exists and has active instances + */ + public ServiceType addServiceType(ServiceTypeRequest serviceTypeRequest) throws ServiceTypeActiveException; + + /** + * Gets a single DCAE Service Type object with the ID typeId. + * + * @param typeId + * ID of the DCAE Service Type to be retrieved. + * + * @return Optional<ServiceType> + */ + public Optional<ServiceType> getServiceType(String typeId); + + /** + * Deactivates an existing DCAE Service Type instance with the ID typeId. + * + * @param typeId + * ID of the DCAE Service Type to be deactivated. + * + * @exception ServiceTypeNotFoundException + * Thrown if the DCAE Service Type is not found. + * + * @exception ServiceTypeAlreadyDeactivatedException + * Thrown if the DCAE Service Type is already deactivated. + */ + public void deleteServiceType(String typeId) throws ServiceTypeNotFoundException, ServiceTypeAlreadyDeactivatedException; + + /** + * Gets a list of all DCAE Service objects. + * + * @return Collection<Service> + */ + public Stream<Service> getServices(); + + /** + * Gets a list of all DCAE Service objects that fall under a specified filter. + * + * @param serviceQueryParams + * ServiceQueryParams object containing query parameters. + * + * @return Collection<Service> + */ + public Stream<Service> getServices(ServiceQueryParams serviceQueryParams); + + /** + * Gets a list of all DCAE Service References that match a service type filter. + * + * @param serviceQueryParams + * ServiceQueryParams object containing query parameters. + * + * @return ServiceRefList + */ + public ServiceRefList getServicesForType(ServiceQueryParams serviceQueryParams); + + /** + * Gets a set of properties on Service objects that match the provided propertyName + * + * @param propertyName + * Property to find unique values. Restricted to type, vnfType, vnfLocation. + * + * @return Set<InventoryProperty> + */ + + public Set<InventoryProperty> getPropertiesOfServices(String propertyName); + + /** + * Gets a single DCAE Service object corresponding to the specified serviceId. + * + * @param serviceId + * Service ID of the DCAE Service to be retrieved. + * + * @return Service + */ + + public Optional<Service> getService(String serviceId); + + /** + * Puts a new DCAE Service with the specified serviceId, or updates an existing DCAE Service corresponding to the specified serviceId. + * + * @param typeId + * Type ID of the associated DCAE Service Type + * + * @param service + * DCAE Service to be uploaded. + */ + public void putService(String typeId, Service service); + + /** + * Deletes an existing DCAE Service object corresponding to the specified serviceId. + * + * @param serviceId + * Service ID of the DCAE Service to be deleted. + * + * @exception ServiceNotFoundException + * Thrown if the DCAE Service is not found. + * + * @exception ServiceAlreadyDeactivatedException + * Thrown if the DCAE Service is already deactivated. + * + */ + + public void deleteService(String serviceId) throws ServiceNotFoundException, ServiceAlreadyDeactivatedException; + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/RestClientBase.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/RestClientBase.java new file mode 100644 index 0000000..c2acb33 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/RestClientBase.java @@ -0,0 +1,96 @@ +/** + * + */ +package org.onap.ccsdk.dashboard.rest; + +import java.net.URL; + +import org.apache.http.HttpHost; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.web.client.RestTemplate; + +/** + * Base class for all the Rest client implementations + * + * @author rp5662 + * + */ +public class RestClientBase { + protected RestTemplate restTemplate = null; + + protected void createRestTemplate(URL url, String user, String pass, String urlScheme) { + RestTemplate restTempl = null; + final HttpHost httpHost = new HttpHost(url.getHost(), url.getPort(), urlScheme); + + // Build a client with a credentials provider + CloseableHttpClient httpClient = null; + + if (user != null && pass != null) { + CredentialsProvider credsProvider = new BasicCredentialsProvider(); + credsProvider.setCredentials(new AuthScope(httpHost), new UsernamePasswordCredentials(user, pass)); + httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build(); + } else { + httpClient = HttpClientBuilder.create().build(); + } + // Create request factory + HttpComponentsClientHttpRequestFactoryBasicAuth requestFactory = new HttpComponentsClientHttpRequestFactoryBasicAuth( + httpHost); + requestFactory.setHttpClient(httpClient); + + // Put the factory in the template + restTempl = new RestTemplate(); + restTempl.setRequestFactory(requestFactory); + this.restTemplate = restTempl; + } + + /** + * Builds URL ensuring appropriate separators. The base comes from + * properties file so could have many problems. + * + * @param base + * @param suffix + * @param queryParams + * key-value pairs; i.e. must have an even number of entries. + * Ignored if null. + * @return + */ + protected String buildUrl(final String[] path, final String[] queryParams) { + StringBuilder sb = new StringBuilder(path[0]); + for (int p = 1; p < path.length; ++p) { + if (!path[p - 1].endsWith("/") && !path[p].startsWith("/")) + sb.append('/'); + sb.append(path[p]); + } + if (queryParams != null && queryParams.length > 0) { + sb.append('?'); + int i = 0; + while (i < queryParams.length) { + if (i > 0) + sb.append('&'); + sb.append(queryParams[i]); + sb.append('='); + sb.append(queryParams[i + 1]); + i += 2; + } + } + return sb.toString(); + } + /** + * Create Http Entity for the tenant header + * + * @param tenant + * @return + */ + protected HttpEntity<String> getTenantHeader(String tenant) { + HttpHeaders headers = new HttpHeaders(); + headers.set("Tenant", tenant); + return new HttpEntity<String>("parameters", headers); + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/RestInventoryClientImpl.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/RestInventoryClientImpl.java new file mode 100644 index 0000000..6389db3 --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/RestInventoryClientImpl.java @@ -0,0 +1,344 @@ +package org.onap.ccsdk.dashboard.rest; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceAlreadyDeactivatedException; +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceNotFoundException; +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeAlreadyDeactivatedException; +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeNotFoundException; +import org.onap.ccsdk.dashboard.model.inventory.ApiResponseMessage; +import org.onap.ccsdk.dashboard.model.inventory.InventoryProperty; +import org.onap.ccsdk.dashboard.model.inventory.Link; +import org.onap.ccsdk.dashboard.model.inventory.Service; +import org.onap.ccsdk.dashboard.model.inventory.ServiceGroupByResults; +import org.onap.ccsdk.dashboard.model.inventory.ServiceList; +import org.onap.ccsdk.dashboard.model.inventory.ServiceQueryParams; +import org.onap.ccsdk.dashboard.model.inventory.ServiceRef; +import org.onap.ccsdk.dashboard.model.inventory.ServiceRefList; +import org.onap.ccsdk.dashboard.model.inventory.ServiceRequest; +import org.onap.ccsdk.dashboard.model.inventory.ServiceType; +import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeList; +import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeQueryParams; +import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeRequest; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.HttpClientErrorException; + +public class RestInventoryClientImpl extends RestClientBase implements InventoryClient { + + private final String baseUrl; + //private final RestTemplate restTemplate; + public static final String SERVICE_TYPES = "dcae-service-types"; + public static final String SERVICES = "dcae-services"; + public static final String SERVICES_GROUPBY = "dcae-services-groupby"; + + public RestInventoryClientImpl(String webapiUrl) { + this(webapiUrl, null, null); + } + + /** + * Builds a restTemplate. If username and password are supplied, uses basic + * HTTP authentication. + * + * @param webapiUrl + * URL of the web endpoint + * @param user + * user name; ignored if null + * @param pass + * password + */ + public RestInventoryClientImpl(String webapiUrl, String user, String pass) { + super(); + if (webapiUrl == null) + throw new IllegalArgumentException("Null URL not permitted"); + URL url = null; + String urlScheme = "http"; + try { + url = new URL(webapiUrl); + baseUrl = url.toExternalForm(); + } catch (MalformedURLException ex) { + throw new RuntimeException("Failed to parse URL", ex); + } + urlScheme = webapiUrl.split(":")[0]; + createRestTemplate(url, user, pass, urlScheme); + } + + public Stream<ServiceType> getServiceTypes() { + String url = buildUrl(new String[] {baseUrl, SERVICE_TYPES}, null); + ResponseEntity<ServiceTypeList> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<ServiceTypeList>() { + }); + Collection<ServiceType> collection = response.getBody().items; + + // Continue retrieving items on the next page if they exist + Link nextLink = response.getBody().paginationLinks.nextLink; + while (nextLink != null) { + url = response.getBody().paginationLinks.nextLink.href; + response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<ServiceTypeList>() { + }); + collection.addAll(response.getBody().items); + nextLink = response.getBody().paginationLinks.nextLink; + } + + return collection.stream(); + } + + public Stream<ServiceType> getServiceTypes(ServiceTypeQueryParams serviceTypeQueryParams) { + + // Only utilize the parameters that aren't null + HashMap<String, String> map = new HashMap<>(); + if (serviceTypeQueryParams.getTypeName() != null) { + map.put("typeName", serviceTypeQueryParams.getTypeName()); + } + if (serviceTypeQueryParams.getOnlyLatest() != null) { + map.put("onlyLatest", Boolean.toString(serviceTypeQueryParams.getOnlyLatest())); + } + if (serviceTypeQueryParams.getOnlyActive() != null) { + map.put("onlyActive", Boolean.toString(serviceTypeQueryParams.getOnlyActive())); + } + if (serviceTypeQueryParams.getVnfType() != null) { + map.put("vnfType", serviceTypeQueryParams.getVnfType()); + } + if (serviceTypeQueryParams.getServiceId() != null) { + map.put("serviceId", serviceTypeQueryParams.getServiceId()); + } + if (serviceTypeQueryParams.getServiceLocation() != null) { + map.put("serviceLocation", serviceTypeQueryParams.getServiceLocation()); + } + if (serviceTypeQueryParams.getAsdcServiceId() != null) { + map.put("asdcServiceId", serviceTypeQueryParams.getAsdcServiceId()); + } + if (serviceTypeQueryParams.getAsdcResourceId() != null) { + map.put("asdcResourceId", serviceTypeQueryParams.getAsdcResourceId()); + } + ArrayList<String> params = new ArrayList<>(); + for (Entry<String, String> ent : map.entrySet()) { + params.add(ent.getKey()); + params.add(ent.getValue()); + } + + String url = buildUrl(new String[] {baseUrl, SERVICE_TYPES}, params.toArray(new String[params.size()])); + ResponseEntity<ServiceTypeList> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<ServiceTypeList>() { + }); + Collection<ServiceType> collection = response.getBody().items; + + // Continue retrieving items on the next page if they exist + Link nextLink = response.getBody().paginationLinks.nextLink; + while (nextLink != null) { + url = response.getBody().paginationLinks.nextLink.href; + response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<ServiceTypeList>() { + }); + collection.addAll(response.getBody().items); + nextLink = response.getBody().paginationLinks.nextLink; + } + + return collection.stream(); + } + + + public ServiceType addServiceType(ServiceType serviceType) { + String url = buildUrl(new String[] { baseUrl, SERVICE_TYPES }, null); + + //Take the ServiceType object and create a ServiceTypeRequest from it + ServiceTypeRequest serviceTypeRequest = ServiceTypeRequest.from(serviceType); + + return restTemplate.postForObject(url, serviceTypeRequest, ServiceType.class); + } + + public ServiceType addServiceType(ServiceTypeRequest serviceTypeRequest) { + String url = buildUrl(new String[] { baseUrl, SERVICE_TYPES }, null); + + return restTemplate.postForObject(url, serviceTypeRequest, ServiceType.class); + } + + public Optional<ServiceType> getServiceType(String typeId) { + String url = buildUrl(new String[] {baseUrl, SERVICE_TYPES, typeId}, null); + ResponseEntity<ServiceType> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<ServiceType>() { + }); + return Optional.ofNullable(response.getBody()); + } + + public void deleteServiceType(String typeId) throws ServiceTypeNotFoundException, ServiceTypeAlreadyDeactivatedException { + String url = buildUrl(new String[] {baseUrl, SERVICE_TYPES, typeId}, null); + try { + restTemplate.exchange(url, HttpMethod.DELETE, null, + new ParameterizedTypeReference<ApiResponseMessage>() { + }); + } catch (HttpClientErrorException e) { + if (e.getStatusCode().value() == 410) { + throw new ServiceTypeAlreadyDeactivatedException(e.getMessage()); + } + else if (e.getStatusCode().value() == 404) { + throw new ServiceTypeNotFoundException(e.getMessage()); + } + } + } + + + public Stream<Service> getServices() { + String url = buildUrl(new String[] {baseUrl, SERVICES}, null); + ResponseEntity<ServiceList> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<ServiceList>() { + }); + Collection<Service> collection = response.getBody().items; + + // Continue retrieving items on the next page if they exist + Link nextLink = response.getBody().paginationLinks.nextLink; + while (nextLink != null) { + url = response.getBody().paginationLinks.nextLink.href; + response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<ServiceList>() { + }); + collection.addAll(response.getBody().items); + nextLink = response.getBody().paginationLinks.nextLink; + } + + return collection.stream(); + } + + public ServiceRefList getServicesForType(ServiceQueryParams serviceQueryParams) { + + // Only utilize the typeId + HashMap<String, String> map = new HashMap<>(); + if (serviceQueryParams.getTypeId() != null) { + map.put("typeId", serviceQueryParams.getTypeId()); + } + ArrayList<String> params = new ArrayList<>(); + for (Entry<String, String> ent : map.entrySet()) { + params.add(ent.getKey()); + params.add(ent.getValue()); + } + + String url = buildUrl(new String[] {baseUrl, SERVICES}, params.toArray(new String[params.size()])); + ResponseEntity<ServiceList> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<ServiceList>() { + }); + Collection<Service> collection = response.getBody().items; + int itemCnt = response.getBody().totalCount; + + // Continue retrieving items on the next page if they exist + Link nextLink = response.getBody().paginationLinks.nextLink; + while (nextLink != null) { + url = response.getBody().paginationLinks.nextLink.href; + response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<ServiceList>() { + }); + collection.addAll(response.getBody().items); + nextLink = response.getBody().paginationLinks.nextLink; + } + + List<ServiceRef> srvcRefList = + collection.stream().map(e->e.createServiceRef()).collect(Collectors.toList()); + + return new ServiceRefList(srvcRefList, itemCnt); + } + + public Stream<Service> getServices(ServiceQueryParams serviceQueryParams) { + + // Only utilize the parameters that aren't null + HashMap<String, String> map = new HashMap<>(); + if (serviceQueryParams.getTypeId() != null) { + map.put("typeId", serviceQueryParams.getTypeId()); + } + if (serviceQueryParams.getVnfId() != null) { + map.put("vnfId", serviceQueryParams.getVnfId()); + } + if (serviceQueryParams.getVnfType() != null) { + map.put("vnfType", serviceQueryParams.getVnfType()); + } + if (serviceQueryParams.getVnfLocation() != null) { + map.put("vnfLocation", serviceQueryParams.getVnfLocation()); + } + if (serviceQueryParams.getComponentType() != null) { + map.put("componentType", serviceQueryParams.getComponentType()); + } + if (serviceQueryParams.getShareable() != null) { + map.put("shareable", Boolean.toString(serviceQueryParams.getShareable())); + } + if (serviceQueryParams.getCreated() != null) { + map.put("created", serviceQueryParams.getCreated()); + } + ArrayList<String> params = new ArrayList<>(); + for (Entry<String, String> ent : map.entrySet()) { + params.add(ent.getKey()); + params.add(ent.getValue()); + } + + String url = buildUrl(new String[] {baseUrl, SERVICES}, params.toArray(new String[params.size()])); + ResponseEntity<ServiceList> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<ServiceList>() { + }); + Collection<Service> collection = response.getBody().items; + + // Continue retrieving items on the next page if they exist + Link nextLink = response.getBody().paginationLinks.nextLink; + while (nextLink != null) { + url = response.getBody().paginationLinks.nextLink.href; + response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<ServiceList>() { + }); + collection.addAll(response.getBody().items); + nextLink = response.getBody().paginationLinks.nextLink; + } + + return collection.stream(); + } + + public Set<InventoryProperty> getPropertiesOfServices(String propertyName) { + String url = buildUrl(new String[] {baseUrl, SERVICES_GROUPBY, propertyName}, null); + ResponseEntity<ServiceGroupByResults> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<ServiceGroupByResults>() { + }); + return response.getBody().propertyValues; + } + + public Optional<Service> getService(String serviceId) { + String url = buildUrl(new String[] {baseUrl, SERVICES, serviceId}, null); + ResponseEntity<Service> response = restTemplate.exchange(url, HttpMethod.GET, null, + new ParameterizedTypeReference<Service>() { + }); + return Optional.ofNullable(response.getBody()); + } + + public void putService(String typeId, Service service) { + String url = buildUrl(new String[] {baseUrl, SERVICES, service.getServiceId()}, null); + + ServiceRequest serviceRequest = ServiceRequest.from(typeId, service); + + restTemplate.exchange(url, HttpMethod.PUT, new HttpEntity<ServiceRequest>(serviceRequest), + new ParameterizedTypeReference<Service>() { + }); + } + + public void deleteService(String serviceId) throws ServiceNotFoundException, ServiceAlreadyDeactivatedException { + String url = buildUrl(new String[] {baseUrl, SERVICES, serviceId}, null); + try { + restTemplate.exchange(url, HttpMethod.DELETE, null, + new ParameterizedTypeReference<ApiResponseMessage>() { + }); + } catch (HttpClientErrorException e) { + if (e.getStatusCode().value() == 410) { + throw new ServiceAlreadyDeactivatedException(e.getMessage()); + } + else if (e.getStatusCode().value() == 404) { + throw new ServiceNotFoundException(e.getMessage()); + } + } + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/RestInventoryClientMockImpl.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/RestInventoryClientMockImpl.java new file mode 100644 index 0000000..75d373a --- /dev/null +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/RestInventoryClientMockImpl.java @@ -0,0 +1,169 @@ +package org.onap.ccsdk.dashboard.rest; + +import java.io.InputStream; +import java.util.Collection; +import java.util.Optional; +import java.util.Scanner; +import java.util.Set; +import java.util.stream.Stream; + +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceAlreadyDeactivatedException; +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceNotFoundException; +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeActiveException; +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeAlreadyDeactivatedException; +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeNotFoundException; +import org.onap.ccsdk.dashboard.model.ECTransportModel; +import org.onap.ccsdk.dashboard.model.inventory.InventoryProperty; +import org.onap.ccsdk.dashboard.model.inventory.Service; +import org.onap.ccsdk.dashboard.model.inventory.ServiceList; +import org.onap.ccsdk.dashboard.model.inventory.ServiceQueryParams; +import org.onap.ccsdk.dashboard.model.inventory.ServiceRefList; +import org.onap.ccsdk.dashboard.model.inventory.ServiceType; +import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeList; +import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeQueryParams; +import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeRequest; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; + +public class RestInventoryClientMockImpl implements InventoryClient { + + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestInventoryClientMockImpl.class); + /** + * For mock outputs + */ + private final ObjectMapper objectMapper = new ObjectMapper(); + + public RestInventoryClientMockImpl() { + // Do not serialize null values + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + // Register Jdk8Module() for Stream and Optional types + objectMapper.registerModule(new Jdk8Module()); + } + + private String getMockDataContent(final String path) { + String result = null; + try { + InputStream is = getClass().getResourceAsStream(path); + if (is == null) + throw new Exception("Failed to find resource at path " + path); + Scanner scanner = new Scanner(is, "UTF-8"); + result = scanner.useDelimiter("\\A").next(); + scanner.close(); + is.close(); + } catch (Exception ex) { + logger.error("getMockDataContent failed", ex); + throw new RuntimeException(ex); + } + return result; + } + + /** + * Creates an input stream using the specified path and requests the mapper + * create an object of the specified type. + * + * @param modelClass + * Model class + * @param path + * Path to classpath resource + * @return Instance of modelClass + */ + private ECTransportModel getMockData(final Class<? extends ECTransportModel> modelClass, final String path) { + ECTransportModel result = null; + String json = getMockDataContent(path); + try { + result = (ECTransportModel) objectMapper.readValue(json, modelClass); + } catch (Exception ex) { + logger.error("getMockData failed", ex); + throw new RuntimeException(ex); + } + return result; + } + + @Override + public Stream<ServiceType> getServiceTypes() { + ServiceTypeList mockData = (ServiceTypeList)getMockData(ServiceTypeList.class, "/serviceTypesList.json"); + Collection<ServiceType> collection = mockData.items; + + return collection.stream(); + } + + @Override + public Stream<ServiceType> getServiceTypes(ServiceTypeQueryParams serviceTypeQueryParams) { + ServiceTypeList mockData = (ServiceTypeList)getMockData(ServiceTypeList.class, "/serviceTypesList.json"); + Collection<ServiceType> collection = mockData.items; + + return collection.stream(); + } + + @Override + public ServiceRefList getServicesForType(ServiceQueryParams serviceQueryParams) { + return null; + } + @Override + public ServiceType addServiceType(ServiceType serviceType) throws ServiceTypeActiveException { + // TODO Auto-generated method stub + return null; + } + + @Override + public ServiceType addServiceType(ServiceTypeRequest serviceTypeRequest) throws ServiceTypeActiveException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Optional<ServiceType> getServiceType(String typeId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void deleteServiceType(String typeId) + throws ServiceTypeNotFoundException, ServiceTypeAlreadyDeactivatedException { + // TODO Auto-generated method stub + + } + + @Override + public Stream<Service> getServices() { + ServiceList mockData = (ServiceList)getMockData(ServiceList.class, "/serviceList.json"); + Collection<Service> collection = mockData.items; + + return collection.stream(); + } + + @Override + public Stream<Service> getServices(ServiceQueryParams serviceQueryParams) { + ServiceList mockData = (ServiceList)getMockData(ServiceList.class, "/serviceList.json"); + Collection<Service> collection = mockData.items; + + return collection.stream(); + } + + @Override + public Set<InventoryProperty> getPropertiesOfServices(String propertyName) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Optional<Service> getService(String serviceId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void putService(String typeId, Service service) { + // TODO Auto-generated method stub + + } + + @Override + public void deleteService(String serviceId) throws ServiceNotFoundException, ServiceAlreadyDeactivatedException { + // TODO Auto-generated method stub + + } +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/service/ControllerEndpointService.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/service/ControllerEndpointService.java index 621de95..2db0af0 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/service/ControllerEndpointService.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/service/ControllerEndpointService.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,13 @@ * * ECOMP is a trademark and service mark of AT&T Intellectual Property. *******************************************************************************/ + package org.onap.ccsdk.dashboard.service; +import java.util.List; + import org.onap.ccsdk.dashboard.domain.ControllerEndpoint; +import org.onap.ccsdk.dashboard.domain.EcdComponent; /** * Provides methods for managing the user's selection of controller endpoint. @@ -56,4 +60,19 @@ public interface ControllerEndpointService { */ void deleteControllerEndpointSelection(long userId); + /** + * Gets all component names that are currently supported through + * ECOMPC dashboard + * + * @return Component instance list; + */ + public List<EcdComponent> getComponents(); + + /** + * + * Add a new component to support in ECOMPC platform + * + * @param component + */ + void insertComponent(EcdComponent component); } diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/service/ControllerEndpointServiceImpl.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/service/ControllerEndpointServiceImpl.java index b4b3c97..88fd53b 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/service/ControllerEndpointServiceImpl.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/service/ControllerEndpointServiceImpl.java @@ -1,76 +1,120 @@ -/*******************************************************************************
- * =============LICENSE_START=========================================================
- *
- * =================================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *******************************************************************************/
-package org.onap.ccsdk.dashboard.service;
-
-import org.onap.ccsdk.dashboard.domain.ControllerEndpoint;
-import org.onap.portalsdk.core.service.DataAccessService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-/**
- * Complete controller endpoint information is in properties. The database just
- * stores the user's selection. Users are not expected to enter credentials so
- * this hybrid solution keeps credentials out of the database.
- */
-@Service("controllerEndpointService")
-@Transactional
-public class ControllerEndpointServiceImpl implements ControllerEndpointService {
-
- @Autowired
- private DataAccessService dataAccessService;
-
- /**
- * @return Data access service
- */
- public DataAccessService getDataAccessService() {
- return dataAccessService;
- }
-
- /**
- * @param dataAccessService
- * Data access service
- */
- public void setDataAccessService(DataAccessService dataAccessService) {
- this.dataAccessService = dataAccessService;
- }
-
- @Override
- public ControllerEndpoint getControllerEndpointSelection(long userId) {
- return (ControllerEndpoint) getDataAccessService()
- .getDomainObject(ControllerEndpoint.class, userId, null);
- }
-
- @Override
- public void updateControllerEndpointSelection(ControllerEndpoint endpoint) {
- getDataAccessService().saveDomainObject(endpoint, null);
- }
-
- @Override
- public void deleteControllerEndpointSelection(long userId) {
- ControllerEndpoint dbEntry = (ControllerEndpoint) getDataAccessService()
- .getDomainObject(ControllerEndpoint.class, userId, null);
- if (dbEntry != null)
- getDataAccessService().deleteDomainObject(dbEntry, null);
- }
-
-}
+/******************************************************************************* + * =============LICENSE_START========================================================= + * + * ================================================================================= + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + *******************************************************************************/ + +package org.onap.ccsdk.dashboard.service; + +import org.onap.ccsdk.dashboard.domain.ControllerEndpoint; +import org.onap.ccsdk.dashboard.domain.EcdComponent; + +import java.util.List; + +import org.onap.portalsdk.core.service.DataAccessService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * Complete controller endpoint information is in properties. The database just + * stores the user's selection. Users are not expected to enter credentials so + * this hybrid solution keeps credentials out of the database. + */ +@Service("controllerEndpointService") +@Transactional +public class ControllerEndpointServiceImpl implements ControllerEndpointService { + + @Autowired + private DataAccessService dataAccessService; + + /** + * @return Data access service + */ + public DataAccessService getDataAccessService() { + return dataAccessService; + } + + /** + * @param dataAccessService + * Data access service + */ + public void setDataAccessService(DataAccessService dataAccessService) { + this.dataAccessService = dataAccessService; + } + + /* + * (non-Javadoc) + * + * @see + * org.openecomp.controller.dashboard.service.ControllerEndpointService# + * getControllerEndpoint(java.lang.Integer) + */ + @Override + public ControllerEndpoint getControllerEndpointSelection(long userId) { + return (ControllerEndpoint) getDataAccessService() + .getDomainObject(ControllerEndpoint.class, userId, null); + } + + /* + * (non-Javadoc) + * + * @see + * org.openecomp.controller.dashboard.service.ControllerEndpointService# + * getComponents() + */ + @SuppressWarnings("unchecked") + @Override + public List<EcdComponent> getComponents() { + return dataAccessService.executeNamedQuery("getAllComponents", null, null); + } + + @Override + public void insertComponent(EcdComponent component) { + dataAccessService.saveDomainObject(component, null); + } + /* + * (non-Javadoc) + * + * @see + * org.openecomp.controller.dashboard.service.ControllerEndpointService# + * updateControllerEndpoint(org.openecomp.controller.dashboard.domain. + * ControllerEndpoint) + */ + @Override + public void updateControllerEndpointSelection(ControllerEndpoint endpoint) { + getDataAccessService().saveDomainObject(endpoint, null); + } + + /* + * // (non-Javadoc) + * + * @see + * org.openecomp.controller.dashboard.service.ControllerEndpointService# + * deleteControllerEndpoint(java.lang.Integer) + */ + @Override + public void deleteControllerEndpointSelection(long userId) { + ControllerEndpoint dbEntry = (ControllerEndpoint) getDataAccessService() + .getDomainObject(ControllerEndpoint.class, userId, null); + if (dbEntry != null) + getDataAccessService().deleteDomainObject(dbEntry, null); + } + +} diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/util/DashboardProperties.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/util/DashboardProperties.java index 717be11..a04a76e 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/util/DashboardProperties.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/util/DashboardProperties.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ * * ECOMP is a trademark and service mark of AT&T Intellectual Property. *******************************************************************************/ + package org.onap.ccsdk.dashboard.util; import org.springframework.beans.factory.annotation.Autowired; @@ -58,25 +59,67 @@ public class DashboardProperties { */ public static final String CONTROLLER_SUBKEY_URL = "url"; /** + * Subkey for property with Inventory URL + */ + public static final String CONTROLLER_SUBKEY_INVENTORY_URL = "inventory.url"; + /** + * Subkey for property with Deployment Handler URL + */ + public static final String CONTROLLER_SUBKEY_DHANDLER_URL = "dhandler.url"; + /** + * Subkey for property with Consul URL + */ + public static final String CONTROLLER_SUBKEY_CONSUL_URL = "consul.url"; + /** * Subkey for property with Controller user name for authentication */ public static final String CONTROLLER_SUBKEY_USERNAME = "username"; /** * Subkey for property with Controller password */ - public static final String CONTROLLER_SUBKEY_PASSWORD = "password"; + public static final String CONTROLLER_SUBKEY_PASS = "password"; /** * Subkey for property with Controller password encryption status */ public static final String CONTROLLER_SUBKEY_ENCRYPTED = "is_encrypted"; - - private Environment environment; - /** - * No-arg constructor + * Key for dashboard deployment environment - dev/uat/prod */ - public DashboardProperties() { - } + public static final String CONTROLLER_IN_ENV = "controller.env"; + + /** + * Key for cloudify tenant environment + */ + public static final String CLOUDIFY_TENANT_PRIM = "cloudify.tenant.primary"; + + /** + * Key for aic tenant environment + */ + public static final String AIC_TENANT_PRIM = "aic.tenant.primary"; + + /** + * Key for controller type: ATT or OS + */ + public static final String CONTROLLER_TYPE = "controller.type"; + + /** Key for K8s deploy permission string + * + */ + public static final String APP_K8S_PERM = "k8s.deploy.perm"; + + public static final String OPS_K8S_URL = "ops.k8s.url"; + + public static final String OPS_GRAFANA_URL = "ops.grf.url"; + + public static final String OPS_CLOUDIFY_URL = "ops.cfy.url"; + + public static final String OPS_CONSUL_URL = "ops.cnsl.url"; + + public static final String OPS_PROMETHEUS_URL = "ops.prom.url"; + + public static final String OPS_DBCL_URL = "ops.dbcl.url"; + + private static Environment environment; protected Environment getEnvironment() { return environment; @@ -96,7 +139,7 @@ public class DashboardProperties { * Property key * @return True or false */ - public boolean containsProperty(final String key) { + public static boolean containsProperty(final String key) { return environment.containsProperty(key); } @@ -105,16 +148,25 @@ public class DashboardProperties { * Property key * @return String value; throws unchecked exception if key is not found */ - public String getProperty(final String key) { + public static String getProperty(final String key) { return environment.getRequiredProperty(key); } /** * @param key * Property key + * @return String value; throws unchecked exception if key is not found + */ + public static String getPropertyDef(final String key, String defVal) { + return environment.getProperty(key, defVal); + } + + /** + * @param key + * Property key * @return True or False; null if key is not found */ - public Boolean getBooleanProperty(final String key) { + public static Boolean getBooleanProperty(final String key) { final String value = getProperty(key); return Boolean.parseBoolean(value); } @@ -128,7 +180,7 @@ public class DashboardProperties { * @return Array of values with leading and trailing whitespace removed; * null if key is not found. */ - public String[] getCsvListProperty(final String key) { + public static String[] getCsvListProperty(final String key) { String listVal = getProperty(key); if (listVal == null) return null; @@ -146,7 +198,7 @@ public class DashboardProperties { * Second part of key * @return Property value for key "controllerKey.propKey" */ - public String getControllerProperty(final String controllerKey, final String propKey) { + public static String getControllerProperty(final String controllerKey, final String propKey) { final String key = controllerKey + '.' + propKey; return getProperty(key); } diff --git a/ccsdk-app-common/src/main/java/org/onap/fusionapp/service/AdminAuthExtension.java b/ccsdk-app-common/src/main/java/org/onap/fusionapp/service/AdminAuthExtension.java index 365ee05..644d332 100644 --- a/ccsdk-app-common/src/main/java/org/onap/fusionapp/service/AdminAuthExtension.java +++ b/ccsdk-app-common/src/main/java/org/onap/fusionapp/service/AdminAuthExtension.java @@ -2,7 +2,7 @@ * =============LICENSE_START=========================================================
*
* =================================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/ccsdk-app-common/src/main/java/org/onap/fusionapp/util/CustomLoggingFilter.java b/ccsdk-app-common/src/main/java/org/onap/fusionapp/util/CustomLoggingFilter.java index 1f08b88..165a8b8 100644 --- a/ccsdk-app-common/src/main/java/org/onap/fusionapp/util/CustomLoggingFilter.java +++ b/ccsdk-app-common/src/main/java/org/onap/fusionapp/util/CustomLoggingFilter.java @@ -2,7 +2,7 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/CloudifyControllerTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/CloudifyControllerTest.java new file mode 100644 index 0000000..ff6aa24 --- /dev/null +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/CloudifyControllerTest.java @@ -0,0 +1,90 @@ +package org.onap.ccsdk.dashboard.controller; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.ccsdk.dashboard.core.MockUser; +import org.onap.ccsdk.dashboard.model.CloudifyTenantList; +import org.onap.ccsdk.dashboard.rest.CloudifyClient; +import org.onap.ccsdk.dashboard.core.MockitoTestSuite; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.springframework.test.web.servlet.RequestBuilder; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import org.springframework.http.MediaType; + + +public class CloudifyControllerTest extends MockitoTestSuite { + + @Mock + private CloudifyClient restClient; + + @InjectMocks + private CloudifyController subject = new CloudifyController(); + + protected final ObjectMapper objectMapper = new ObjectMapper(); + + @Mock + UserUtils userUtils = new UserUtils(); + + @Mock + User epuser; + + MockUser mockUser = new MockUser(); + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + objectMapper.registerModule(new Jdk8Module()); + } + + @Test + public final void testGetControllerEndpoints_stubbed() { + + } + + @Test + public final void testGetTenants_stubbed() throws Exception { + + String tenantsList = + "{\"items\": [{\"id\": 1, \"name\": \"default_tenant\", \"dName\": \"default_tenant\" }, " + + "{\"id\": 2, \"name\": \"dyh1b1902\", \"dName\": \"dyh1b1902\"}], " + + "\"metadata\": {\"pagination\": {\"total\": 2, \"offset\": 0, \"size\": 0}}}"; + CloudifyTenantList sampleData = null; + try { + sampleData = objectMapper.readValue(tenantsList, CloudifyTenantList.class); + } catch (Exception e) { + } + + User user = mockUser.mockUser(); + user.setLoginId("tester"); + MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); + + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(restClient.getTenants()).thenReturn(sampleData); + + RequestBuilder request = MockMvcRequestBuilders. + get("/tenants"). + accept(MediaType.APPLICATION_JSON); + + String tenantStr = + subject.getTenants(mockedRequest); + + assertNotNull(tenantStr); + assertTrue(tenantStr.contains("dyh1b")); + + + } + +} diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/core/MockUser.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/core/MockUser.java new file mode 100644 index 0000000..4b68c8e --- /dev/null +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/core/MockUser.java @@ -0,0 +1,65 @@ +package org.onap.ccsdk.dashboard.core; + +import java.util.Date; + +import org.onap.portalsdk.core.domain.User; + +public class MockUser { + + public User mockUser() { + + User ePUser = new User(); + ePUser.setOrgId(null); + ePUser.setManagerId(null); + ePUser.setFirstName("test"); + ePUser.setLastName("test"); + ePUser.setMiddleInitial(null); + ePUser.setPhone(null); + ePUser.setFax(null); + ePUser.setCellular(null); + ePUser.setEmail(null); + ePUser.setAddressId(null); + ePUser.setAlertMethodCd(null); + ePUser.setHrid(null); + ePUser.setOrgUserId("guestT"); + ePUser.setOrgCode(null); + ePUser.setAddress1(null); + ePUser.setAddress2(null); + ePUser.setCity(null); + ePUser.setState(null); + ePUser.setZipCode(null); + ePUser.setCountry(null); + ePUser.setOrgManagerUserId(null); + ePUser.setLocationClli(null); + ePUser.setBusinessCountryCode(null); + ePUser.setBusinessCountryName(null); + ePUser.setBusinessUnit(null); + ePUser.setBusinessUnitName(null); + ePUser.setDepartment(null); + ePUser.setDepartmentName(null); + ePUser.setCompanyCode(null); + ePUser.setCompany(null); + ePUser.setZipCodeSuffix(null); + ePUser.setJobTitle(null); + ePUser.setCommandChain(null); + ePUser.setSiloStatus(null); + ePUser.setCostCenter(null); + ePUser.setFinancialLocCode(null); + + ePUser.setLoginId(null); + ePUser.setLoginPwd(null); + Date date = new Date(); + ePUser.setLastLoginDate(date); + ePUser.setActive(true); + ePUser.setInternal(false); + ePUser.setSelectedProfileId(null); + ePUser.setTimeZoneId(null); + ePUser.setOnline(true); + ePUser.setChatId(null); + ePUser.setUserApps(null); + ePUser.setPseudoRoles(null); + + ePUser.setId((long) -1); + return ePUser; + } +} diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/core/MockitoTestSuite.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/core/MockitoTestSuite.java new file mode 100644 index 0000000..c251a5c --- /dev/null +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/core/MockitoTestSuite.java @@ -0,0 +1,95 @@ + +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.ccsdk.dashboard.core; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class MockitoTestSuite { + + + public MockHttpServletRequestWrapper mockedRequest = new MockHttpServletRequestWrapper( + Mockito.mock(HttpServletRequest.class)); + public HttpServletResponse mockedResponse = Mockito.mock(HttpServletResponse.class); + + public MockHttpServletRequestWrapper getMockedRequest() { + return mockedRequest; + } + + public HttpServletResponse getMockedResponse() { + return mockedResponse; + } + + public class MockHttpServletRequestWrapper extends HttpServletRequestWrapper { + + HttpSession session = Mockito.mock(HttpSession.class); + + public MockHttpServletRequestWrapper(HttpServletRequest request) { + super(request); + + } + + @Override + public HttpSession getSession() { + + return session; + } + + @Override + public HttpSession getSession(boolean create) { + + return session; + } + + } + + @Test + public void test() + { + assert(true); + } +}
\ No newline at end of file diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/CloudifyRestClientImplTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/CloudifyRestClientImplTest.java new file mode 100644 index 0000000..e7e51cf --- /dev/null +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/CloudifyRestClientImplTest.java @@ -0,0 +1,119 @@ +package org.onap.ccsdk.dashboard.rest; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.ccsdk.dashboard.model.CloudifyErrorCause; +import org.onap.ccsdk.dashboard.model.CloudifyEvent; +import org.onap.ccsdk.dashboard.model.CloudifyEventList; +import org.onap.ccsdk.dashboard.model.CloudifyEventList.Metadata; +import org.onap.ccsdk.dashboard.model.CloudifyTenantList; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; + +public class CloudifyRestClientImplTest { + + @Mock + RestTemplate mockRest; + + @InjectMocks + CloudifyRestClientImpl subject = + new CloudifyRestClientImpl("https://www.orcl.com/v3.1", "", ""); + + protected final ObjectMapper objectMapper = new ObjectMapper(); + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + objectMapper.registerModule(new Jdk8Module()); + } + + @Test + public final void getEventlogsTest() throws JsonParseException, JsonMappingException, IOException { + String executionId = "123a123a"; + String tenant = "thisTenant"; + List<CloudifyEvent> items = new ArrayList<CloudifyEvent>(); + CloudifyEvent aMockEvent = new CloudifyEvent("dcae_dtieventproc_idns-k8s-svc-blueprint_02_28_02", "dcae_dtieventproc_idns-k8s-svc-blueprint_02_28_02", + null, "workflow_succeeded", "5f8a2e05-e187-4925-90de-ece9160aa517", "warning", "ctx.7a10e191-f12b-4142-aa5d-6e5766ebb1d4", + "install workflow execution succeeded", "publish_l36bhr", "publish", "cloudify.interfaces.lifecycle.create", + "2019-02-28T23:17:49.228Z", "2019-02-28T23:17:49.700Z", "cloudify_event", "install"); + items.add(aMockEvent); + items.add( + new CloudifyEvent("dcae_dtieventproc_idns-k8s-svc-blueprint_02_28_02", "dcae_dtieventproc_idns-k8s-svc-blueprint_02_28_02", + null, "workflow_node_event", "5f8a2e05-e187-4925-90de-ece9160aa517", "warning", "ctx.7a10e191-f12b-4142-aa5d-6e5766ebb1d4", + "Starting node", "publish_l36bhr", "publish", "cloudify.interfaces.lifecycle.create", + "2019-02-28T23:17:48.391Z", "2019-02-28T23:17:48.516Z", "cloudify_event", "install")); + + String metaInfo = "metadata\": {\"pagination\": {\"total\": 2, \"offset\": 0, \"size\": 0}}"; + Metadata metadata = null; + //metadata = objectMapper.readValue(metaInfo, Metadata.class); + + CloudifyEventList expected = new CloudifyEventList(items, metadata); + + ResponseEntity<CloudifyEventList> response = new ResponseEntity<CloudifyEventList>(expected, HttpStatus.OK); + Mockito.when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(), + Matchers.<ParameterizedTypeReference<CloudifyEventList>>any())).thenReturn(response); + CloudifyEventList actual = subject.getEventlogs(executionId, tenant); + + assertTrue(actual.items.size() == 2); + + } + @Test + public final void testGetTenants_GetData() { + // define the entity you want the exchange to return + String tenantsList = "{\"items\": [{\"id\": 1, \"dName\": null, \"name\": \"default_tenant\"}, {\"id\": 2, \"dName\": null, \"name\": \"dyh1b1902\"}], \"metadata\": {\"pagination\": {\"total\": 2, \"offset\": 0, \"size\": 0}}}"; + CloudifyTenantList sampleData = null; + try { + sampleData = objectMapper.readValue(tenantsList, CloudifyTenantList.class); + } catch (Exception e) { + } + + ResponseEntity<CloudifyTenantList> response = new ResponseEntity<CloudifyTenantList>(sampleData, HttpStatus.OK); + Mockito.when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(), + Matchers.<ParameterizedTypeReference<CloudifyTenantList>>any())).thenReturn(response); + + CloudifyTenantList res = subject.getTenants(); + assertNotNull(res); + assertThat(res.items.get(1).name, is("dyh1b1902")); + // Assert.assertEquals(myobjectA, res.get(0)); + } + + @Test(expected = RestClientException.class) + public final void testGetTenants_withException() { + // define the entity you want the exchange to return + Mockito.when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(), + Matchers.<ParameterizedTypeReference<CloudifyTenantList>>any())).thenThrow(RestClientException.class); + + subject.getTenants(); + + + } +} diff --git a/ccsdk-app-common/src/test/java/org/onap/fusion/core/MockApplicationContextTestSuite.java b/ccsdk-app-common/src/test/java/org/onap/fusion/core/MockApplicationContextTestSuite.java deleted file mode 100644 index ccefdce..0000000 --- a/ccsdk-app-common/src/test/java/org/onap/fusion/core/MockApplicationContextTestSuite.java +++ /dev/null @@ -1,137 +0,0 @@ -/*******************************************************************************
- * =============LICENSE_START=========================================================
- *
- * =================================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *******************************************************************************/
-package org.onap.fusion.core;
-
-import java.io.IOException;
-
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.onap.portalsdk.core.conf.AppConfig;
-import org.onap.portalsdk.core.objectcache.AbstractCacheManager;
-import org.onap.portalsdk.core.util.CacheManager;
-import org.onap.portalsdk.core.util.SystemProperties;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Profile;
-import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.springframework.test.context.web.AnnotationConfigWebContextLoader;
-import org.springframework.test.context.web.WebAppConfiguration;
-import org.springframework.test.web.servlet.MockMvc;
-import org.springframework.test.web.servlet.setup.MockMvcBuilders;
-import org.springframework.web.context.WebApplicationContext;
-import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
-
-/**
- * In order to write a unit test, 1. inherit this class - See SanityTest.java 2.
- * place the "war" folder on your test class's classpath 3. run the test with
- * the following VM argument; This is important because when starting the
- * application from Container, the System Properties file
- * (SystemProperties.java) can have the direct path but, when running from the
- * Mock Junit container, the path should be prefixed with "classpath" to enable
- * the mock container to search for the file in the classpath
- * -Dcontainer.classpath="classpath:"
- *
- */
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@WebAppConfiguration
-@ContextConfiguration(loader = AnnotationConfigWebContextLoader.class, classes = { MockAppConfig.class })
-@ActiveProfiles(value = "test")
-public class MockApplicationContextTestSuite {
-
- @Autowired
- public WebApplicationContext wac;
-
- private MockMvc mockMvc;
-
- @Before
- public void setup() {
- if (mockMvc == null) {
- this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
-
- }
- }
-
- public Object getBean(String name) {
- return this.wac.getBean(name);
- }
-
- public MockMvc getMockMvc() {
- return mockMvc;
- }
-
- public void setMockMvc(MockMvc mockMvc) {
- this.mockMvc = mockMvc;
- }
-
- public WebApplicationContext getWebApplicationContext() {
- return wac;
- }
-
-}
-
-@Configuration
-@ComponentScan(basePackages = {"org.openecomp", "org.onap"}, excludeFilters = {
- // see AppConfig class
-})
-@Profile("test")
-class MockAppConfig extends AppConfig {
-
- @Bean
- public SystemProperties systemProperties() {
- return new MockSystemProperties();
- }
-
- @Bean
- public AbstractCacheManager cacheManager() {
- return new CacheManager() {
-
- public void configure() throws IOException {
-
- }
- };
- }
-
- protected String[] tileDefinitions() {
- return new String[] { "classpath:/WEB-INF/fusion/defs/definitions.xml",
- "classpath:/WEB-INF/defs/definitions.xml" };
- }
-
- @Override
- public void addInterceptors(InterceptorRegistry registry) {
- // registry.addInterceptor(new
- // SessionTimeoutInterceptor()).excludePathPatterns(getExcludeUrlPathsForSessionTimeout());
- // registry.addInterceptor(resourceInterceptor());
- }
-
- public static class MockSystemProperties extends SystemProperties {
-
- public MockSystemProperties() {
- }
-
- }
-
-}
|