aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/swagger/api/Bootstrap.java52
-rw-r--r--src/main/java/io/swagger/api/factories/DcaeServiceTypesApiServiceFactory.java38
-rw-r--r--src/main/java/io/swagger/api/factories/DcaeServicesApiServiceFactory.java57
-rw-r--r--src/main/java/io/swagger/api/factories/DcaeServicesGroupbyApiServiceFactory.java38
-rw-r--r--src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java222
-rw-r--r--src/main/java/io/swagger/api/impl/DcaeServicesApiServiceImpl.java400
-rw-r--r--src/main/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImpl.java106
7 files changed, 913 insertions, 0 deletions
diff --git a/src/main/java/io/swagger/api/Bootstrap.java b/src/main/java/io/swagger/api/Bootstrap.java
new file mode 100644
index 0000000..71be330
--- /dev/null
+++ b/src/main/java/io/swagger/api/Bootstrap.java
@@ -0,0 +1,52 @@
+package io.swagger.api;
+
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+import io.swagger.jaxrs.config.SwaggerContextService;
+import io.swagger.models.*;
+
+import io.swagger.models.auth.*;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+
+public class Bootstrap extends HttpServlet {
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+ Info info = new Info()
+ .title("Swagger Server")
+ .description("DCAE Inventory is a web service that provides the following:\n\n1. Real-time data on all DCAE services and their components\n2. Comprehensive details on available DCAE service types\n")
+ .termsOfService("")
+ .license(new License()
+ .name("")
+ .url(""));
+
+ ServletContext context = config.getServletContext();
+ Swagger swagger = new Swagger().info(info);
+
+ new SwaggerContextService().withServletConfig(config).updateSwagger(swagger);
+ }
+}
diff --git a/src/main/java/io/swagger/api/factories/DcaeServiceTypesApiServiceFactory.java b/src/main/java/io/swagger/api/factories/DcaeServiceTypesApiServiceFactory.java
new file mode 100644
index 0000000..ba583b8
--- /dev/null
+++ b/src/main/java/io/swagger/api/factories/DcaeServiceTypesApiServiceFactory.java
@@ -0,0 +1,38 @@
+package io.swagger.api.factories;
+
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+import io.swagger.api.DcaeServiceTypesApiService;
+import io.swagger.api.impl.DcaeServiceTypesApiServiceImpl;
+
+@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2016-04-18T20:16:22.119Z")
+public class DcaeServiceTypesApiServiceFactory {
+
+ private final static DcaeServiceTypesApiService service = new DcaeServiceTypesApiServiceImpl();
+
+ public static DcaeServiceTypesApiService getDcaeServiceTypesApi()
+ {
+ return service;
+ }
+}
diff --git a/src/main/java/io/swagger/api/factories/DcaeServicesApiServiceFactory.java b/src/main/java/io/swagger/api/factories/DcaeServicesApiServiceFactory.java
new file mode 100644
index 0000000..6bd06a0
--- /dev/null
+++ b/src/main/java/io/swagger/api/factories/DcaeServicesApiServiceFactory.java
@@ -0,0 +1,57 @@
+package io.swagger.api.factories;
+
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+import org.openecomp.dcae.inventory.clients.DCAEControllerClient;
+import org.openecomp.dcae.inventory.clients.DatabusControllerClient;
+import io.swagger.api.DcaeServicesApiService;
+import io.swagger.api.impl.DcaeServicesApiServiceImpl;
+
+@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2016-04-18T20:16:22.119Z")
+public class DcaeServicesApiServiceFactory {
+
+ // Yes I agree this code is not great and I blame for Swagger for putting me in this spot.
+ private static DCAEControllerClient dcaeControllerClient;
+ private static DatabusControllerClient databusControllerClient;
+
+ public static void setDcaeControllerClient(DCAEControllerClient dcaeControllerClient) {
+ DcaeServicesApiServiceFactory.dcaeControllerClient = dcaeControllerClient;
+ }
+
+ public static void setDatabusControllerClient(DatabusControllerClient databusControllerClient) {
+ DcaeServicesApiServiceFactory.databusControllerClient = databusControllerClient;
+ }
+
+ public static DcaeServicesApiService getDcaeServicesApi() {
+ // TODO: Hide these exceptions behind a custom exception. This should be fatal.
+ if (dcaeControllerClient == null) {
+ throw new RuntimeException("DCAE controller client not configured");
+ }
+ if (databusControllerClient == null) {
+ throw new RuntimeException("Databus controller client not configured");
+ }
+ return new DcaeServicesApiServiceImpl(dcaeControllerClient, databusControllerClient);
+ }
+
+}
diff --git a/src/main/java/io/swagger/api/factories/DcaeServicesGroupbyApiServiceFactory.java b/src/main/java/io/swagger/api/factories/DcaeServicesGroupbyApiServiceFactory.java
new file mode 100644
index 0000000..43cdcb6
--- /dev/null
+++ b/src/main/java/io/swagger/api/factories/DcaeServicesGroupbyApiServiceFactory.java
@@ -0,0 +1,38 @@
+package io.swagger.api.factories;
+
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+import io.swagger.api.DcaeServicesGroupbyApiService;
+import io.swagger.api.impl.DcaeServicesGroupbyApiServiceImpl;
+
+@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2016-04-18T20:16:22.119Z")
+public class DcaeServicesGroupbyApiServiceFactory {
+
+ private final static DcaeServicesGroupbyApiService service = new DcaeServicesGroupbyApiServiceImpl();
+
+ public static DcaeServicesGroupbyApiService getDcaeServicesGroupbyApi()
+ {
+ return service;
+ }
+}
diff --git a/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java b/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java
new file mode 100644
index 0000000..261f52c
--- /dev/null
+++ b/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java
@@ -0,0 +1,222 @@
+package io.swagger.api.impl;
+
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+import org.openecomp.dcae.inventory.daos.DCAEServiceTypesDAO;
+import org.openecomp.dcae.inventory.daos.DCAEServicesDAO;
+import org.openecomp.dcae.inventory.daos.InventoryDAOManager;
+import org.openecomp.dcae.inventory.dbthings.mappers.DCAEServiceTypeObjectMapper;
+import org.openecomp.dcae.inventory.dbthings.models.DCAEServiceObject;
+import org.openecomp.dcae.inventory.dbthings.models.DCAEServiceTypeObject;
+import io.swagger.api.*;
+import io.swagger.model.*;
+
+import io.swagger.api.NotFoundException;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+import org.skife.jdbi.v2.Handle;
+import org.skife.jdbi.v2.Query;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriInfo;
+import java.util.ArrayList;
+import java.util.List;
+
+@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2016-04-18T20:16:22.119Z")
+public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService {
+
+ private final static Logger LOG = LoggerFactory.getLogger(DcaeServiceTypesApiServiceImpl.class);
+ private static int PAGINATION_PAGE_SIZE = 25;
+
+ private DCAEServiceType createDCAEServiceType(DCAEServiceTypeObject serviceTypeObject, UriInfo uriInfo) {
+ DCAEServiceType serviceType = new DCAEServiceType();
+ serviceType.setSelfLink(DcaeServiceTypesApi.buildLinkForGet(uriInfo, "self", serviceTypeObject.getTypeName()));
+ serviceType.setTypeName(serviceTypeObject.getTypeName());
+ serviceType.setOwner(serviceTypeObject.getOwner());
+ serviceType.setVnfTypes(serviceTypeObject.getVnfTypes());
+ serviceType.setServiceIds(serviceTypeObject.getServiceIds());
+ serviceType.setServiceLocations(serviceTypeObject.getServiceLocations());
+ serviceType.setBlueprintTemplate(serviceTypeObject.getBlueprintTemplate());
+ serviceType.created(serviceTypeObject.getCreated().toDate());
+
+ return serviceType;
+ }
+
+ @Override
+ public Response dcaeServiceTypesGet(String vnfType, String serviceId, String serviceLocation, Integer offset, UriInfo uriInfo,
+ SecurityContext securityContext)
+ throws NotFoundException {
+ List<DCAEServiceTypeObject> serviceTypeObjects = new ArrayList<>();
+
+ // TODO: Make this variable also a URL parameter.
+ DateTime createdCutoff = DateTime.now(DateTimeZone.UTC);
+
+ try (Handle jdbiHandle = InventoryDAOManager.getInstance().getHandle()) {
+ StringBuilder sb = new StringBuilder("select * from dcae_service_types");
+
+ List<String> whereClauses = new ArrayList<String>();
+
+ if (vnfType != null) {
+ whereClauses.add(":vnfType = any(vnf_types)");
+ }
+
+ if (serviceId != null) {
+ whereClauses.add("(:serviceId = any(service_ids) or service_ids = \'{}\' or service_ids is null)");
+ }
+
+ if (serviceLocation != null) {
+ whereClauses.add("(:serviceLocation = any(service_locations) or service_locations = \'{}\' or service_locations is null)");
+ }
+
+ whereClauses.add("created < :createdCutoff");
+ // We only want the active service types
+ whereClauses.add("is_active = TRUE");
+
+ if (!whereClauses.isEmpty()) {
+ sb.append(" where ");
+ sb.append(String.join(" and ", whereClauses));
+ }
+
+ // Sort by created timestamp - always descending.
+ sb.append(" order by created desc");
+
+ Query<DCAEServiceTypeObject> query = jdbiHandle.createQuery(sb.toString()).map(new DCAEServiceTypeObjectMapper());
+
+ if (vnfType != null) {
+ query.bind("vnfType", vnfType);
+ }
+
+ if (serviceId != null) {
+ query.bind("serviceId", serviceId);
+ }
+
+ if (serviceLocation != null) {
+ query.bind("serviceLocation", serviceLocation);
+ }
+
+ query.bind("createdCutoff", createdCutoff);
+
+ serviceTypeObjects = query.list();
+ }
+
+ offset = (offset == null) ? 0 : offset;
+
+ Integer totalCount = serviceTypeObjects.size();
+
+ // See comment in DcaeServicesApiServiceImpl.java above similar code.
+ Integer endpoint = Math.min(offset + PAGINATION_PAGE_SIZE, totalCount);
+ List<DCAEServiceTypeObject> serviceTypeObjectsSliced = serviceTypeObjects.subList(offset, endpoint);
+
+ List<DCAEServiceType> serviceTypes = new ArrayList<>();
+
+ for (DCAEServiceTypeObject serviceTypeObject : serviceTypeObjectsSliced) {
+ serviceTypes.add(createDCAEServiceType(serviceTypeObject, uriInfo));
+ }
+
+ InlineResponse200 response = new InlineResponse200();
+ response.setItems(serviceTypes);
+ response.setTotalCount(totalCount);
+
+ InlineResponse200Links navigationLinks = new InlineResponse200Links();
+ Integer offsetPrev = offset - PAGINATION_PAGE_SIZE;
+
+ if (offsetPrev >= 0) {
+ navigationLinks.setPreviousLink(DcaeServiceTypesApi.buildLinkForGet(uriInfo, "prev", vnfType, offsetPrev));
+ }
+
+ Integer offsetNext = offset + PAGINATION_PAGE_SIZE;
+
+ if (offsetNext < totalCount) {
+ navigationLinks.setNextLink(DcaeServiceTypesApi.buildLinkForGet(uriInfo, "next", vnfType, offsetNext));
+ }
+
+ response.setLinks(navigationLinks);
+
+ return Response.ok().entity(response).build();
+ }
+
+ @Override
+ public Response dcaeServiceTypesTypeNameGet(String typeName, UriInfo uriInfo, SecurityContext securityContext)
+ throws NotFoundException {
+ DCAEServiceTypesDAO serviceTypesDAO = InventoryDAOManager.getInstance().getDCAEServiceTypesDAO();
+ DCAEServiceTypeObject serviceTypeObject = serviceTypesDAO.getByTypeName(typeName);
+
+ if (serviceTypeObject == null) {
+ return Response.status(Response.Status.NOT_FOUND).build();
+ }
+
+ return Response.ok().entity(createDCAEServiceType(serviceTypeObject, uriInfo)).build();
+ }
+
+ @Override
+ public Response dcaeServiceTypesTypeNamePut(String typeName, DCAEServiceTypeRequest request, UriInfo uriInfo,
+ SecurityContext securityContext) {
+ DCAEServiceTypesDAO serviceTypesDAO = InventoryDAOManager.getInstance().getDCAEServiceTypesDAO();
+ DCAEServiceTypeObject serviceTypeObject = serviceTypesDAO.getByTypeName(typeName);
+
+ if (serviceTypeObject == null) {
+ // Create object from request
+ serviceTypeObject = new DCAEServiceTypeObject();
+ serviceTypeObject.setTypeName(typeName);
+ serviceTypeObject.setOwner(request.getOwner());
+ serviceTypeObject.setVnfTypes(request.getVnfTypes());
+ serviceTypeObject.setServiceIds(request.getServiceIds());
+ serviceTypeObject.setServiceLocations(request.getServiceLocations());
+ serviceTypeObject.setBlueprintTemplate(request.getBlueprintTemplate());
+ serviceTypeObject.setCreated(DateTime.now(DateTimeZone.UTC));
+
+ serviceTypesDAO.insertNewerVersion(serviceTypeObject);
+
+ return Response.ok().entity(createDCAEServiceType(serviceTypeObject, uriInfo)).build();
+ }
+
+ DCAEServicesDAO servicesDAO = InventoryDAOManager.getInstance().getDCAEServicesDAO();
+ Integer count = servicesDAO.countByType(DCAEServiceObject.DCAEServiceStatus.RUNNING, typeName);
+
+ LOG.info(String.format("Checked num DCAE services running: %s, %d", typeName, count));
+
+ // Allow the updating of an existing DCAE service type IFF there are no running DCAE services for this type
+
+ if (count > 0) {
+ String message = String.format("DCAE services of type %s are still running: %d", typeName, count);
+ ApiResponseMessage entity = new ApiResponseMessage(ApiResponseMessage.ERROR, message);
+ return Response.status(Response.Status.CONFLICT).entity(entity).build();
+ } else {
+ serviceTypeObject.setOwner(request.getOwner());
+ serviceTypeObject.setVnfTypes(request.getVnfTypes());
+ serviceTypeObject.setServiceIds(request.getServiceIds());
+ serviceTypeObject.setServiceLocations(request.getServiceLocations());
+ serviceTypeObject.setBlueprintTemplate(request.getBlueprintTemplate());
+ serviceTypeObject.setCreated(DateTime.now(DateTimeZone.UTC));
+
+ InventoryDAOManager.getInstance().getDCAEServiceTypeTransactionDAO().upsert(serviceTypeObject);
+
+ return Response.ok().entity(serviceTypeObject).build();
+ }
+ }
+
+}
diff --git a/src/main/java/io/swagger/api/impl/DcaeServicesApiServiceImpl.java b/src/main/java/io/swagger/api/impl/DcaeServicesApiServiceImpl.java
new file mode 100644
index 0000000..1861688
--- /dev/null
+++ b/src/main/java/io/swagger/api/impl/DcaeServicesApiServiceImpl.java
@@ -0,0 +1,400 @@
+package io.swagger.api.impl;
+
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+import org.openecomp.dcae.inventory.clients.DCAEControllerClient;
+import org.openecomp.dcae.inventory.clients.DatabusControllerClient;
+import org.openecomp.dcae.inventory.daos.DCAEServiceComponentsDAO;
+import org.openecomp.dcae.inventory.daos.DCAEServiceTransactionDAO;
+import org.openecomp.dcae.inventory.daos.DCAEServicesDAO;
+import org.openecomp.dcae.inventory.daos.InventoryDAOManager;
+import org.openecomp.dcae.inventory.dbthings.mappers.DCAEServiceObjectMapper;
+import org.openecomp.dcae.inventory.dbthings.models.DCAEServiceComponentObject;
+import org.openecomp.dcae.inventory.dbthings.models.DCAEServiceObject;
+import org.openecomp.dcae.inventory.exceptions.DCAEControllerClientException;
+import org.openecomp.dcae.inventory.exceptions.DatabusControllerClientException;
+import io.swagger.api.*;
+import io.swagger.model.*;
+
+import io.swagger.api.NotFoundException;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+import org.skife.jdbi.v2.Handle;
+import org.skife.jdbi.v2.Query;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.core.*;
+import javax.ws.rs.core.Link;
+import java.util.*;
+
+@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2016-04-18T20:16:22.119Z")
+public class DcaeServicesApiServiceImpl extends DcaeServicesApiService {
+
+ private final static Logger LOG = LoggerFactory.getLogger(DcaeServicesApiServiceImpl.class);
+ private static int PAGINATION_PAGE_SIZE = 25;
+ private static String COMPONENT_SOURCE_DCAE_CONTROLLER = "DCAECONTROLLER";
+ private static String COMPONENT_SOURCE_DATA_BUS_CONTROLLER = "DMAAPCONTROLLER";
+
+ private final DCAEControllerClient dcaeControllerClient;
+ private final DatabusControllerClient databusControllerClient;
+
+ private DCAEService createDCAEService(DCAEServiceObject serviceObject, Collection<DCAEServiceComponentObject> componentObjects,
+ UriInfo uriInfo) {
+ // TODO: Complete links: come back and do links for vnf
+ DCAEService service = new DCAEService();
+ service.setServiceId(serviceObject.getServiceId());
+ service.setSelfLink(DcaeServicesApi.buildLinkForGet(uriInfo, "self", serviceObject.getServiceId()));
+ service.setTypeLink(DcaeServiceTypesApi.buildLinkForGet(uriInfo, "type", serviceObject.getTypeName()));
+ service.setCreated(serviceObject.getCreated().toDate());
+ service.setModified(serviceObject.getModified().toDate());
+ service.setVnfId(serviceObject.getVnfId());
+ //service.setVnfLink(vnfLink);
+ service.setVnfType(serviceObject.getVnfType());
+ service.setVnfLocation(serviceObject.getVnfLocation());
+ service.setDeploymentRef(serviceObject.getDeploymentRef());
+
+ List<DCAEServiceComponent> serviceComponents = new ArrayList<DCAEServiceComponent>();
+
+ for (DCAEServiceComponentObject sco : componentObjects) {
+ DCAEServiceComponent component = new DCAEServiceComponent();
+ component.setComponentId(sco.getComponentId());
+ component.setComponentType(sco.getComponentType());
+ component.setComponentSource(sco.getComponentSource());
+ component.setShareable(sco.getShareable());
+ component.setCreated(sco.getCreated().toDate());
+ component.setModified(sco.getModified().toDate());
+
+ // TODO: When putting together the components fail. Should this be a 500 case?
+ // For now, this is just logged as a warning.
+
+ if (COMPONENT_SOURCE_DCAE_CONTROLLER.equals(sco.getComponentSource().toUpperCase())) {
+ try {
+ DCAEControllerClient.ServiceInstance serviceInstance
+ = this.dcaeControllerClient.getServiceInstance(component.getComponentId());
+ component.setStatus(serviceInstance.getStatus());
+ // There's no specific location rather its inferred from the tenant
+ component.setLocation(this.dcaeControllerClient.getLocation(serviceInstance));
+ Link componentLink = Link.fromUri(this.dcaeControllerClient.constructResourceURI(sco.getComponentId()))
+ .rel("component").title(component.getComponentId()).build();
+ component.setComponentLink(componentLink);
+ } catch (DCAEControllerClientException e) {
+ LOG.warn(String.format("%s, %s", e.getMessage(), sco.toString()));
+ }
+ } else if (COMPONENT_SOURCE_DATA_BUS_CONTROLLER.equals(sco.getComponentSource().toUpperCase())) {
+ try {
+ if (this.databusControllerClient.isExists(sco.getComponentId())) {
+ Link componentLink = Link.fromUri(this.databusControllerClient.constructResourceURI(sco.getComponentId()))
+ .rel("component").title(component.getComponentId()).build();
+ component.setComponentLink(componentLink);
+ } else {
+ LOG.warn(String.format("Feed/topic does not exist: %s", sco.getComponentId()));
+ }
+ } catch (DatabusControllerClientException e) {
+ LOG.warn(String.format("%s, %s", e.getMessage(), sco.toString()));
+ }
+ } else {
+ LOG.warn(String.format("Handling unknown component source: %s", sco.getComponentSource()));
+ }
+
+ serviceComponents.add(component);
+ }
+
+ service.components(serviceComponents);
+
+ return service;
+ }
+
+ @Override
+ public Response dcaeServicesGet(String typeName, String vnfId, String vnfType, String vnfLocation,
+ String componentType, Boolean shareable, DateTime created, Integer offset,
+ UriInfo uriInfo, SecurityContext securityContext) {
+ List<DCAEServiceObject> serviceObjects = new ArrayList<>();
+ DateTime createdCutoff = (created == null ? DateTime.now(DateTimeZone.UTC) : created);
+
+ LOG.info(String.format("Create time upper bound cutoff: %s", createdCutoff.toString()));
+
+ // Offset is zero-based index
+ offset = (offset == null) ? 0 : offset;
+ LOG.info(String.format("Query offset: %d", offset));
+
+ try (Handle jdbiHandle = InventoryDAOManager.getInstance().getHandle()) {
+ // WATCH! There is the use of "distinct" here.
+ StringBuilder sb = new StringBuilder("select distinct ds.* from dcae_services ds");
+ sb.append(" join dcae_services_components_maps m on ds.service_id = m.service_id ");
+ sb.append(" join dcae_service_components dsc on m.component_id = dsc.component_id");
+
+ List<String> whereClauses = new ArrayList<String>();
+
+ if (typeName != null) {
+ whereClauses.add("ds.type_name = :typeName");
+ }
+
+ if (vnfId != null) {
+ whereClauses.add("ds.vnf_id = :vnfId");
+ }
+
+ if (vnfType != null) {
+ whereClauses.add("ds.vnf_type = :vnfType");
+ }
+
+ if (vnfLocation != null) {
+ whereClauses.add("ds.vnf_location = :vnfLocation");
+ }
+
+ if (componentType != null) {
+ whereClauses.add("dsc.component_type = :componentType");
+ }
+
+ if (shareable != null) {
+ whereClauses.add("dsc.shareable = :shareable");
+ }
+
+ whereClauses.add("ds.created < :createdCutoff");
+ whereClauses.add("ds.status = :serviceStatus");
+
+ if (!whereClauses.isEmpty()) {
+ sb.append(" where ");
+ sb.append(String.join(" and ", whereClauses));
+ }
+
+ // Sort by created timestamp - always descending.
+ sb.append(" order by created desc");
+
+ Query<DCAEServiceObject> query = jdbiHandle.createQuery(sb.toString()).map(new DCAEServiceObjectMapper());
+
+ if (typeName != null) {
+ query.bind("typeName", typeName);
+ }
+
+ if (vnfId != null) {
+ query.bind("vnfId", vnfId);
+ }
+
+ if (vnfType != null) {
+ query.bind("vnfType", vnfType);
+ }
+
+ if (vnfLocation != null) {
+ query.bind("vnfLocation", vnfLocation);
+ }
+
+ if (componentType != null) {
+ query.bind("componentType", componentType);
+ }
+
+ if (shareable != null) {
+ // NOTE: That the shareable field in the database is actually an integer.
+ query.bind("shareable", (shareable ? 1 : 0));
+ }
+
+ query.bind("createdCutoff", createdCutoff);
+ // NOTE: This is hardcoded because service status is only used internally.
+ query.bind("serviceStatus", DCAEServiceObject.DCAEServiceStatus.RUNNING);
+
+ serviceObjects = query.list();
+ }
+
+ // NOTE: Chose to do the pagination via in code here rather than in SQL using LIMIT and OFFSET constraints
+ // because of the need for the global total number of result items. SQL approach would require two queries.
+ // Going forward, I think the better approach is using SQL because the resultsets may become very large.
+ // For now I think this approach is OK and actually we do less SQL querying.
+ Integer endpoint = Math.min(offset + PAGINATION_PAGE_SIZE, serviceObjects.size());
+ List<DCAEServiceObject> serviceObjectsSliced = serviceObjects.subList(offset, endpoint);
+
+ DCAEServiceComponentsDAO componentsDAO = InventoryDAOManager.getInstance().getDCAEServiceComponentsDAO();
+ List<DCAEService> services = new ArrayList<DCAEService>();
+
+ for (DCAEServiceObject so : serviceObjectsSliced) {
+ List<DCAEServiceComponentObject> components = componentsDAO.getByServiceId(so.getServiceId());
+ services.add(createDCAEService(so, components, uriInfo));
+ }
+
+ InlineResponse2001 response = new InlineResponse2001();
+ response.setItems(services);
+ response.setTotalCount(serviceObjects.size());
+ // TODO: Show the total count of items in this response i.e. local count?
+
+ InlineResponse200Links navigationLinks = new InlineResponse200Links();
+ Integer offsetPrev = offset - PAGINATION_PAGE_SIZE;
+
+ if (offsetPrev >= 0) {
+ navigationLinks.setPreviousLink(DcaeServicesApi.buildLinkForGet(uriInfo, "prev", typeName, vnfId, vnfType,
+ vnfLocation, componentType, shareable, created, offsetPrev));
+ }
+
+ Integer offsetNext = offset + PAGINATION_PAGE_SIZE;
+
+ if (offsetNext < serviceObjects.size()) {
+ navigationLinks.setNextLink(DcaeServicesApi.buildLinkForGet(uriInfo, "next", typeName, vnfId, vnfType,
+ vnfLocation, componentType, shareable, created, offsetNext));
+ }
+
+ response.setLinks(navigationLinks);
+
+ return Response.ok().entity(response).build();
+ }
+
+ @Override
+ public Response dcaeServicesServiceIdGet(String serviceId, UriInfo uriInfo, SecurityContext securityContext)
+ throws NotFoundException {
+ DCAEServicesDAO servicesDAO = InventoryDAOManager.getInstance().getDCAEServicesDAO();
+ DCAEServiceComponentsDAO componentsDAO = InventoryDAOManager.getInstance().getDCAEServiceComponentsDAO();
+
+ DCAEServiceObject serviceObject = servicesDAO.getByServiceId(DCAEServiceObject.DCAEServiceStatus.RUNNING, serviceId);
+
+ if (serviceObject == null) {
+ throw new NotFoundException(1, String.format("DCAEService not found: %s", serviceId));
+ }
+
+ List<DCAEServiceComponentObject> componentObjects = componentsDAO.getByServiceId(serviceId);
+ DCAEService service = createDCAEService(serviceObject, componentObjects, uriInfo);
+
+ return Response.ok().entity(service).build();
+ }
+
+ @Override
+ public Response dcaeServicesServiceIdPut(String serviceId, DCAEServiceRequest request, UriInfo uriInfo,
+ SecurityContext securityContext) {
+ // Check to make sure that the DCAE service type exists
+ if (InventoryDAOManager.getInstance().getDCAEServiceTypesDAO().getByTypeName(request.getTypeName()) == null) {
+ String errorMessage = String.format("DCAE service type does not exist: %s", request.getTypeName());
+ ApiResponseMessage message = new ApiResponseMessage(ApiResponseMessage.ERROR, errorMessage);
+ return Response.status(422).entity(message).build();
+ }
+
+ // TODO: Check DCAE service components against source services i.e. DCAE controller and data bus controller
+ // Possibly refuse to process if that check fails.
+
+ DCAEServicesDAO servicesDAO = InventoryDAOManager.getInstance().getDCAEServicesDAO();
+ DCAEServiceComponentsDAO componentsDAO = InventoryDAOManager.getInstance().getDCAEServiceComponentsDAO();
+
+ // NOTE: 1607 is using Postgres v9.3 which does NOT have the upgrade to the INSERT operation that allows for UPSERTs
+ // Challenge here is make this entire PUT operation atomic.
+ // TODO: 1607 we are actually using v9.5 which has the UPSERT. Migrate this code to use the UPSERT.
+
+ // Watch! We have to query for services regardless of status because we need to account for "removed" instances
+ // that get resurrected.
+ final DCAEServiceObject serviceObjectFromStore = servicesDAO.getByServiceId(serviceId);
+ final Map<String, DCAEServiceComponentObject> componentObjectsFromStore = new HashMap<String, DCAEServiceComponentObject>();
+
+ for (DCAEServiceComponentObject componentObject : componentsDAO.getByServiceId(serviceId)) {
+ componentObjectsFromStore.put(componentObject.getComponentId(), componentObject);
+ }
+
+ DateTime modified = DateTime.now(DateTimeZone.UTC);
+
+ DCAEServiceTransactionDAO.DCAEServiceTransactionContext transactionContext
+ = new DCAEServiceTransactionDAO.DCAEServiceTransactionContext(serviceId, modified);
+
+ // 1) Insert/update for DCAEServiceObject
+
+ DCAEServiceObject serviceObjectToSendBack = serviceObjectFromStore;
+
+ if (serviceObjectFromStore == null) {
+ serviceObjectToSendBack = new DCAEServiceObject(serviceId, request);
+ serviceObjectToSendBack.setModified(modified);
+ transactionContext.setServiceObjectToInsert(serviceObjectToSendBack);
+ } else {
+ LOG.info(String.format("DCAEServiceObject already exists - updating: %s, %s",
+ serviceObjectFromStore.getCreated().toString(),
+ serviceObjectFromStore.getModified().toString()));
+
+ serviceObjectToSendBack = new DCAEServiceObject(serviceObjectFromStore, request);
+ serviceObjectToSendBack.setModified(modified);
+ transactionContext.setServiceObjectToUpdate(serviceObjectToSendBack);
+ }
+
+ // 2) Insert/update DCAEServiceComponentObjects. Components exist independent of the associated DCAE service.
+
+ Map<String, DCAEServiceComponentObject> componentObjectsToSendBack = new HashMap<String, DCAEServiceComponentObject>();
+
+ for (DCAEServiceComponentRequest requestComponent : request.getComponents()) {
+ // Have to query the database rather than checking the result of getting by service id because of the
+ // independence of components and services. A component may already exist even though from a service
+ // perspective it is seen as "new".
+ final DCAEServiceComponentObject coExisting = componentsDAO.getByComponentId(requestComponent.getComponentId());
+ DCAEServiceComponentObject coToSendBack = null;
+
+ if (coExisting == null) {
+ // Add new component
+ coToSendBack = new DCAEServiceComponentObject(requestComponent);
+ coToSendBack.setModified(modified);
+ transactionContext.addComponentObjectToInsert(coToSendBack);
+ } else {
+ // TODO: Check if the mutable fields have changed before doing the update.
+ // Update existing component
+ coToSendBack = new DCAEServiceComponentObject(coExisting, requestComponent);
+ coToSendBack.setModified(modified);
+ transactionContext.addComponentObjectToUpdate(coToSendBack);
+ }
+
+ if (coToSendBack != null) {
+ componentObjectsToSendBack.put(coToSendBack.getComponentId(), coToSendBack);
+ }
+ }
+
+ // 3) Update relationships: add ones that don't exist, delete ones that do exist but no longer should not
+
+ // Add relationships that didn't exist before
+ for (String componentId : componentObjectsToSendBack.keySet()) {
+ if (!componentObjectsFromStore.containsKey(componentId)) {
+ transactionContext.addMappingsToInsert(componentId);
+ }
+ }
+
+ // Remove relationships that have been removed
+ for (String componentId : componentObjectsFromStore.keySet()) {
+ if (!componentObjectsToSendBack.containsKey(componentId)) {
+ transactionContext.addMappingsToDelete(componentId);
+ }
+ }
+
+ DCAEServiceTransactionDAO transactionDAO = InventoryDAOManager.getInstance().getDCAEServiceTransactionDAO();
+ transactionDAO.insert(transactionContext);
+
+ DCAEService service = createDCAEService(serviceObjectToSendBack, componentObjectsToSendBack.values(), uriInfo);
+
+ return Response.ok().entity(service).build();
+ }
+
+ public Response dcaeServicesServiceIdDelete(String serviceId, SecurityContext securityContext) throws NotFoundException {
+ DCAEServicesDAO servicesDAO = InventoryDAOManager.getInstance().getDCAEServicesDAO();
+
+ if (servicesDAO.getByServiceId(DCAEServiceObject.DCAEServiceStatus.RUNNING, serviceId) == null) {
+ throw new NotFoundException(ApiResponseMessage.ERROR, String.format("DCAE service not found: %s", serviceId));
+ }
+
+ servicesDAO.updateStatusByServiceId(DateTime.now(DateTimeZone.UTC), DCAEServiceObject.DCAEServiceStatus.REMOVED,
+ serviceId);
+
+ return Response.ok().build();
+ }
+
+ public DcaeServicesApiServiceImpl(DCAEControllerClient dcaeControllerClient, DatabusControllerClient databusControllerClient) {
+ this.dcaeControllerClient = dcaeControllerClient;
+ this.databusControllerClient = databusControllerClient;
+ }
+
+}
diff --git a/src/main/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImpl.java b/src/main/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImpl.java
new file mode 100644
index 0000000..10bd7fa
--- /dev/null
+++ b/src/main/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImpl.java
@@ -0,0 +1,106 @@
+package io.swagger.api.impl;
+
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+import org.openecomp.dcae.inventory.daos.InventoryDAOManager;
+import org.openecomp.dcae.inventory.dbthings.models.DCAEServiceObject;
+import io.swagger.api.*;
+import io.swagger.model.DCAEServiceGroupByResults;
+import io.swagger.model.DCAEServiceGroupByResultsPropertyValues;
+import org.skife.jdbi.v2.Handle;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriInfo;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2016-04-18T20:16:22.119Z")
+public class DcaeServicesGroupbyApiServiceImpl extends DcaeServicesGroupbyApiService {
+
+ @Override
+ public Response dcaeServicesGroupbyPropertyNameGet(String propertyName, UriInfo uriInfo, SecurityContext securityContext) {
+ String columnName = "";
+
+ switch (propertyName) {
+ case "type":
+ columnName = "type_name";
+ break;
+ case "vnfLocation":
+ columnName = "vnf_location";
+ break;
+ case "vnfType":
+ columnName = "vnf_type";
+ break;
+ default:
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+
+ List<Map<String, Object>> results = new ArrayList<>();
+
+ try (Handle jdbiHandle = InventoryDAOManager.getInstance().getHandle()) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(String.format("select %s, count(1) as num ", columnName));
+ sb.append(" from dcae_services where status = :serviceStatus");
+ sb.append(String.format(" group by %s order by count(1) desc", columnName));
+ String queryString = sb.toString();
+
+ // NOTE: This is hardcoded because service status is only used internally.
+ results = jdbiHandle.createQuery(queryString).bind("serviceStatus", DCAEServiceObject.DCAEServiceStatus.RUNNING)
+ .list();
+ }
+
+ DCAEServiceGroupByResults response = new DCAEServiceGroupByResults();
+ response.setPropertyName(propertyName);
+
+ for (Map<String, Object> result : results) {
+ DCAEServiceGroupByResultsPropertyValues value = new DCAEServiceGroupByResultsPropertyValues();
+ value.setCount(((Long) result.get("num")).intValue());
+ String propertyValue = (String) result.get(columnName);
+ value.setPropertyValue(propertyValue);
+
+ switch (propertyName) {
+ case "type":
+ value.setDcaeServiceQueryLink(DcaeServicesApi.buildLinkForGetByTypeName(uriInfo, "dcae_services",
+ propertyValue));
+ break;
+ case "vnfLocation":
+ value.setDcaeServiceQueryLink(DcaeServicesApi.buildLinkForGetByVnfLocation(uriInfo, "dcae_services",
+ propertyValue));
+ break;
+ case "vnfType":
+ value.setDcaeServiceQueryLink(DcaeServicesApi.buildLinkForGetByVnfType(uriInfo, "dcae_services",
+ propertyValue));
+ break;
+ default:
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+
+ response.getPropertyValues().add(value);
+ }
+
+ return Response.ok().entity(response).build();
+ }
+}