diff options
author | 2019-03-15 12:25:28 -0400 | |
---|---|---|
committer | 2019-03-15 12:25:32 -0400 | |
commit | b46d863e9e5db30291034e8740291c70875f1f5f (patch) | |
tree | 6766ccb15edba5807a429278bf57ed8d241d2ce8 /ccsdk-app-common | |
parent | 2e98a6c64dcdc0891f3729abb045115b790a2c54 (diff) |
Resolve security issues
This change contains the following fixes:
1) Updated ccsdk/dashboard to use ONAP's oparent parent pom
2) Removed <version> tag from dependencies managed by oparent,
where feasible (e.g. not spring, since oparent uses Spring 5
and dashboard is based on Spring 4)
3) Updated versions of third party libraries as needed to address
vulnerabilities found in nexus IQ scan.
4) Added missing license headers in source files to resolve
checkstyle error from oparent.
5) Fixed indentation (tab -> 4 spaces) to resolve oparent
checkstyle warning.
Change-Id: Ib92d5ef86dbdb78c270d0901cc0753cd5a78eb6e
Issue-ID: CCSDK-1167
Signed-off-by: Timoney, Dan (dt5972) <dtimoney@att.com>
Diffstat (limited to 'ccsdk-app-common')
125 files changed, 11356 insertions, 10499 deletions
diff --git a/ccsdk-app-common/.checkstyle b/ccsdk-app-common/.checkstyle new file mode 100644 index 0000000..327b388 --- /dev/null +++ b/ccsdk-app-common/.checkstyle @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<fileset-config file-format-version="1.2.0" simple-config="false" sync-formatter="false"> + <local-check-config name="maven-checkstyle-plugin onap-license" location="jar:file:/Users/dt5972/.m2/repository/org/onap/oparent/checkstyle/1.2.3/checkstyle-1.2.3.jar!/onap-checkstyle/check-license.xml" type="remote" description="maven-checkstyle-plugin configuration onap-license"> + <property name="checkstyle.cache.file" value="${project_loc}/target/checkstyle-cachefile"/> + <property name="checkstyle.header.file" value="/Users/dt5972/eclipse/onap/.metadata/.plugins/org.eclipse.core.resources/.projects/ccsdk-app-common/com.basistech.m2e.code.quality.checkstyleConfigurator/checkstyle-header-onap-license.txt"/> + </local-check-config> + <local-check-config name="maven-checkstyle-plugin onap-java-style" location="jar:file:/Users/dt5972/.m2/repository/org/onap/oparent/checkstyle/1.2.3/checkstyle-1.2.3.jar!/onap-checkstyle/onap-java-style.xml" type="remote" description="maven-checkstyle-plugin configuration onap-java-style"> + <property name="checkstyle.cache.file" value="${project_loc}/target/checkstyle-cachefile"/> + <property name="checkstyle.header.file" value="/Users/dt5972/eclipse/onap/.metadata/.plugins/org.eclipse.core.resources/.projects/ccsdk-app-common/com.basistech.m2e.code.quality.checkstyleConfigurator/checkstyle-header-onap-java-style.txt"/> + </local-check-config> + <fileset name="java-sources-onap-license" enabled="true" check-config-name="maven-checkstyle-plugin onap-license" local="true"> + <file-match-pattern match-pattern="^src/test/java/.*\/.*\.java" include-pattern="true"/> + <file-match-pattern match-pattern="^src/main/java/.*\/.*\.java" include-pattern="true"/> + </fileset> + <fileset name="java-sources-onap-java-style" enabled="true" check-config-name="maven-checkstyle-plugin onap-java-style" local="true"> + <file-match-pattern match-pattern="^src/test/java/.*\/.*\.java" include-pattern="true"/> + <file-match-pattern match-pattern="^src/main/java/.*\/.*\.java" include-pattern="true"/> + <file-match-pattern match-pattern="^src/main/resources.*\.properties" include-pattern="true"/> + <file-match-pattern match-pattern="^src/test/resources.*\.properties" include-pattern="true"/> + </fileset> +</fileset-config> diff --git a/ccsdk-app-common/pom.xml b/ccsdk-app-common/pom.xml index e7a58c6..1f78337 100644 --- a/ccsdk-app-common/pom.xml +++ b/ccsdk-app-common/pom.xml @@ -2,6 +2,12 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.ccsdk.dashboard</groupId>
+ <artifactId>ccsdk-app-parent</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </parent>
<groupId>org.onap.ccsdk.dashboard</groupId>
<artifactId>ccsdk-app-common</artifactId>
@@ -9,10 +15,11 @@ <packaging>jar</packaging>
<name>ONAP Operations Manager Dashboard common</name>
<description>CCSDK Dashboard common Java code</description>
+
<properties>
<encoding>UTF-8</encoding>
- <springframework.version>4.2.0.RELEASE</springframework.version>
+ <springframework.version>4.3.22.RELEASE</springframework.version>
<hibernate.version>4.3.11.Final</hibernate.version>
<eelf.version>1.0.0</eelf.version>
<epsdk.version>2.5.1</epsdk.version>
@@ -22,6 +29,7 @@ <stagingNexusPath>/content/repositories/staging/</stagingNexusPath>
<skipTests>false</skipTests>
<jacocoVersion>0.7.6.201602180812</jacocoVersion>
+ <jackson.version>2.9.8</jackson.version>
</properties>
<repositories>
@@ -136,7 +144,6 @@ <plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
- <version>${jacocoVersion}</version>
<executions>
<execution>
<id>prepare-agent</id>
@@ -182,14 +189,14 @@ <!-- For using HTTP Basic Auth in uService REST client -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- <version>4.3.5</version>
+ <artifactId>httpclient</artifactId>
+ <!-- inherit version from oparent-->
</dependency>
<!-- Postgresql driver -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
- <version>9.3-1100-jdbc41</version>
+ <version>9.3-1104-jdbc41</version>
</dependency>
<!-- SDK components -->
<dependency>
@@ -216,32 +223,35 @@ <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
- <version>2.9.0</version>
+ <version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
- <version>2.9.0</version>
+ <!-- oparent defines this version, but not version for other jackson -->
+ <!-- artifacts. So, defined our own property, set to value from oparent -->
+ <!-- so that jackson artifacts can be kept in sync -->
+ <version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
- <version>2.9.0</version>
+ <version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
- <version>2.9.0</version>
+ <version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
- <version>2.9.0</version>
+ <version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
- <version>0.9.5.2</version>
+ <version>0.9.5.3</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
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 index 149708f..27b887a 100644 --- 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 @@ -35,114 +35,115 @@ 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; - } - - + 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 d7cdc6f..06ca980 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 @@ -81,1296 +81,1191 @@ import com.fasterxml.jackson.core.JsonProcessingException; @RequestMapping("/") public class CloudifyController extends DashboardRestrictedBaseController { - private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CloudifyController.class); - private CloudifyClient restClient; + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CloudifyController.class); + private CloudifyClient restClient; - /** - * Enum for selecting an item type. - */ - public enum CloudifyDataItem { - BLUEPRINT, DEPLOYMENT, EXECUTION, TENANT; - } + /** + * 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); - } - }; + 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 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 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 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 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 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; - } + /** + * 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); + } + }; - /** - * 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; - } + /** + * 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); + } + }; - /** - * 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; - } + /** + * 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; + } - /** - * 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 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; + } - /** - * 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; - } + /** + * 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; + } - /** - * 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); - } + /** + * 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 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); - } + /** + * 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; + } - /** - * 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); - } + /** + * 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); + } - /** - * 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 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); + } - /** - * 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); - } + /** + * 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); + } - /** - * 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); - } + /** + * 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); + } - 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); - } + /** + * 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); + } - /** - * 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); - } + /** + * 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>(); - /** - * 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); + 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); + } - // 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); - } + return objectMapper.writeValueAsString(cfyExecList); + } - /** - * 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); - } + /** + * 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); + } - /** - * 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); - } + /** + * 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 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); - } + /** + * 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); - /** - * 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); - } + // 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 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); - } + /** + * 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); + } - @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); - } + /** + * 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); + } - 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()); - } + /** + * 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 index 3c17288..efe2ab7 100644 --- 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 @@ -103,1124 +103,1093 @@ 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 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 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"; - private static Date begin, end; + @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 { + 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()); + 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; - } + /** + * 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 { - @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); + InventoryClient inventoryClient = getInventoryClient(); + String outboundJson = ""; + List itemList = null; - 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; - } + 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 { - /** - * 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; + 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(); - 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 { - - } + itemList = inventoryClient.getServiceTypes(serviceQueryParams).collect(Collectors.toList()); + List<BlueprintResponse> filterList = new ArrayList<BlueprintResponse>(); - 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(); + 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); - itemList = inventoryClient.getServiceTypes(serviceQueryParams).collect(Collectors.toList()); - List<BlueprintResponse> filterList = new ArrayList<BlueprintResponse>(); + RestResponsePage<List> model = new RestResponsePage<>(totalItems, pageCount, itemList); + outboundJson = objectMapper.writeValueAsString(model); - 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); + return outboundJson; + } - RestResponsePage<List> model = new RestResponsePage<>(totalItems, pageCount, itemList); - outboundJson = objectMapper.writeValueAsString(model); + @SuppressWarnings({ "rawtypes", "unchecked" }) + private String getBlueprintTypeId(String searchBy, Optional<Integer> version, String typeId) throws Exception { - return outboundJson; - } + InventoryClient inventoryClient = getInventoryClient(); + ServiceTypeQueryParams serviceQueryParams = null; - @SuppressWarnings({ "rawtypes", "unchecked" }) - private String getBlueprintTypeId(String searchBy, Optional<Integer> version, String typeId) throws Exception { + if (version.isPresent()) { + serviceQueryParams = new ServiceTypeQueryParams.Builder().typeName(searchBy).onlyLatest(false).build(); + } else { + serviceQueryParams = new ServiceTypeQueryParams.Builder().typeName(searchBy).build(); + } - InventoryClient inventoryClient = getInventoryClient(); - ServiceTypeQueryParams serviceQueryParams = null; + List itemList = inventoryClient.getServiceTypes(serviceQueryParams).collect(Collectors.toList()); - if (version.isPresent()) { - serviceQueryParams = new ServiceTypeQueryParams.Builder().typeName(searchBy).onlyLatest(false).build(); - } else { - serviceQueryParams = new ServiceTypeQueryParams.Builder().typeName(searchBy).build(); - } + 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(); + } - List itemList = inventoryClient.getServiceTypes(serviceQueryParams).collect(Collectors.toList()); + /** + * 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); + } - 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); - } + /** + * 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); + } - @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; + /** + * 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); + } - 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 = { + 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 + "/{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; - } + @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; - /** - * 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); - } + 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; - } + /** + * 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; + } - /** - * 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); - } + /** + * 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; + } - 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); - } + /** + * 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 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()); - } + 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 3aa7821..feb8dc5 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 @@ -65,419 +65,391 @@ import com.fasterxml.jackson.core.JsonProcessingException; @RequestMapping("/healthservices") public class ConsulController extends DashboardRestrictedBaseController { - private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ConsulController.class); + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ConsulController.class); - /** - * Enum for selecting an item type. - */ - public enum ConsulDataItem { - SERVICE_INFO, SERVICE_HEALTH, NODES, DATACENTERS; - } + /** + * Enum for selecting an item type. + */ + public enum ConsulDataItem { + SERVICE_INFO, SERVICE_HEALTH, NODES, DATACENTERS; + } - private static Date begin, end; - private static final String NODES_PATH = "/nodes"; - private static final String SERVICES_PATH = "/services"; + 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 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<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); - } - }; + /** + * 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 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; - } + /** + * 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 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 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 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 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; - } + /** + * 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; + /** + * 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"); + } - 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); - } + 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; - /** - * 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); - } + 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); + } - 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); - } + /** + * 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 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()); - } + 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 7ccdbf4..c5a624e 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 @@ -57,190 +57,184 @@ 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. + * 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); + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(DashboardHomeController.class); - @Autowired - private ControllerEndpointService controllerEndpointService; + @Autowired + private ControllerEndpointService controllerEndpointService; - /** - * For general use in these methods - */ - private final ObjectMapper mapper; + /** + * 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>(); - 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); - } + List<EcdComponent> dbResult = controllerEndpointService.getComponents(); - /** - * @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"); - } + List dcaeCompList = (List) dbResult.stream().filter(s -> ((EcdComponent) s).contains("dcae")) + .collect(Collectors.toList()); - /** - * 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; - } + 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; + } - /** - * 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 + * @param request HttpServletRequest + * @param endpoint Body with endpoint details * @return Result indicating success or failure - * @throws Exception - * if application user is not found + * @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 { + 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()); + RestResponseSuccess success = new RestResponseSuccess( + "Inserted new component with name " + newComponent.getCname()); outboundJson = mapper.writeValueAsString(success); postLogAudit(request); return outboundJson; @@ -249,154 +243,147 @@ public class DashboardHomeController extends DashboardRestrictedBaseController { /** * Gets the OPS Tools URLs from dashboard properties * - * @param request - * HttpServletRequest - * @return List of ControllerOpsTools objects, or an error on - * failure - * @throws Exception + * @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 = { 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; - } + @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; - } + /** + * 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 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()); - } + 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 809dbb9..441b529 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 @@ -58,413 +58,412 @@ import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; */ 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; - } + /** + * 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 index c99583c..1c3ac8f 100644 --- 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 @@ -60,184 +60,188 @@ import com.fasterxml.jackson.core.JsonProcessingException; @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; + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(DeploymentHandlerController.class); - @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; - } + private static final String DEPLOYMENTS_PATH = "dcae-deployments"; - @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; - } + private static Date begin, end; - 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); - } + @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; + } - 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()); - } + @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 de86a3e..c2330f4 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 @@ -85,218 +85,211 @@ import org.springframework.web.util.WebUtils; */ public class ECDSingleSignOnController extends UnRestrictedBaseController { - private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ECDSingleSignOnController.class); + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ECDSingleSignOnController.class); - @Autowired - private LoginService loginService; + @Autowired + private LoginService loginService; - @Autowired - private LoginStrategy loginStrategy; + @Autowired + private LoginStrategy loginStrategy; - @Autowired - private RoleService roleService; - - private String viewName; - private String welcomeView; + @Autowired + private RoleService roleService; - /** - * 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 { + private String viewName; + private String welcomeView; - Map<String, String> model = new HashMap<String, String>(); - HashMap<String, String> additionalParamsMap = new HashMap<String, String>(); - LoginBean commandBean = new LoginBean(); + /** + * 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 { - // SessionTimeoutInterceptor sets these parameters - String forwardURL = URLDecoder.decode(request.getParameter("forwardURL"), "UTF-8"); - String redirectToPortal = request.getParameter("redirectToPortal"); + Map<String, String> model = new HashMap<String, String>(); + HashMap<String, String> additionalParamsMap = new HashMap<String, String>(); + LoginBean commandBean = new LoginBean(); - if (isLoginCookieExist(request) && redirectToPortal == null) { - HttpSession session = null; - session = AppUtils.getSession(request); - User user = UserUtils.getUserSession(request); - if (session == null || user == null) { + // SessionTimeoutInterceptor sets these parameters + String forwardURL = URLDecoder.decode(request.getParameter("forwardURL"), "UTF-8"); + String redirectToPortal = request.getParameter("redirectToPortal"); - 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 + if (isLoginCookieExist(request) && redirectToPortal == null) { + HttpSession session = null; + session = AppUtils.getSession(request); + User user = UserUtils.getUserSession(request); + if (session == null || user == null) { - else { - /* - * Portal is not available. Redirect user to the login page, - * ignoring the forwardURL parameter. - */ - return new ModelAndView("redirect:login.htm"); - } + 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)); - } + /** + * 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; + } - public boolean isLoginCookieExist(HttpServletRequest request) { - Cookie ep = WebUtils.getCookie(request, LoginStrategy.EP_SERVICE); - return (ep != null); - } + protected void initateSessionMgtHandler(HttpServletRequest request) { + String portalJSessionId = getPortalJSessionId(request); + String jSessionId = getJessionId(request); + PortalTimeoutHandler.sessionCreated(portalJSessionId, jSessionId, AppUtils.getSession(request)); + } - public String getPortalJSessionId(HttpServletRequest request) { - Cookie ep = WebUtils.getCookie(request, LoginStrategy.EP_SERVICE); - return ep.getValue(); - } + public boolean isLoginCookieExist(HttpServletRequest request) { + Cookie ep = WebUtils.getCookie(request, LoginStrategy.EP_SERVICE); + return (ep != null); + } - public String getJessionId(HttpServletRequest request) { - return request.getSession().getId(); - } + public String getPortalJSessionId(HttpServletRequest request) { + Cookie ep = WebUtils.getCookie(request, LoginStrategy.EP_SERVICE); + return ep.getValue(); + } - public String getViewName() { - return viewName; - } + public String getJessionId(HttpServletRequest request) { + return request.getSession().getId(); + } - public void setViewName(String viewName) { - this.viewName = viewName; - } + public String getViewName() { + return viewName; + } - public String getWelcomeView() { - return welcomeView; - } + public void setViewName(String viewName) { + this.viewName = viewName; + } - public void setWelcomeView(String welcomeView) { - this.welcomeView = welcomeView; - } + public String getWelcomeView() { + return welcomeView; + } - public LoginService getLoginService() { - return loginService; - } + public void setWelcomeView(String welcomeView) { + this.welcomeView = welcomeView; + } - public void setLoginService(LoginService loginService) { - this.loginService = loginService; - } + 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 0810e3d..df5ec64 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 @@ -22,7 +22,6 @@ package org.onap.ccsdk.dashboard.controller; - import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; @@ -58,220 +57,215 @@ import org.springframework.web.bind.annotation.RestController; @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 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(); - 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"; + 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 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"); - } - } + private boolean isDbConnUp() { + @SuppressWarnings("unchecked") + List<App> list = dataAccessService.executeQuery(APP_DB_QRY, null); + if (list.size() > 0) { + return true; + } else { + return false; + } + } - 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)); - } + private App findApp() { + @SuppressWarnings("unchecked") + List<App> list = dataAccessService.executeQuery(APP_DB_QRY, null); + return (list == null || list.isEmpty()) ? null : (App) list.get(0); + } - 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(); + public static boolean isServiceReachable(String targetUrl) throws IOException { + HttpURLConnection httpUrlConnection = (HttpURLConnection) new URL(targetUrl).openConnection(); + httpUrlConnection.setRequestMethod("HEAD"); - 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; - } + try { + int responseCode = httpUrlConnection.getResponseCode(); + return responseCode == HttpURLConnection.HTTP_OK; + } catch (UnknownHostException noInternetConnection) { + return false; + } + } - 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"); + @Autowired + public void setCacheManager(AbstractCacheManager cacheManager) { + this.cacheManager = cacheManager; + } - 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 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 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()); - } + 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 index bdbf6ad..135b650 100644 --- 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 @@ -84,901 +84,865 @@ import com.fasterxml.jackson.core.JsonProcessingException; @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()); - } + 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 2905dca..3e74ff4 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 @@ -30,62 +30,62 @@ import org.onap.portalsdk.core.domain.support.DomainVo; */ 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; - } + 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 index 719ad23..c62d7bc 100644 --- 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 @@ -27,36 +27,42 @@ 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; - } - + 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/exceptions/BadRequestException.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/exceptions/BadRequestException.java index bd75bac..f06c3a1 100644 --- 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 @@ -24,12 +24,12 @@ package org.onap.ccsdk.dashboard.exceptions; public class BadRequestException extends Exception { - /** - * - */ - private static final long serialVersionUID = -8654510668910559419L; + /** + * + */ + private static final long serialVersionUID = -8654510668910559419L; - public BadRequestException (String message) { - super(message); - } + 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 index c1de4fe..de89257 100644 --- 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 @@ -26,22 +26,22 @@ package org.onap.ccsdk.dashboard.exceptions; */ public class DashboardControllerException extends Exception { - private static final long serialVersionUID = -1373841666122351816L; + private static final long serialVersionUID = -1373841666122351816L; - public DashboardControllerException() { - super(); - } + public DashboardControllerException() { + super(); + } - public DashboardControllerException(String message) { - super(message); - } + public DashboardControllerException(String message) { + super(message); + } - public DashboardControllerException(String message, Throwable cause) { - super(message, cause); - } + public DashboardControllerException(String message, Throwable cause) { + super(message, cause); + } - public DashboardControllerException(Throwable cause) { - super(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 index 4785823..ec4a504 100644 --- 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 @@ -23,14 +23,14 @@ package org.onap.ccsdk.dashboard.exceptions; public class DeploymentNotFoundException extends Exception { - - /** - * - */ - private static final long serialVersionUID = -5983803277201006988L; - public DeploymentNotFoundException (String message) { - super(message); - } + /** + * + */ + 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 index 72a6dbe..7f8bd42 100644 --- 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 @@ -23,12 +23,12 @@ package org.onap.ccsdk.dashboard.exceptions; public class DownstreamException extends Exception { - /** - * - */ - private static final long serialVersionUID = 142869535142369337L; + /** + * + */ + private static final long serialVersionUID = 142869535142369337L; - public DownstreamException (String message) { - super(message); - } + 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 index f87dc3e..aaab4d0 100644 --- 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 @@ -22,14 +22,14 @@ package org.onap.ccsdk.dashboard.exceptions; public class ServerErrorException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 8366380783861251332L; - public ServerErrorException(String message) { - super(message); - } + /** + * + */ + 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 index 117d506..02a8e70 100644 --- 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 @@ -22,14 +22,14 @@ package org.onap.ccsdk.dashboard.exceptions; public class ServiceAlreadyExistsException extends Exception { - - /** - * - */ - private static final long serialVersionUID = -4696234983451006280L; - public ServiceAlreadyExistsException (String message) { - super(message); - } + /** + * + */ + 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 index 2e7f5fe..dbd4588 100644 --- 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 @@ -1,10 +1,31 @@ +/******************************************************************************* + * =============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.inventory; public class BlueprintParseException extends Exception { - private static final long serialVersionUID = -6334355506595623685L; + private static final long serialVersionUID = -6334355506595623685L; - public BlueprintParseException(Throwable cause) { - super(cause); - } + 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 index 1b0e2d8..31baeec 100644 --- 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 @@ -1,13 +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.inventory; public class ServiceAlreadyDeactivatedException extends Exception { - /** - * - */ - private static final long serialVersionUID = 7268552618026889672L; + /** + * + */ + private static final long serialVersionUID = 7268552618026889672L; - public ServiceAlreadyDeactivatedException (String message) { - super(message); - } + 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 index de4a549..3df52d9 100644 --- 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 @@ -1,9 +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.inventory; public class ServiceNotFoundException extends Exception { - private static final long serialVersionUID = -8183806298586822720L; + private static final long serialVersionUID = -8183806298586822720L; - public ServiceNotFoundException() { super(); } - public ServiceNotFoundException (String message) { super(message); } + 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 index ce799f5..e5d8ce7 100644 --- 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 @@ -1,11 +1,43 @@ +/******************************************************************************* + * =============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.inventory; public class ServiceTypeActiveException extends Exception { - private static final long serialVersionUID = 7403567744784579153L; + 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); } + 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 index e7d1f8c..a7e135f 100644 --- 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 @@ -1,13 +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.inventory; public class ServiceTypeAlreadyDeactivatedException extends Exception { - /** - * - */ - private static final long serialVersionUID = -4359544421618429774L; + /** + * + */ + private static final long serialVersionUID = -4359544421618429774L; - public ServiceTypeAlreadyDeactivatedException (String message) { - super(message); - } + 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 index 806d127..bc801b8 100644 --- 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 @@ -1,11 +1,43 @@ +/******************************************************************************* + * =============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.inventory; public class ServiceTypeAlreadyExistsException extends Exception { - private static final long serialVersionUID = 8146558049192514157L; + 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); } + 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 index 54cffcf..2b8ec24 100644 --- 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 @@ -1,12 +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.inventory; public class ServiceTypeNotFoundException extends Exception { - private static final long serialVersionUID = 1218738334353236154L; + private static final long serialVersionUID = 1218738334353236154L; - public ServiceTypeNotFoundException() { super(); } + public ServiceTypeNotFoundException() { + super(); + } - public ServiceTypeNotFoundException (String message) { - super(message); - } + 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 47503f8..d9fa528 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 @@ -32,30 +32,30 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ public final class CloudifyBlueprint extends ECTransportModel { - /** A unique identifier for the blueprint. */ - public final String id; - /** The blueprint’s main file name. */ - public final String main_file_name; - /** The blueprint’s description. */ - public final String description; - /** The time the blueprint was uploaded to the manager. */ - public final String created_at; - /** The last time the blueprint was updated. */ - public final String updated_at; - /** The parsed result of the blueprint. */ - public final Map<String, Object> plan; + /** A unique identifier for the blueprint. */ + public final String id; + /** The blueprint’s main file name. */ + public final String main_file_name; + /** The blueprint’s description. */ + public final String description; + /** The time the blueprint was uploaded to the manager. */ + public final String created_at; + /** The last time the blueprint was updated. */ + public final String updated_at; + /** The parsed result of the blueprint. */ + public final Map<String, Object> plan; - @JsonCreator - public CloudifyBlueprint(@JsonProperty("main_file_name") String main_file_name, - @JsonProperty("description") String description, @JsonProperty("created_at") String created_at, - @JsonProperty("updated_at") String updated_at, @JsonProperty("id") String id, - @JsonProperty("plan") Map<String, Object> plan) { - this.main_file_name = main_file_name; - this.description = description; - this.created_at = created_at; - this.updated_at = updated_at; - this.id = id; - this.plan = plan; - } + @JsonCreator + public CloudifyBlueprint(@JsonProperty("main_file_name") String main_file_name, + @JsonProperty("description") String description, @JsonProperty("created_at") String created_at, + @JsonProperty("updated_at") String updated_at, @JsonProperty("id") String id, + @JsonProperty("plan") Map<String, Object> plan) { + this.main_file_name = main_file_name; + this.description = description; + this.created_at = created_at; + this.updated_at = updated_at; + this.id = id; + this.plan = plan; + } } 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 2c64efe..ca24849 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 @@ -29,16 +29,15 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ public final class CloudifyBlueprintContent extends ECTransportModel { - /** A unique identifier for the blueprint. */ - public final String id; - /** The content of the blueprint as YAML */ - public final String content; + /** A unique identifier for the blueprint. */ + public final String id; + /** The content of the blueprint as YAML */ + public final String content; - @JsonCreator - public CloudifyBlueprintContent(@JsonProperty("id") String id, - @JsonProperty("content") String content) { - this.id = id; - this.content = content; - } + @JsonCreator + public CloudifyBlueprintContent(@JsonProperty("id") String id, @JsonProperty("content") String content) { + this.id = id; + this.content = content; + } } 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 114a823..6238e22 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 @@ -28,36 +28,38 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; public class CloudifyBlueprintList extends ECTransportModel { - - public final List<CloudifyBlueprint> items; - public final Metadata metadata; + + public final List<CloudifyBlueprint> items; + public final Metadata metadata; @JsonCreator - public CloudifyBlueprintList(@JsonProperty("items") List<CloudifyBlueprint> items, @JsonProperty("metadata") Metadata metadata){ - this.items = items; - this.metadata = metadata; - } - - public static final class Metadata { - public final Pagination pagination; + public CloudifyBlueprintList(@JsonProperty("items") List<CloudifyBlueprint> 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){ + 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; + + 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; - } - } - } - + 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/CloudifyBlueprintUpload.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyBlueprintUpload.java index d7cf0d3..a77e974 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 @@ -37,19 +37,19 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ public final class CloudifyBlueprintUpload extends ECTransportModel { - /** A unique identifier for the blueprint. */ - public final String blueprint_id; - /** The blueprint’s main file name. */ - public final String blueprint_filename; - /** The zip file URL. */ - public final String zip_url; + /** A unique identifier for the blueprint. */ + public final String blueprint_id; + /** The blueprint’s main file name. */ + public final String blueprint_filename; + /** The zip file URL. */ + public final String zip_url; - @JsonCreator - public CloudifyBlueprintUpload(@JsonProperty("blueprint_id") String blueprint_id, - @JsonProperty("blueprint_filename") String blueprint_filename, @JsonProperty("zip_url") String zip_url) { - this.blueprint_id = blueprint_id; - this.blueprint_filename = blueprint_filename; - this.zip_url = zip_url; - } + @JsonCreator + public CloudifyBlueprintUpload(@JsonProperty("blueprint_id") String blueprint_id, + @JsonProperty("blueprint_filename") String blueprint_filename, @JsonProperty("zip_url") String zip_url) { + this.blueprint_id = blueprint_id; + this.blueprint_filename = blueprint_filename; + this.zip_url = zip_url; + } } 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 index f8b13e0..624c41a 100644 --- 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 @@ -25,20 +25,19 @@ 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; - } + + /** 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 index 8c6a39d..155f415 100644 --- 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 @@ -27,34 +27,36 @@ 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; + 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 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; + public static final class Metadata { + public final Pagination pagination; @JsonCreator - public Metadata(@JsonProperty("pagination") Pagination pagination){ + 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; + + 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; - } - } - } + 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 4e07c1f..60bf229 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 @@ -33,132 +33,133 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ public final class CloudifyDeployment extends ECTransportModel { - /** A unique identifier for the deployment. */ - public final String id; - public final String description; - /** The id of the blueprint the deployment is based on. */ - public final String blueprint_id; - /** The time when the deployment was created. */ - public final String created_at; - /** The time the deployment was last updated at. */ - public final String updated_at; - /** - * A dictionary containing key value pairs which represents a deployment - * input and its provided value. - */ - 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. */ - public final Map<String, Object> policy_triggers; - /** A dictionary containing an outputs definition of a deployment. */ - public final Map<String, Object> outputs; - /** A dictionary containing the groups definition of deployment. */ - public final Map<String, Object> groups; - - public final Map<String, Object> scaling_groups; - /** 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") 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("tenant_name") String tenant_name) { - this.description = description; - this.blueprint_id = blueprint_id; - this.created_at = created_at; - this.updated_at = updated_at; - this.id = id; - this.inputs = inputs; - this.policy_types = policy_types; - this.policy_triggers = policy_triggers; - this.outputs = outputs; - this.groups = groups; - this.scaling_groups = scaling_groups; - this.workflows = workflows; - this.tenant_name = tenant_name; - } - - public static final class Inputs { - public final String openstack_auth_url; - public final String external_network_name; - public final String openstack_username; - public final String instance_image; - public final String keypair_name; - public final String instance_name; - public final String keypair_private_key_path; - public final String openstack_tenant_name; - public final String subnet_name; - public final String openstack_region; - public final String openstack_password; - public final String ssh_username; - public final String instance_flavor; - public final String network_name; - - @JsonCreator - public Inputs(@JsonProperty("openstack_auth_url") String openstack_auth_url, - @JsonProperty("external_network_name") String external_network_name, - @JsonProperty("openstack_username") String openstack_username, - @JsonProperty("instance_image") String instance_image, - @JsonProperty("keypair_name") String keypair_name, @JsonProperty("instance_name") String instance_name, - @JsonProperty("keypair_private_key_path") String keypair_private_key_path, - @JsonProperty("openstack_tenant_name") String openstack_tenant_name, - @JsonProperty("subnet_name") String subnet_name, - @JsonProperty("openstack_region") String openstack_region, - @JsonProperty("openstack_password") String openstack_password, - @JsonProperty("ssh_username") String ssh_username, - @JsonProperty("instance_flavor") String instance_flavor, - @JsonProperty("network_name") String network_name) { - - this.openstack_auth_url = openstack_auth_url; - this.external_network_name = external_network_name; - this.openstack_username = openstack_username; - this.instance_image = instance_image; - this.keypair_name = keypair_name; - this.instance_name = instance_name; - this.keypair_private_key_path = keypair_private_key_path; - this.openstack_tenant_name = openstack_tenant_name; - this.subnet_name = subnet_name; - this.openstack_region = openstack_region; - this.openstack_password = openstack_password; - this.ssh_username = ssh_username; - this.instance_flavor = instance_flavor; - this.network_name = network_name; - } - } - - public static final class Workflow { - public final String name; - public final String created_at; - public final Map<String,Parameter> parameters; - - @JsonCreator - public Workflow(@JsonProperty("name") String name, @JsonProperty("created_at") String created_at, - @JsonProperty("parameters") Map<String,Parameter> parameters) { - this.name = name; - this.created_at = created_at; - this.parameters = parameters; - } - } - - public static final class Parameter { - - @JsonProperty("default") - public final Object xdefault; - public final String description; - - @JsonCreator - public Parameter(@JsonProperty("default") Object xdefault, @JsonProperty("description") String description) { - this.xdefault = xdefault; - this.description = description; - } - } + /** A unique identifier for the deployment. */ + public final String id; + public final String description; + /** The id of the blueprint the deployment is based on. */ + public final String blueprint_id; + /** The time when the deployment was created. */ + public final String created_at; + /** The time the deployment was last updated at. */ + public final String updated_at; + /** + * A dictionary containing key value pairs which represents a deployment input + * and its provided value. + */ + 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. */ + public final Map<String, Object> policy_triggers; + /** A dictionary containing an outputs definition of a deployment. */ + public final Map<String, Object> outputs; + /** A dictionary containing the groups definition of deployment. */ + public final Map<String, Object> groups; + + public final Map<String, Object> scaling_groups; + /** 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") 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("tenant_name") String tenant_name) { + this.description = description; + this.blueprint_id = blueprint_id; + this.created_at = created_at; + this.updated_at = updated_at; + this.id = id; + this.inputs = inputs; + this.policy_types = policy_types; + this.policy_triggers = policy_triggers; + this.outputs = outputs; + this.groups = groups; + this.scaling_groups = scaling_groups; + this.workflows = workflows; + this.tenant_name = tenant_name; + } + + public static final class Inputs { + public final String openstack_auth_url; + public final String external_network_name; + public final String openstack_username; + public final String instance_image; + public final String keypair_name; + public final String instance_name; + public final String keypair_private_key_path; + public final String openstack_tenant_name; + public final String subnet_name; + public final String openstack_region; + public final String openstack_password; + public final String ssh_username; + public final String instance_flavor; + public final String network_name; + + @JsonCreator + public Inputs(@JsonProperty("openstack_auth_url") String openstack_auth_url, + @JsonProperty("external_network_name") String external_network_name, + @JsonProperty("openstack_username") String openstack_username, + @JsonProperty("instance_image") String instance_image, + @JsonProperty("keypair_name") String keypair_name, @JsonProperty("instance_name") String instance_name, + @JsonProperty("keypair_private_key_path") String keypair_private_key_path, + @JsonProperty("openstack_tenant_name") String openstack_tenant_name, + @JsonProperty("subnet_name") String subnet_name, + @JsonProperty("openstack_region") String openstack_region, + @JsonProperty("openstack_password") String openstack_password, + @JsonProperty("ssh_username") String ssh_username, + @JsonProperty("instance_flavor") String instance_flavor, + @JsonProperty("network_name") String network_name) { + + this.openstack_auth_url = openstack_auth_url; + this.external_network_name = external_network_name; + this.openstack_username = openstack_username; + this.instance_image = instance_image; + this.keypair_name = keypair_name; + this.instance_name = instance_name; + this.keypair_private_key_path = keypair_private_key_path; + this.openstack_tenant_name = openstack_tenant_name; + this.subnet_name = subnet_name; + this.openstack_region = openstack_region; + this.openstack_password = openstack_password; + this.ssh_username = ssh_username; + this.instance_flavor = instance_flavor; + this.network_name = network_name; + } + } + + public static final class Workflow { + public final String name; + public final String created_at; + public final Map<String, Parameter> parameters; + + @JsonCreator + public Workflow(@JsonProperty("name") String name, @JsonProperty("created_at") String created_at, + @JsonProperty("parameters") Map<String, Parameter> parameters) { + this.name = name; + this.created_at = created_at; + this.parameters = parameters; + } + } + + public static final class Parameter { + + @JsonProperty("default") + public final Object xdefault; + public final String description; + + @JsonCreator + public Parameter(@JsonProperty("default") Object xdefault, @JsonProperty("description") String description) { + this.xdefault = xdefault; + this.description = description; + } + } } 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 4a26767..4dfef1e 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 @@ -27,36 +27,38 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; public class CloudifyDeploymentList extends ECTransportModel { - - public final List<CloudifyDeployment> items; - public final Metadata metadata; + + public final List<CloudifyDeployment> items; + public final Metadata metadata; @JsonCreator - public CloudifyDeploymentList(@JsonProperty("items") List<CloudifyDeployment> items, @JsonProperty("metadata") Metadata metadata){ - this.items = items; - this.metadata = metadata; - } + public CloudifyDeploymentList(@JsonProperty("items") List<CloudifyDeployment> items, + @JsonProperty("metadata") Metadata metadata) { + this.items = items; + this.metadata = metadata; + } - public static final class Metadata { - public final Pagination pagination; + public static final class Metadata { + public final Pagination pagination; @JsonCreator - public Metadata(@JsonProperty("pagination") Pagination pagination){ + 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; + + 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; - } - } - } - + 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/CloudifyDeploymentRequest.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyDeploymentRequest.java index 92c7ec3..2110111 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 @@ -42,23 +42,23 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ public final class CloudifyDeploymentRequest extends ECTransportModel { - /** A unique identifier for the deployment. */ - public final String deployment_id; - /** A unique identifier for the blueprint. */ - public final String blueprint_id; - /** - * These values are input for the deployment which can be retrieved from the - * GET /blueprint API this is :plan.input field in GET /blueprint - */ - public final Map<String, Object> parameters; + /** A unique identifier for the deployment. */ + public final String deployment_id; + /** A unique identifier for the blueprint. */ + public final String blueprint_id; + /** + * These values are input for the deployment which can be retrieved from the GET + * /blueprint API this is :plan.input field in GET /blueprint + */ + public final Map<String, Object> parameters; - @JsonCreator - public CloudifyDeploymentRequest(@JsonProperty("deployment_id") String deployment_id, - @JsonProperty("blueprint_id") String blueprint_id, - @JsonProperty("parameters") Map<String, Object> parameters) { - this.deployment_id = deployment_id; - this.blueprint_id = blueprint_id; - this.parameters = parameters; - } + @JsonCreator + public CloudifyDeploymentRequest(@JsonProperty("deployment_id") String deployment_id, + @JsonProperty("blueprint_id") String blueprint_id, + @JsonProperty("parameters") Map<String, Object> parameters) { + this.deployment_id = deployment_id; + this.blueprint_id = blueprint_id; + this.parameters = parameters; + } } 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 index cecece3..16ac145 100644 --- 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 @@ -29,7 +29,9 @@ 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 + * 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", @@ -47,44 +49,40 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ 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; + /** 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) { + @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; - } + 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 index 19134a4..65688bb 100644 --- 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 @@ -32,62 +32,56 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ 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; + /** 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 tenant_name; - public final String created_by; + public final String created_by; - public final Boolean private_resource; + public final Boolean private_resource; - public final String resource_availability; + 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) { - @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; - } + 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 index 3f3a8fa..30d3d16 100644 --- 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 @@ -27,9 +27,12 @@ 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: + * 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 * - * 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, @@ -41,38 +44,36 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ public final class CloudifyDeploymentUpgradeRequest extends ECTransportModel { - public final String config_url; - public final String config_format; - public final String chartRepo; - public final String chartVersion; + 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) { + @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; - } + 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_url() { + return config_url; + } - public String getConfig_format() { - return config_format; - } + public String getConfig_format() { + return config_format; + } - public String getChartRepo() { - return chartRepo; - } + public String getChartRepo() { + return chartRepo; + } - public String getChartVersion() { - return chartVersion; - } + 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 index 468b62d..bca8fb3 100644 --- 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 @@ -26,28 +26,26 @@ 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 + "]"; - } + /** 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 index 4910f9f..d95ff24 100644 --- 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 @@ -29,69 +29,62 @@ 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; + /** 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) { + @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; - } + 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 index d633faa..f5d596f 100644 --- 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 @@ -28,34 +28,36 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class CloudifyEventList extends ECTransportModel { - public final List<CloudifyEvent> items; - public final Metadata metadata; + 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 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; + public static final class Metadata { + public final Pagination pagination; @JsonCreator - public Metadata(@JsonProperty("pagination") Pagination pagination){ + 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; + + 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; - } - } - } + 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 e701528..3fe393d 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 @@ -32,55 +32,52 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ public final class CloudifyExecution 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 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; + /** 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 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("tenant_name") String tenant_name, - @JsonProperty("error") String error, @JsonProperty("id") String id, - @JsonProperty("parameters") Map<String, Object> parameters, - @JsonProperty("is_helm") Boolean is_helm, - @JsonProperty("helm_status") 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("tenant_name") String tenant_name, @JsonProperty("error") String error, + @JsonProperty("id") String id, @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; - this.workflow_id = workflow_id; - 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; - } + 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.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 e493c70..c53b314 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 @@ -27,36 +27,38 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; public class CloudifyExecutionList extends ECTransportModel { - - public final List<CloudifyExecution> items; - public final Metadata metadata; + + public final List<CloudifyExecution> items; + public final Metadata metadata; @JsonCreator - public CloudifyExecutionList(@JsonProperty("items") List<CloudifyExecution> items, @JsonProperty("metadata") Metadata metadata){ - this.items = items; - this.metadata = metadata; - } + public CloudifyExecutionList(@JsonProperty("items") List<CloudifyExecution> items, + @JsonProperty("metadata") Metadata metadata) { + this.items = items; + this.metadata = metadata; + } - public static final class Metadata { - public final Pagination pagination; + public static final class Metadata { + public final Pagination pagination; @JsonCreator - public Metadata(@JsonProperty("pagination") Pagination pagination){ + 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; + + 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; - } - } - } - + 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/CloudifyExecutionRequest.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyExecutionRequest.java index c333faf..e296565 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 @@ -28,77 +28,76 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class CloudifyExecutionRequest extends ECTransportModel { - /** A unique identifier for the deployment. */ - public String deployment_id; - /** A unique identifier for the workflow */ - public String workflow_id; - public Boolean allow_custom_parameters; - public Boolean force; - public String tenant; - /** Parameters: retrieve using the GET /deployments */ - 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_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_id = workflow_id; - this.allow_custom_parameters = allowCustomParameters; - this.force = force; - this.tenant = tenant; - this.parameters = parameters; - } + /** A unique identifier for the deployment. */ + public String deployment_id; + /** A unique identifier for the workflow */ + public String workflow_id; + public Boolean allow_custom_parameters; + public Boolean force; + public String tenant; + /** Parameters: retrieve using the GET /deployments */ + 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_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_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 index b275466..6352f40 100644 --- 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 @@ -25,12 +25,12 @@ 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; - } + /** 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 index 95795d6..f384a6f 100644 --- 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 @@ -28,34 +28,36 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class CloudifyNodeIdList { - public final List<CloudifyNodeId> items; - public final Metadata metadata; + 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; + 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){ + 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; + + 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; - } - } - } + 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/CloudifyNodeInstance.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeInstance.java index adbc02a..c89079d 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeInstance.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/CloudifyNodeInstance.java @@ -29,16 +29,16 @@ 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; + /** The id of the node instance. */ + public final String id; - @JsonCreator - public CloudifyNodeInstance(@JsonProperty("id") String id, - @JsonProperty("runtime_properties") Map<String, Object> runtime_properties) { - this.id = id; - this.runtime_properties = runtime_properties; - } + /** 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 index f87d34c..abe25fc 100644 --- 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 @@ -30,32 +30,33 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ 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; - } + /** 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 index c5ed092..423abe2 100644 --- 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 @@ -28,36 +28,38 @@ 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; + + 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; + 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){ + 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; + + 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; - } - } - } - + 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 index 4a10457..1813e5c 100644 --- 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 @@ -28,34 +28,36 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class CloudifyNodeInstanceList extends ECTransportModel { - public final List<CloudifyNodeInstance> items; - public final Metadata metadata; + 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; + 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){ + 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; + + 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; - } - } - } + 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 index b0c876e..594ebfa 100644 --- 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 @@ -26,32 +26,28 @@ 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; + /** 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; - } + @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 index 3cd53b7..5a30163 100644 --- 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 @@ -27,34 +27,36 @@ 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; + 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 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; + public static final class Metadata { + public final Pagination pagination; @JsonCreator - public Metadata(@JsonProperty("pagination") Pagination pagination){ + 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; + + 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; - } - } - } + 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 index b1a3fe5..3026a7a 100644 --- 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 @@ -26,33 +26,28 @@ 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; - } -} + /** 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 index fba4229..b885936 100644 --- 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 @@ -26,19 +26,18 @@ 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; - } + /** 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 index f298a28..c7f8530 100644 --- 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 @@ -27,34 +27,36 @@ 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; + 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; + 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){ + 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; + + 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; - } - } - } + 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 47b6cb0..1e57b12 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 @@ -28,17 +28,16 @@ import com.fasterxml.jackson.annotation.JsonProperty; * Model for message returned by Consul about monitored datacenters. * * <pre> - "dcname" - </pre> + * "dcname" + * </pre> */ public final class ConsulDatacenter extends ECTransportModel { - public final String name; + public final String name; - @JsonCreator - public ConsulDatacenter( - @JsonProperty("ID") String name) { - this.name = name; - } + @JsonCreator + public ConsulDatacenter(@JsonProperty("ID") String name) { + this.name = name; + } } 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 801dc56..5612b6d 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 @@ -61,56 +61,56 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ public final class ConsulHealthServiceRegistration extends ECTransportModel { - public final List<ConsulServiceRegistration> services; + public final List<ConsulServiceRegistration> services; - @JsonCreator - public ConsulHealthServiceRegistration(@JsonProperty("services") List<ConsulServiceRegistration> services) { - this.services = services; - } + @JsonCreator + public ConsulHealthServiceRegistration(@JsonProperty("services") List<ConsulServiceRegistration> services) { + this.services = services; + } - public static final class ConsulServiceRegistration { + public static final class ConsulServiceRegistration { - public final String id; - public final String name; - public final String address; - public final String port; - public final List<String> tags; - public final List<EndpointCheck> checks; + public final String id; + public final String name; + public final String address; + public final String port; + public final List<String> tags; + public final List<EndpointCheck> checks; - @JsonCreator - public ConsulServiceRegistration(@JsonProperty("id") String id, // - @JsonProperty("name") String name, // - @JsonProperty("address") String address, // - @JsonProperty("port") String port, // - @JsonProperty("tags") List<String> tags,// - @JsonProperty("checks") List<EndpointCheck> checks) { - this.id = id; - this.name = name; - this.address = address; - this.port = port; - this.tags = tags; - this.checks = checks; - } + @JsonCreator + public ConsulServiceRegistration(@JsonProperty("id") String id, // + @JsonProperty("name") String name, // + @JsonProperty("address") String address, // + @JsonProperty("port") String port, // + @JsonProperty("tags") List<String> tags, // + @JsonProperty("checks") List<EndpointCheck> checks) { + this.id = id; + this.name = name; + this.address = address; + this.port = port; + this.tags = tags; + this.checks = checks; + } - } + } - public static final class EndpointCheck { + public static final class EndpointCheck { - public final String endpoint; - public final String interval; - public final String description; - public final String name; + public final String endpoint; + public final String interval; + public final String description; + public final String name; - @JsonCreator - public EndpointCheck(@JsonProperty("endpoint") String endpoint, // - @JsonProperty("interval") String interval, // - @JsonProperty("description") String description, // - @JsonProperty("name") String name) { - this.endpoint = endpoint; - this.interval = interval; - this.description = description; - this.name = name; - } - } + @JsonCreator + public EndpointCheck(@JsonProperty("endpoint") String endpoint, // + @JsonProperty("interval") String interval, // + @JsonProperty("description") String description, // + @JsonProperty("name") String name) { + this.endpoint = endpoint; + this.interval = interval; + this.description = description; + this.name = name; + } + } } 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 617830c..7122a52 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 @@ -27,7 +27,8 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; /** - * Model for message returned by Consul about a node registered for health monitoring. + * Model for message returned by Consul about a node registered for health + * monitoring. * * <pre> { @@ -39,34 +40,31 @@ import com.fasterxml.jackson.annotation.JsonProperty; "CreateIndex":6, "ModifyIndex":179808 } - </pre> + * </pre> */ public final class ConsulNodeInfo extends ECTransportModel { - public final String id; - public final String node; - public final String address; - public final Map<String,Object> taggedAddresses; - public final Map<String,Object> meta; - public final int createIndex; - public final int modifyIndex; + public final String id; + public final String node; + public final String address; + public final Map<String, Object> taggedAddresses; + public final Map<String, Object> meta; + public final int createIndex; + public final int modifyIndex; - @JsonCreator - public ConsulNodeInfo( - @JsonProperty("ID") String id, - @JsonProperty("Node") String node, - @JsonProperty("Address") String address, - @JsonProperty("TaggedAddresses") Map<String,Object> taggedAddresses, - @JsonProperty("Meta") Map<String,Object> meta, - @JsonProperty("CreateIndex") int createIndex, - @JsonProperty("ModifyIndex") int modifyIndex) { - this.id = id; - this.node = node; - this.address = address; - this.taggedAddresses = taggedAddresses; - this.meta = meta; - this.createIndex = createIndex; - this.modifyIndex = modifyIndex; - } + @JsonCreator + public ConsulNodeInfo(@JsonProperty("ID") String id, @JsonProperty("Node") String node, + @JsonProperty("Address") String address, + @JsonProperty("TaggedAddresses") Map<String, Object> taggedAddresses, + @JsonProperty("Meta") Map<String, Object> meta, @JsonProperty("CreateIndex") int createIndex, + @JsonProperty("ModifyIndex") int modifyIndex) { + this.id = id; + this.node = node; + this.address = address; + this.taggedAddresses = taggedAddresses; + this.meta = meta; + this.createIndex = createIndex; + this.modifyIndex = modifyIndex; + } } 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 fcf00d8..5f3876a 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 @@ -39,44 +39,39 @@ import com.fasterxml.jackson.annotation.JsonProperty; "ServiceName": "pgaasServer1", "CreateIndex": 190199, "ModifyIndex": 199395 - } </pre> - * - */ + } + * </pre> + * + */ public final class ConsulServiceHealth extends ECTransportModel { - public final String node; - public final String checkID; - public final String name; - public final String status; - public final String notes; - public final String output; - public final String serviceID; - public final String serviceName; - public final int createIndex; - public final int modifyIndex; + public final String node; + public final String checkID; + public final String name; + public final String status; + public final String notes; + public final String output; + public final String serviceID; + public final String serviceName; + public final int createIndex; + public final int modifyIndex; - @JsonCreator - public ConsulServiceHealth( - @JsonProperty("Node") String node, - @JsonProperty("CheckID") String checkID, - @JsonProperty("Name") String name, - @JsonProperty("Status") String status, - @JsonProperty("Notes") String notes, - @JsonProperty("Output") String output, - @JsonProperty("ServiceID") String serviceID, - @JsonProperty("ServiceName") String serviceName, - @JsonProperty("CreateIndex") int createIndex, - @JsonProperty("ModifyIndex") int modifyIndex) { - this.node = node; - this.checkID = checkID; - this.name = name; - this.status = status; - this.notes = notes; - this.output = output; - this.serviceID = serviceID; - this.serviceName = serviceName; - this.createIndex = createIndex; - this.modifyIndex = modifyIndex; - } + @JsonCreator + public ConsulServiceHealth(@JsonProperty("Node") String node, @JsonProperty("CheckID") String checkID, + @JsonProperty("Name") String name, @JsonProperty("Status") String status, + @JsonProperty("Notes") String notes, @JsonProperty("Output") String output, + @JsonProperty("ServiceID") String serviceID, @JsonProperty("ServiceName") String serviceName, + @JsonProperty("CreateIndex") int createIndex, @JsonProperty("ModifyIndex") int modifyIndex) { + this.node = node; + this.checkID = checkID; + this.name = name; + this.status = status; + this.notes = notes; + this.output = output; + this.serviceID = serviceID; + this.serviceName = serviceName; + this.createIndex = createIndex; + this.modifyIndex = modifyIndex; + } } 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 3a8a171..42e1fd2 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 @@ -39,16 +39,16 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ public final class ConsulServiceHealthHistory extends ECTransportModel { - public final String status; - public final String output; - public final String date; + public final String status; + public final String output; + public final String date; - @JsonCreator - public ConsulServiceHealthHistory(@JsonProperty("Status") String status, @JsonProperty("Output") String output, - @JsonProperty("Date") String date) { - this.status = status; - this.output = output; - this.date = date; - } + @JsonCreator + public ConsulServiceHealthHistory(@JsonProperty("Status") String status, @JsonProperty("Output") String output, + @JsonProperty("Date") String date) { + this.status = status; + this.output = output; + this.date = date; + } } 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 f990b1f..bb04a66 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 @@ -42,13 +42,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ public final class ConsulServiceInfo extends ECTransportModel { - public final String name; - public final List<String> addresses; + public final String name; + public final List<String> addresses; - @JsonCreator - public ConsulServiceInfo(@JsonProperty("name") String name, @JsonProperty("addresses") List<String> addresses) { - this.name = name; - this.addresses = addresses; - } + @JsonCreator + public ConsulServiceInfo(@JsonProperty("name") String name, @JsonProperty("addresses") List<String> addresses) { + this.name = name; + this.addresses = addresses; + } } 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 abbfd52..03159c2 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 @@ -29,75 +29,72 @@ import org.onap.portalsdk.core.onboarding.util.CipherUtil; */ public class ControllerEndpointCredentials extends ControllerEndpointTransport { - public String username; - public String password; - public boolean isEncryptedPass; + 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 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 String getUsername() { + return username; + } - public void setUsername(String username) { - this.username = username; - } + public void setUsername(String username) { + this.username = username; + } - public String getPassword() { - return password; - } + public String getPassword() { + return password; + } - public void setPassword(String password) { - this.password = password; - } + public void setPassword(String password) { + this.password = password; + } - public boolean getEncryptedPassword() { - return isEncryptedPass; - } + public boolean getEncryptedPassword() { + return isEncryptedPass; + } - public void setEncryptedPassword(boolean isEncryptedPass) { - this.isEncryptedPass = 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()); - } + /** + * 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; - } + /** + * 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); - } + /** + * 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 e297782..56019c9 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 @@ -26,70 +26,71 @@ package org.onap.ccsdk.dashboard.model; */ 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, 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() { - return selected; - } - - public void setSelected(boolean selected) { - this.selected = selected; - } - - 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; - } - - public String getConsulUrl() { - return consulUrl; - } - - public void setConsulUrl(String consulUrl) { - this.consulUrl = consulUrl; - } + 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, 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() { + return selected; + } + + public void setSelected(boolean selected) { + this.selected = selected; + } + + 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; + } + + 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 index 0f752a7..1bc8702 100644 --- 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 @@ -26,30 +26,31 @@ package org.onap.ccsdk.dashboard.model; */ 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; - } + 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 946a4ec..1d0f258 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 @@ -32,32 +32,32 @@ import com.fasterxml.jackson.databind.SerializationFeature; */ public abstract class ECTransportModel { - protected final ObjectMapper mapper = new ObjectMapper(); + protected final ObjectMapper mapper = new ObjectMapper(); - public ECTransportModel() { - // Do not serialize null values - mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - // toString should yield pretty version - mapper.configure(SerializationFeature.INDENT_OUTPUT, true); - // tolerate empty strings where object is expected - mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true); - } + public ECTransportModel() { + // Do not serialize null values + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + // toString should yield pretty version + mapper.configure(SerializationFeature.INDENT_OUTPUT, true); + // tolerate empty strings where object is expected + mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true); + } - /** - * Convenience method that serializes content as JSON and catches any - * exception so this method can be easily used in a catch clause. - * - * @return A REST error response object as well-formed JSON - */ - public String toString() { - String json = null; - try { - json = mapper.writeValueAsString(this); - } catch (JsonProcessingException jpe) { - // Should never, ever happen - json = "{ \"error\" : \"" + jpe.toString() + "\"}"; - } - return json; - } + /** + * Convenience method that serializes content as JSON and catches any exception + * so this method can be easily used in a catch clause. + * + * @return A REST error response object as well-formed JSON + */ + public String toString() { + String json = null; + try { + json = mapper.writeValueAsString(this); + } catch (JsonProcessingException jpe) { + // Should never, ever happen + json = "{ \"error\" : \"" + jpe.toString() + "\"}"; + } + return json; + } } diff --git a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/EcdAppComponent.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/EcdAppComponent.java index a507515..28eb6f0 100644 --- a/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/EcdAppComponent.java +++ b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/model/EcdAppComponent.java @@ -26,19 +26,18 @@ import java.util.List; import org.onap.ccsdk.dashboard.domain.EcdComponent; public class EcdAppComponent { - - 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; - } + + 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 1b72e7c..7edbdf8 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 @@ -25,29 +25,29 @@ package org.onap.ccsdk.dashboard.model; * Model for JSON response with health-check results. */ public class HealthStatus { - // Either 200 or 503 - public int statusCode; - // Additional detail in case of error, empty in case of success. - public String message; + // Either 200 or 503 + public int statusCode; + // Additional detail in case of error, empty in case of success. + public String message; - public HealthStatus(int code, String msg) { - this.statusCode = code; - this.message = msg; - } + public HealthStatus(int code, String msg) { + this.statusCode = code; + this.message = msg; + } - public int getStatusCode() { - return statusCode; - } + public int getStatusCode() { + return statusCode; + } - public void setStatusCode(int code) { - this.statusCode = code; - } + public void setStatusCode(int code) { + this.statusCode = code; + } - public String getMessage() { - return message; - } + public String getMessage() { + return message; + } - public void setMessage(String msg) { - this.message = msg; - } + public void setMessage(String msg) { + this.message = msg; + } }
\ No newline at end of file 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 8027f92..d18f327 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 @@ -29,65 +29,62 @@ import com.fasterxml.jackson.databind.ObjectMapper; */ public class RestResponseError extends ECTransportModel { - private String error; + private String error; - public RestResponseError() { - } + public RestResponseError() { + } - /** - * Convenience constructor - * - * @param message - * Message body - */ - public RestResponseError(final String message) { - this.error = message; - } + /** + * Convenience constructor + * + * @param message Message body + */ + public RestResponseError(final String message) { + this.error = message; + } - /** - * Convenience constructor that limits the size of the throwable message. - * - * @param message - * Message body - * @param t - * Throwable used to construct body - */ - public RestResponseError(final String message, final Throwable t) { - final int enough = 512; - String exString = t.toString(); - String exceptionMsg = exString.length() > enough ? exString.substring(0, enough) : exString; - this.error = message + ": " + exceptionMsg; - } + /** + * Convenience constructor that limits the size of the throwable message. + * + * @param message Message body + * @param t Throwable used to construct body + */ + public RestResponseError(final String message, final Throwable t) { + final int enough = 512; + String exString = t.toString(); + String exceptionMsg = exString.length() > enough ? exString.substring(0, enough) : exString; + this.error = message + ": " + exceptionMsg; + } - public String getError() { - return error; - } + public String getError() { + return error; + } - public void setError(String message) { - this.error = message; - } + public void setError(String message) { + this.error = message; + } - /** - * Convenience method that serializes content as JSON and catches any - * exception so this can be easily used in a catch clause. - * - * @return A REST error response object as well-formed JSON - */ - public String toJson() { - String json = null; - try { - ObjectMapper mapper = new ObjectMapper(); - json = mapper.writeValueAsString(this); - } catch (JsonProcessingException jpe) { - // Should never, ever happen - json = "{ \"error\" : \"" + jpe.toString() + "\"}"; - } - return json; - } + /** + * Convenience method that serializes content as JSON and catches any exception + * so this can be easily used in a catch clause. + * + * @return A REST error response object as well-formed JSON + */ + public String toJson() { + String json = null; + try { + ObjectMapper mapper = new ObjectMapper(); + json = mapper.writeValueAsString(this); + } catch (JsonProcessingException jpe) { + // Should never, ever happen + json = "{ \"error\" : \"" + jpe.toString() + "\"}"; + } + return json; + } - @Override - public String toString() { - return "RestErrorResponse[message=" + error + "]"; - } + @Override + public String toString() { + return "RestErrorResponse[message=" + error + "]"; + } } 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 5e9c963..39a04ed 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 @@ -25,51 +25,50 @@ package org.onap.ccsdk.dashboard.model; * Model for a response with count of items available, count of pages required * to display all items, and one page worth of data items. * - * @param <T> - * Model class for item + * @param <T> Model class for item */ public class RestResponsePage<T> extends ECTransportModel { - private int totalItems; - private int totalPages; - private T items; + private int totalItems; + private int totalPages; + private T items; - public RestResponsePage() { - } + public RestResponsePage() { + } - public RestResponsePage(final int totalItems, final int totalPages, final T items) { - this.totalItems = totalItems; - this.totalPages = totalPages; - this.items = items; - } + public RestResponsePage(final int totalItems, final int totalPages, final T items) { + this.totalItems = totalItems; + this.totalPages = totalPages; + this.items = items; + } - public int getTotalItems() { - return totalItems; - } + public int getTotalItems() { + return totalItems; + } - public void setTotalItems(int items) { - this.totalItems = items; - } + public void setTotalItems(int items) { + this.totalItems = items; + } - public int getTotalPages() { - return totalPages; - } + public int getTotalPages() { + return totalPages; + } - public void setTotalPages(int pages) { - this.totalPages = pages; - } + public void setTotalPages(int pages) { + this.totalPages = pages; + } - public T getItems() { - return items; - } + public T getItems() { + return items; + } - public void setItems(final T data) { - this.items = data; - } + public void setItems(final T data) { + this.items = data; + } - @Override - public String toString() { - return "RestResponsePage[totalItems=" + totalItems + ", totalPages=" + totalPages + ", items=" + items + "]"; - } + @Override + public String toString() { + return "RestResponsePage[totalItems=" + totalItems + ", totalPages=" + totalPages + ", items=" + items + "]"; + } } 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 4eba0d8..4db65f1 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 @@ -26,32 +26,31 @@ package org.onap.ccsdk.dashboard.model; */ public class RestResponseSuccess extends ECTransportModel { - private String message; - - public RestResponseSuccess() { - } - - /** - * Convenience constructor - * - * @param message - * Message body - */ - public RestResponseSuccess(final String message) { - this.message = message; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - @Override - public String toString() { - return "RestResponseSuccess[message=" + message + "]"; - } + private String message; + + public RestResponseSuccess() { + } + + /** + * Convenience constructor + * + * @param message Message body + */ + public RestResponseSuccess(final String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return "RestResponseSuccess[message=" + message + "]"; + } } 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 index 06a516c..844c066 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.deploymenthandler; import java.util.Collection; @@ -8,33 +29,32 @@ 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; - } + /** 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 index 75f97ee..7e93d9c 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.deploymenthandler; import java.util.Map; @@ -7,7 +28,8 @@ 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: + * Model for message POST-ed to controller to create a Deployment via the + * Deployment Handler API: * * <pre> { @@ -30,73 +52,70 @@ import com.fasterxml.jackson.annotation.JsonProperty; * 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; - } + /** component or namespace for the service */ + private final String component; - public String getTag() { - return tag; - } + /** tag to identify the deployment */ + private final String tag; - public String getComponent() { - return component; - } + /** The blueprint name for the service to be deployed. */ + private final String blueprintName; - public Optional<String> getBlueprintId() { - return blueprintId; - } + /** 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 index b715a2d..ba0604d 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.deploymenthandler; import com.fasterxml.jackson.annotation.JsonCreator; @@ -5,15 +26,15 @@ 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; - } + /** 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 index 9d6a3b7..b0ac9e9 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.deploymenthandler; import java.util.Map; @@ -6,7 +27,8 @@ 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: + * Model for message POST-ed to controller to create a Deployment via the + * Deployment Handler API: * * <pre> { @@ -22,28 +44,32 @@ import com.fasterxml.jackson.annotation.JsonProperty; * </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; - } + + /** + * 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 index a0606c7..ae229b2 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.deploymenthandler; import java.util.Map; @@ -6,7 +27,8 @@ 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: + * Model for message POST-ed to controller to create a Deployment via the + * Deployment Handler API: * * <pre> { @@ -25,54 +47,56 @@ import com.fasterxml.jackson.annotation.JsonProperty; * 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; - } + /** 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 index 513b673..2c43f8a 100644 --- 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 @@ -1,32 +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.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; - } + /** 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 index 0dd9f9e..6d9644c 100644 --- 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 @@ -1,37 +1,59 @@ +/******************************************************************************* + * =============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.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; - } + /** 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 index cd81a0b..83c1989 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.deploymenthandler; import com.fasterxml.jackson.annotation.JsonCreator; @@ -9,24 +30,24 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ 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; - } + /** 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 index c0b27b6..68833cb 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.deploymenthandler; import com.fasterxml.jackson.annotation.JsonCreator; @@ -8,25 +29,27 @@ import com.fasterxml.jackson.annotation.JsonProperty; * */ 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; - } + + /** 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 index 5b3b456..13dcc4b 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.deploymenthandler; import java.util.Collection; @@ -11,24 +32,26 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ 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; - } + /** 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 index 564d4b3..173744a 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.deploymenthandler; import java.util.Map; @@ -6,7 +27,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; /** - * Model for message used by the controller to create a DeploymentRequest for + * Model for message used by the controller to create a DeploymentRequest for * the Deployment Handler API. * * <pre> @@ -28,36 +49,39 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ 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; - } + /** 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 index a2c1c20..1cb0a51 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import com.fasterxml.jackson.annotation.JsonCreator; @@ -5,19 +26,18 @@ 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; - } + /** 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 index c0b7b37..70f5fd5 100644 --- 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 @@ -1,4 +1,26 @@ +/******************************************************************************* + * =============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.inventory; + import java.io.File; import java.io.IOException; import java.util.Map; @@ -15,56 +37,56 @@ import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; @JsonIgnoreProperties(ignoreUnknown = true) public class Blueprint { - private static final ObjectMapper YAML_MAPPER = new ObjectMapper(new YAMLFactory()); + private static final ObjectMapper YAML_MAPPER = new ObjectMapper(new YAMLFactory()); + + static { + YAML_MAPPER.registerModule(new Jdk8Module()); + } - static { - YAML_MAPPER.registerModule(new Jdk8Module()); - } + @JsonProperty("inputs") + private Map<String, BlueprintInput> inputs; + @JsonProperty("description") + private String description; - @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); + } + } - 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; + } - private static ObjectMapper getYamlMapper() { - return YAML_MAPPER; - } + public Map<String, BlueprintInput> getInputs() { + return inputs; + } - public Map<String, BlueprintInput> getInputs() { - return inputs; - } + public String getDescription() { + return description; + } - public String getDescription() { - return description; - } + @Override + public String toString() { + return "inputs: " + ((getInputs() != null) ? getInputs().toString() : "{}"); + } - @Override - public String toString() { - return "inputs: " + ((getInputs() != null) ? getInputs().toString() : "{}"); - } - - public static void main(String args[]) throws Exception { + 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(); - } - } + 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 index 596438b..972c86b 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import java.util.Optional; @@ -9,111 +30,119 @@ 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/ + * 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() + - "}"; - } + 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 index fdec86d..7c09ea6 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import com.fasterxml.jackson.annotation.JsonCreator; @@ -5,54 +26,53 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class BlueprintResponse { - public BlueprintResponse() { - } + public BlueprintResponse() { + } - /** Name of the ServiceType */ - private String typeName; + /** Name of the ServiceType */ + private String typeName; - /** Version number for this ServiceType */ - private Integer typeVersion; + /** Version number for this ServiceType */ + private Integer typeVersion; - /** Unique identifier for this ServiceType */ - private String typeId; + /** 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; - } + @JsonCreator + public BlueprintResponse(@JsonProperty("typeName") String typeName, + @JsonProperty("typeVersion") Integer typeVersion, @JsonProperty("typeId") String typeId) { - public String getTypeName() { - return typeName; - } + this.typeName = typeName; + this.typeVersion = typeVersion; + this.typeId = typeId; + } - public Integer getTypeVersion() { - return typeVersion; - } + public String getTypeName() { + return typeName; + } - public String getTypeId() { - return typeId; - } + public Integer getTypeVersion() { + return typeVersion; + } - public void setTypeName(String typeName) { - this.typeName = typeName; - } + public String getTypeId() { + return typeId; + } - public void setTypeVersion(Integer typeVersion) { - this.typeVersion = typeVersion; - } + public void setTypeName(String typeName) { + this.typeName = typeName; + } - public void setTypeId(String typeId) { - this.typeId = typeId; - } + public void setTypeVersion(Integer typeVersion) { + this.typeVersion = typeVersion; + } - @Override - public String toString() { - return "BlueprintResponse [typeName=" + typeName + ", typeVersion=" + typeVersion + ", typeId=" + typeId + "]"; - } + 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 index 3856deb..4f0bf8e 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import com.fasterxml.jackson.annotation.JsonCreator; @@ -5,19 +26,18 @@ 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; - } + /** 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 index 42d4e47..986e574 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import java.util.Collection; @@ -10,31 +31,27 @@ 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; - } + 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 index 928f176..3631623 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import java.util.Collection; @@ -10,153 +31,138 @@ 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); - } - } - */ + /** 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 index e7d247b..a2e525f 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import com.fasterxml.jackson.annotation.JsonCreator; @@ -5,43 +26,44 @@ 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; - } + /** 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 index c4c2fd9..123392b 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import com.fasterxml.jackson.annotation.JsonCreator; @@ -5,27 +26,31 @@ 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; - } + /** 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; - public static ServiceComponentRequest from(ServiceComponent sc) { - return new ServiceComponentRequest(sc.componentId, sc.componentType, sc.componentSource, sc.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 index 0bf6858..d8e6e8b 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import java.util.Set; @@ -7,15 +28,15 @@ 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; - } + /** 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 index 71f786a..e440477 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import java.util.Collection; @@ -9,32 +30,31 @@ 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; - } - } + /** 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 index c24f86b..62fdfd0 100644 --- 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 @@ -1,122 +1,132 @@ +/******************************************************************************* + * =============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.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; - } + + 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 index dd7acd1..f338d28 100644 --- 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 @@ -1,50 +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.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; - } - */ + /** 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 index 8524115..d9491d9 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import java.util.Collection; @@ -6,17 +27,16 @@ 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; + /** 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; + } - - @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 index 036c9ae..ecb1da0 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import java.util.ArrayList; @@ -8,50 +29,47 @@ 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 - ); - } + /** 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 index f6f26ba..6a7868e 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import java.util.Collection; @@ -14,327 +35,328 @@ 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; - } + /** 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 index 28cddf6..938ec6d 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import java.util.Collection; @@ -9,32 +30,31 @@ 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; - } - } + /** 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 index f9d1b6f..8d98d9d 100644 --- 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 @@ -1,157 +1,163 @@ +/******************************************************************************* + * =============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.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; - } + 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 index 42dd018..533571b 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import java.util.Collection; @@ -8,108 +29,86 @@ 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; + /** 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)); - } + @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 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; - } + 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 index 292773a..efcdf3b 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import com.fasterxml.jackson.annotation.JsonCreator; @@ -5,22 +26,22 @@ 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; - } + private final String serviceTypeId; - public String getServiceTypeId() { - return serviceTypeId; - } + private final ServiceRefList serviceRefList; - public ServiceRefList getServiceRefList() { - return 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 index 3ef334f..2ba8aa7 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.inventory; import java.util.Collection; @@ -8,41 +29,40 @@ 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; - - } + /** 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 index 56fb9ee..4173f5e 100644 --- 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 @@ -1,6 +1,24 @@ -/** - * - */ +/******************************************************************************* + * =============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.rest; import java.util.Map; @@ -28,220 +46,215 @@ import org.onap.ccsdk.dashboard.model.CloudifyTenantList; */ 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); + /** + * 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 index a433908..bd9100e 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* +* =============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.rest; import java.io.InputStream; @@ -30,176 +51,183 @@ import com.fasterxml.jackson.databind.ObjectMapper; */ 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; - } + 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 index 1854577..3a4f2b1 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.rest; import java.net.MalformedURLException; @@ -35,316 +56,319 @@ 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(); - } - + 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 index f8daaf5..c63652b 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.rest; import java.util.List; @@ -13,62 +34,57 @@ import org.onap.ccsdk.dashboard.model.ConsulServiceInfo; */ 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 services that are monitored by Consul. + * + * @return List of ConsulServiceHealth + */ + public List<ConsulServiceInfo> getServices(String datacenter); - /** - * 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); + /** + * 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 index 82095c2..30b1f30 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.rest; import java.io.InputStream; @@ -16,92 +37,90 @@ 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; - } + 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 index 32311a8..b48b8d4 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.rest; import java.net.MalformedURLException; @@ -26,166 +47,166 @@ 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(); - } + + 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/DeploymentHandlerClient.java b/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/DeploymentHandlerClient.java index 2599a27..0804e9a 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.rest; import java.util.stream.Stream; @@ -13,76 +34,65 @@ 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. - * - * @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; + /** + * 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); - /** - * 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; + /** + * 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 index 168c28b..c03dff6 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.rest; import java.io.IOException; @@ -30,184 +51,174 @@ 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(); - } + private final String baseUrl; + // private final RestTemplate restTemplate; + private static final String DEPLOYMENTS = "dcae-deployments"; + private static final String UPDATE_PATH = "dcae-deployment-update"; - @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(); - } + protected final ObjectMapper objectMapper = new ObjectMapper(); - @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; - } + public DeploymentHandlerClientImpl(String webapiUrl) { + this(webapiUrl, null, 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. - } + /** + * 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()); + } - - @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()); - } - } - } + 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 7af5a20..0c4053c 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,3 +1,24 @@ +/******************************************************************************* + * =============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.rest; import java.net.URI; @@ -14,37 +35,36 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; /** * Utility class to enable Basic HTTP Authentication with Spring REST templates. - * + * * From: * http://www.baeldung.com/2012/04/16/how-to-use-resttemplate-with-basic-authentication-in-spring-3-1/ */ public class HttpComponentsClientHttpRequestFactoryBasicAuth extends HttpComponentsClientHttpRequestFactory { - private HttpHost host; - - /** - * @param host - * HttpHost - */ - public HttpComponentsClientHttpRequestFactoryBasicAuth(HttpHost host) { - super(); - this.host = host; - } - - protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { - return createHttpContext(); - } - - private HttpContext createHttpContext() { - // Create AuthCache instance - AuthCache authCache = new BasicAuthCache(); - // Generate BASIC scheme object and add it to the local auth cache - BasicScheme basicAuth = new BasicScheme(); - authCache.put(host, basicAuth); - - // Add AuthCache to the execution context - BasicHttpContext localcontext = new BasicHttpContext(); - localcontext.setAttribute(HttpClientContext.AUTH_CACHE, authCache); - return localcontext; - } + private HttpHost host; + + /** + * @param host HttpHost + */ + public HttpComponentsClientHttpRequestFactoryBasicAuth(HttpHost host) { + super(); + this.host = host; + } + + protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { + return createHttpContext(); + } + + private HttpContext createHttpContext() { + // Create AuthCache instance + AuthCache authCache = new BasicAuthCache(); + // Generate BASIC scheme object and add it to the local auth cache + BasicScheme basicAuth = new BasicScheme(); + authCache.put(host, basicAuth); + + // Add AuthCache to the execution context + BasicHttpContext localcontext = new BasicHttpContext(); + localcontext.setAttribute(HttpClientContext.AUTH_CACHE, authCache); + return localcontext; + } } 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 index d9f03ad..0e93a39 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.rest; import java.util.Optional; @@ -22,146 +43,148 @@ import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeRequest; */ 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; + /** + * 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 index c2acb33..c7c1cdf 100644 --- 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 @@ -1,6 +1,24 @@ -/** - * - */ +/******************************************************************************* + * =============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.rest; import java.net.URL; @@ -23,74 +41,74 @@ import org.springframework.web.client.RestTemplate; * */ 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); + 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); - // Build a client with a credentials provider - CloseableHttpClient httpClient = null; + // Put the factory in the template + restTempl = new RestTemplate(); + restTempl.setRequestFactory(requestFactory); + this.restTemplate = restTempl; + } - 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); + /** + * 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(); + } - // 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); - } + /** + * 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 index 6389db3..ebe7e4f 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.rest; import java.net.MalformedURLException; @@ -38,307 +59,295 @@ 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()); - } - } - } + 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 index 75d373a..5a422c0 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.rest; import java.io.InputStream; @@ -30,140 +51,139 @@ 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 - - } + 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 2db0af0..b63f972 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 @@ -35,44 +35,41 @@ import org.onap.ccsdk.dashboard.domain.EcdComponent; */ public interface ControllerEndpointService { - /** - * Gets the object for the specified user ID. - * - * @param userId - * Application user ID - * @return ControllerEndpointCredentials instance; null if none exists. - */ - ControllerEndpoint getControllerEndpointSelection(long userId); + /** + * Gets the object for the specified user ID. + * + * @param userId Application user ID + * @return ControllerEndpointCredentials instance; null if none exists. + */ + ControllerEndpoint getControllerEndpointSelection(long userId); - /** - * Creates or updates an entry for the user ID specified within the object. - * - * @param endpoint - * info to store. - */ - void updateControllerEndpointSelection(ControllerEndpoint endpoint); + /** + * Creates or updates an entry for the user ID specified within the object. + * + * @param endpoint info to store. + */ + void updateControllerEndpointSelection(ControllerEndpoint endpoint); - /** - * Deletes the object for the specified user ID. - * - * @param userId - * Application user ID - */ - void deleteControllerEndpointSelection(long userId); + /** + * Deletes the object for the specified user ID. + * + * @param userId Application user ID + */ + void deleteControllerEndpointSelection(long userId); - /** - * Gets all component names that are currently supported through - * ECOMPC dashboard - * - * @return Component instance list; - */ - public List<EcdComponent> getComponents(); + /** + * 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); + /** + * + * 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 88fd53b..6eacb47 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 @@ -41,80 +41,75 @@ import org.springframework.transaction.annotation.Transactional; @Transactional public class ControllerEndpointServiceImpl implements ControllerEndpointService { - @Autowired - private DataAccessService dataAccessService; + @Autowired + private DataAccessService dataAccessService; - /** - * @return Data access service - */ - public DataAccessService getDataAccessService() { - return dataAccessService; - } + /** + * @return Data access service + */ + public DataAccessService getDataAccessService() { + return dataAccessService; + } - /** - * @param dataAccessService - * Data access service - */ - public void setDataAccessService(DataAccessService dataAccessService) { - this.dataAccessService = 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); - } + /* + * (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); + } - @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# + * getComponents() + */ + @SuppressWarnings("unchecked") + @Override + public List<EcdComponent> getComponents() { + return dataAccessService.executeNamedQuery("getAllComponents", null, 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); - } + @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 a04a76e..63ace9c 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 @@ -42,165 +42,157 @@ import org.springframework.core.env.Environment; @PropertySource(value = { "${container.classpath:}/WEB-INF/conf/dashboard.properties" }) public class DashboardProperties { - /** - * Key for property that indicates if test data should be used - */ - public static final String CONTROLLER_MOCK_DATA = "controller.mock.data"; - /** - * Key for property with list of controllers - */ - public static final String CONTROLLER_KEY_LIST = "controller.key.list"; - /** - * Subkey for property with Controller name (description) - */ - public static final String CONTROLLER_SUBKEY_NAME = "name"; - /** - * Subkey for property with Controller URL - */ - 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_PASS = "password"; - /** - * Subkey for property with Controller password encryption status - */ - public static final String CONTROLLER_SUBKEY_ENCRYPTED = "is_encrypted"; - /** - * Key for dashboard deployment environment - dev/uat/prod - */ - 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; - } - - /** - * @param environment - * Environment - */ - @Autowired - public void setEnvironment(final Environment environment) { - this.environment = environment; - } - - /** - * @param key - * Property key - * @return True or false - */ - public static boolean containsProperty(final String key) { - return environment.containsProperty(key); - } - - /** - * @param key - * Property key - * @return String value; throws unchecked exception if key is not found - */ - 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 static Boolean getBooleanProperty(final String key) { - final String value = getProperty(key); - return Boolean.parseBoolean(value); - } - - /** - * Gets the values for a comma-separated list property value as a String - * array. - * - * @param key - * Property key - * @return Array of values with leading and trailing whitespace removed; - * null if key is not found. - */ - public static String[] getCsvListProperty(final String key) { - String listVal = getProperty(key); - if (listVal == null) - return null; - String[] vals = listVal.split("\\s*,\\s*"); - return vals; - } - - /** - * Convenience method to get a property from the fake hierarchical key-value - * set. - * - * @param controllerKey - * First part of key - * @param propKey - * Second part of key - * @return Property value for key "controllerKey.propKey" - */ - public static String getControllerProperty(final String controllerKey, final String propKey) { - final String key = controllerKey + '.' + propKey; - return getProperty(key); - } + /** + * Key for property that indicates if test data should be used + */ + public static final String CONTROLLER_MOCK_DATA = "controller.mock.data"; + /** + * Key for property with list of controllers + */ + public static final String CONTROLLER_KEY_LIST = "controller.key.list"; + /** + * Subkey for property with Controller name (description) + */ + public static final String CONTROLLER_SUBKEY_NAME = "name"; + /** + * Subkey for property with Controller URL + */ + 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_PASS = "password"; + /** + * Subkey for property with Controller password encryption status + */ + public static final String CONTROLLER_SUBKEY_ENCRYPTED = "is_encrypted"; + /** + * Key for dashboard deployment environment - dev/uat/prod + */ + 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; + } + + /** + * @param environment Environment + */ + @Autowired + public void setEnvironment(final Environment environment) { + this.environment = environment; + } + + /** + * @param key Property key + * @return True or false + */ + public static boolean containsProperty(final String key) { + return environment.containsProperty(key); + } + + /** + * @param key Property key + * @return String value; throws unchecked exception if key is not found + */ + 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 static Boolean getBooleanProperty(final String key) { + final String value = getProperty(key); + return Boolean.parseBoolean(value); + } + + /** + * Gets the values for a comma-separated list property value as a String array. + * + * @param key Property key + * @return Array of values with leading and trailing whitespace removed; null if + * key is not found. + */ + public static String[] getCsvListProperty(final String key) { + String listVal = getProperty(key); + if (listVal == null) + return null; + String[] vals = listVal.split("\\s*,\\s*"); + return vals; + } + + /** + * Convenience method to get a property from the fake hierarchical key-value + * set. + * + * @param controllerKey First part of key + * @param propKey Second part of key + * @return Property value for key "controllerKey.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/model/Result.java b/ccsdk-app-common/src/main/java/org/onap/fusionapp/model/Result.java index 1f6328d..bc0a43a 100644 --- a/ccsdk-app-common/src/main/java/org/onap/fusionapp/model/Result.java +++ b/ccsdk-app-common/src/main/java/org/onap/fusionapp/model/Result.java @@ -25,29 +25,27 @@ package org.onap.fusionapp.model; * Trivial model of a String */ public class Result { - private String result; + private String result; - /** - * @param result - * String - */ - public Result(String result) { - this.result = result; - } + /** + * @param result String + */ + public Result(String result) { + this.result = result; + } - /** - * @return String - */ - public String getResult() { - return result; - } + /** + * @return String + */ + public String getResult() { + return result; + } - /** - * @param result - * String - */ - public void setResult(String result) { - this.result = result; - } + /** + * @param result String + */ + public void setResult(String result) { + this.result = result; + } } 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 644d332..0f2a1db 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 @@ -30,13 +30,12 @@ import org.onap.portalsdk.core.domain.User; */
public class AdminAuthExtension {
- /**
- * @param user
- * User who was authenticated
- */
- public void saveUserExtension(User user) {
- // app's developer implement their own logic here, like updating app's
- // related tables
- }
+ /**
+ * @param user User who was authenticated
+ */
+ public void saveUserExtension(User user) {
+ // app's developer implement their own logic here, like updating app's
+ // related tables
+ }
}
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 165a8b8..13c36e6 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 @@ -33,26 +33,25 @@ import ch.qos.logback.core.spi.FilterReply; */ public class CustomLoggingFilter extends Filter<ILoggingEvent> { - /** - * Custom Filter is added to strip out the continuous U-EB logging messages - * But make sure we log the ERROR and WARNING Level messages. - * - * @param event - * Logging event - */ - @Override - public FilterReply decide(ILoggingEvent event) { - try { - if ((event.getLevel() != Level.ERROR || event.getLevel() != Level.WARN) - && ("UEBConsumerThread".equalsIgnoreCase(event.getThreadName())) - && (event.getLoggerName().contains("com.att.nsa") - || event.getLoggerName().contains("org.apache.http"))) { - return FilterReply.DENY; - } else { - return FilterReply.NEUTRAL; - } - } catch (Exception e) { - return FilterReply.NEUTRAL; - } - } + /** + * Custom Filter is added to strip out the continuous U-EB logging messages But + * make sure we log the ERROR and WARNING Level messages. + * + * @param event Logging event + */ + @Override + public FilterReply decide(ILoggingEvent event) { + try { + if ((event.getLevel() != Level.ERROR || event.getLevel() != Level.WARN) + && ("UEBConsumerThread".equalsIgnoreCase(event.getThreadName())) + && (event.getLoggerName().contains("com.att.nsa") + || event.getLoggerName().contains("org.apache.http"))) { + return FilterReply.DENY; + } else { + return FilterReply.NEUTRAL; + } + } catch (Exception e) { + return FilterReply.NEUTRAL; + } + } } 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 index ff6aa24..0a5fe93 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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 static org.junit.Assert.*; 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 index 4b68c8e..0a331e0 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.core; import java.util.Date; 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 index e7e51cf..5f4f737 100644 --- 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 @@ -1,3 +1,24 @@ +/******************************************************************************* + * =============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.rest; import static org.hamcrest.CoreMatchers.is; |