diff options
Diffstat (limited to 'src/main/java/io/swagger/api')
7 files changed, 254 insertions, 183 deletions
diff --git a/src/main/java/io/swagger/api/Bootstrap.java b/src/main/java/io/swagger/api/Bootstrap.java index 71be330..5050ed3 100644 --- a/src/main/java/io/swagger/api/Bootstrap.java +++ b/src/main/java/io/swagger/api/Bootstrap.java @@ -1,28 +1,25 @@ -package io.swagger.api; - -/* - * ============LICENSE_START========================================== - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== +/*- + * ============LICENSE_START======================================================= + * dcae-inventory + * ================================================================================ + * 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 - * + * + * 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. - * + * ============LICENSE_END========================================================= */ +package io.swagger.api; + import io.swagger.jaxrs.config.SwaggerContextService; import io.swagger.models.*; @@ -40,6 +37,8 @@ public class Bootstrap extends HttpServlet { .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("") + .contact(new Contact() + .email("dcae@lists.openecomp.org")) .license(new License() .name("") .url("")); diff --git a/src/main/java/io/swagger/api/factories/DcaeServiceTypesApiServiceFactory.java b/src/main/java/io/swagger/api/factories/DcaeServiceTypesApiServiceFactory.java index ba583b8..fecd8fe 100644 --- a/src/main/java/io/swagger/api/factories/DcaeServiceTypesApiServiceFactory.java +++ b/src/main/java/io/swagger/api/factories/DcaeServiceTypesApiServiceFactory.java @@ -1,28 +1,25 @@ -package io.swagger.api.factories; - -/* - * ============LICENSE_START========================================== - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== +/*- + * ============LICENSE_START======================================================= + * dcae-inventory + * ================================================================================ + * 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 - * + * + * 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. - * + * ============LICENSE_END========================================================= */ +package io.swagger.api.factories; + import io.swagger.api.DcaeServiceTypesApiService; import io.swagger.api.impl.DcaeServiceTypesApiServiceImpl; diff --git a/src/main/java/io/swagger/api/factories/DcaeServicesApiServiceFactory.java b/src/main/java/io/swagger/api/factories/DcaeServicesApiServiceFactory.java index 6bd06a0..47f213d 100644 --- a/src/main/java/io/swagger/api/factories/DcaeServicesApiServiceFactory.java +++ b/src/main/java/io/swagger/api/factories/DcaeServicesApiServiceFactory.java @@ -1,28 +1,25 @@ -package io.swagger.api.factories; - -/* - * ============LICENSE_START========================================== - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== +/*- + * ============LICENSE_START======================================================= + * dcae-inventory + * ================================================================================ + * 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 - * + * + * 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. - * + * ============LICENSE_END========================================================= */ +package io.swagger.api.factories; + import org.openecomp.dcae.inventory.clients.DCAEControllerClient; import org.openecomp.dcae.inventory.clients.DatabusControllerClient; import io.swagger.api.DcaeServicesApiService; @@ -44,13 +41,6 @@ public class DcaeServicesApiServiceFactory { } 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 index 43cdcb6..041fbaf 100644 --- a/src/main/java/io/swagger/api/factories/DcaeServicesGroupbyApiServiceFactory.java +++ b/src/main/java/io/swagger/api/factories/DcaeServicesGroupbyApiServiceFactory.java @@ -1,28 +1,25 @@ -package io.swagger.api.factories; - -/* - * ============LICENSE_START========================================== - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== +/*- + * ============LICENSE_START======================================================= + * dcae-inventory + * ================================================================================ + * 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 - * + * + * 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. - * + * ============LICENSE_END========================================================= */ +package io.swagger.api.factories; + import io.swagger.api.DcaeServicesGroupbyApiService; import io.swagger.api.impl.DcaeServicesGroupbyApiServiceImpl; diff --git a/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java b/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java index 261f52c..34d8a4b 100644 --- a/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java +++ b/src/main/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImpl.java @@ -1,28 +1,25 @@ -package io.swagger.api.impl; - -/* - * ============LICENSE_START========================================== - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== +/*- + * ============LICENSE_START======================================================= + * dcae-inventory + * ================================================================================ + * 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 - * + * + * 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. - * + * ============LICENSE_END========================================================= */ +package io.swagger.api.impl; + import org.openecomp.dcae.inventory.daos.DCAEServiceTypesDAO; import org.openecomp.dcae.inventory.daos.DCAEServicesDAO; import org.openecomp.dcae.inventory.daos.InventoryDAOManager; @@ -45,6 +42,8 @@ import javax.ws.rs.core.SecurityContext; import javax.ws.rs.core.UriInfo; import java.util.ArrayList; import java.util.List; +import java.util.Locale; +import java.util.UUID; @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2016-04-18T20:16:22.119Z") public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService { @@ -54,21 +53,30 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService { private DCAEServiceType createDCAEServiceType(DCAEServiceTypeObject serviceTypeObject, UriInfo uriInfo) { DCAEServiceType serviceType = new DCAEServiceType(); - serviceType.setSelfLink(DcaeServiceTypesApi.buildLinkForGet(uriInfo, "self", serviceTypeObject.getTypeName())); + serviceType.setSelfLink(DcaeServiceTypesApi.buildLinkForGet(uriInfo, "self", serviceTypeObject.getTypeId())); + serviceType.setTypeId(serviceTypeObject.getTypeId()); serviceType.setTypeName(serviceTypeObject.getTypeName()); + serviceType.setTypeVersion(serviceTypeObject.getTypeVersion()); 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()); + serviceType.setAsdcServiceId(serviceTypeObject.getAsdcServiceId()); + serviceType.setAsdcResourceId(serviceTypeObject.getAsdcResourceId()); + // TODO: Construct ASDC service URL somehow + serviceType.setCreated(serviceTypeObject.getCreated().toDate()); + + DateTime deactivated = serviceTypeObject.getDeactivated(); + serviceType.setDeactivated(deactivated == null ? null : deactivated.toDate()); return serviceType; } @Override - public Response dcaeServiceTypesGet(String vnfType, String serviceId, String serviceLocation, Integer offset, UriInfo uriInfo, - SecurityContext securityContext) + public Response dcaeServiceTypesGet(String typeName, Boolean onlyLatest, Boolean onlyActive, String vnfType, + String serviceId, String serviceLocation, String asdcServiceId, + String asdcResourceId, Integer offset, UriInfo uriInfo, SecurityContext securityContext) throws NotFoundException { List<DCAEServiceTypeObject> serviceTypeObjects = new ArrayList<>(); @@ -76,12 +84,23 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService { DateTime createdCutoff = DateTime.now(DateTimeZone.UTC); try (Handle jdbiHandle = InventoryDAOManager.getInstance().getHandle()) { - StringBuilder sb = new StringBuilder("select * from dcae_service_types"); + StringBuilder sb = new StringBuilder("select * from "); + + if (onlyLatest) { + // Use the view which filters types that are of only the latest versions + sb.append("dcae_service_types_latest"); + } else { + sb.append("dcae_service_types"); + } List<String> whereClauses = new ArrayList<String>(); + if (typeName != null) { + whereClauses.add(":typeName = type_name"); + } + if (vnfType != null) { - whereClauses.add(":vnfType = any(vnf_types)"); + whereClauses.add("lower(:vnfType) = any(lower(vnf_types\\:\\:text)\\:\\:text[])"); } if (serviceId != null) { @@ -92,9 +111,27 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService { whereClauses.add("(:serviceLocation = any(service_locations) or service_locations = \'{}\' or service_locations is null)"); } + if (asdcServiceId != null) { + if ("NONE".equals(asdcServiceId.toUpperCase(Locale.ENGLISH))) { + whereClauses.add("asdc_service_id is null"); + } else { + whereClauses.add(":asdcServiceId = asdc_service_id"); + } + } + + if (asdcResourceId != null) { + if ("NONE".equals(asdcResourceId.toUpperCase(Locale.ENGLISH))) { + whereClauses.add("asdc_resource_id is null"); + } else { + whereClauses.add(":asdcResourceId = asdc_resource_id"); + } + } + whereClauses.add("created < :createdCutoff"); - // We only want the active service types - whereClauses.add("is_active = TRUE"); + + if (onlyActive) { + whereClauses.add("deactivated is null"); + } if (!whereClauses.isEmpty()) { sb.append(" where "); @@ -106,6 +143,10 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService { Query<DCAEServiceTypeObject> query = jdbiHandle.createQuery(sb.toString()).map(new DCAEServiceTypeObjectMapper()); + if (typeName != null) { + query.bind("typeName", typeName); + } + if (vnfType != null) { query.bind("vnfType", vnfType); } @@ -118,6 +159,14 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService { query.bind("serviceLocation", serviceLocation); } + if (asdcServiceId != null && !"NONE".equals(asdcServiceId.toUpperCase(Locale.ENGLISH))) { + query.bind("asdcServiceId", asdcServiceId); + } + + if (asdcResourceId != null && !"NONE".equals(asdcResourceId.toUpperCase(Locale.ENGLISH))) { + query.bind("asdcResourceId", asdcResourceId); + } + query.bind("createdCutoff", createdCutoff); serviceTypeObjects = query.list(); @@ -144,14 +193,18 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService { InlineResponse200Links navigationLinks = new InlineResponse200Links(); Integer offsetPrev = offset - PAGINATION_PAGE_SIZE; + // TODO: MUST UPDATE THIS LINK NAV CODE + if (offsetPrev >= 0) { - navigationLinks.setPreviousLink(DcaeServiceTypesApi.buildLinkForGet(uriInfo, "prev", vnfType, offsetPrev)); + navigationLinks.setPreviousLink(DcaeServiceTypesApi.buildLinkForGet(uriInfo, "prev", typeName, onlyLatest, + onlyActive, vnfType, serviceId, serviceLocation, asdcServiceId, asdcResourceId, offsetPrev)); } Integer offsetNext = offset + PAGINATION_PAGE_SIZE; if (offsetNext < totalCount) { - navigationLinks.setNextLink(DcaeServiceTypesApi.buildLinkForGet(uriInfo, "next", vnfType, offsetNext)); + navigationLinks.setNextLink(DcaeServiceTypesApi.buildLinkForGet(uriInfo, "next", typeName, onlyLatest, + onlyActive, vnfType, serviceId, serviceLocation, asdcServiceId, asdcResourceId, offsetNext)); } response.setLinks(navigationLinks); @@ -160,10 +213,10 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService { } @Override - public Response dcaeServiceTypesTypeNameGet(String typeName, UriInfo uriInfo, SecurityContext securityContext) + public Response dcaeServiceTypesTypeIdGet(String typeId, UriInfo uriInfo, SecurityContext securityContext) throws NotFoundException { DCAEServiceTypesDAO serviceTypesDAO = InventoryDAOManager.getInstance().getDCAEServiceTypesDAO(); - DCAEServiceTypeObject serviceTypeObject = serviceTypesDAO.getByTypeName(typeName); + DCAEServiceTypeObject serviceTypeObject = serviceTypesDAO.getByTypeId(typeId); if (serviceTypeObject == null) { return Response.status(Response.Status.NOT_FOUND).build(); @@ -172,51 +225,88 @@ public class DcaeServiceTypesApiServiceImpl extends DcaeServiceTypesApiService { return Response.ok().entity(createDCAEServiceType(serviceTypeObject, uriInfo)).build(); } + /** + * Create a DCAE service type database object + * + * Utility method that takes a DCAE service type request body and creates a database object representation + * to insert. + * + * @param typeId + * @param request + * @return + */ + private static DCAEServiceTypeObject createDCAEServiceTypeDBO(String typeId, DCAEServiceTypeRequest request) { + DCAEServiceTypeObject serviceTypeObject = new DCAEServiceTypeObject(); + serviceTypeObject.setTypeId(typeId); + serviceTypeObject.setTypeName(request.getTypeName()); + serviceTypeObject.setTypeVersion(request.getTypeVersion()); + serviceTypeObject.setOwner(request.getOwner()); + serviceTypeObject.setBlueprintTemplate(request.getBlueprintTemplate()); + serviceTypeObject.setVnfTypes(request.getVnfTypes()); + serviceTypeObject.setServiceIds(request.getServiceIds()); + serviceTypeObject.setServiceLocations(request.getServiceLocations()); + serviceTypeObject.setAsdcServiceId(request.getAsdcServiceId()); + serviceTypeObject.setAsdcResourceId(request.getAsdcResourceId()); + serviceTypeObject.setCreated(DateTime.now(DateTimeZone.UTC)); + + return serviceTypeObject; + } + @Override - public Response dcaeServiceTypesTypeNamePut(String typeName, DCAEServiceTypeRequest request, UriInfo uriInfo, + public Response dcaeServiceTypesTypeIdPost(DCAEServiceTypeRequest request, UriInfo uriInfo, SecurityContext securityContext) { DCAEServiceTypesDAO serviceTypesDAO = InventoryDAOManager.getInstance().getDCAEServiceTypesDAO(); - DCAEServiceTypeObject serviceTypeObject = serviceTypesDAO.getByTypeName(typeName); + // Must query by the implicit composite key: type name, type version, asdc service id, asdc resource id + // Had to split up the queries into two because in SQL selecting by null has to be `some_field is null` + // + // FIXME: There is a race condition here where there could be multiple records with different ids + // for the same implicit composite key. Maybe the answer is to simply add back in a PUT. + DCAEServiceTypeObject serviceTypeObject + = (request.getAsdcServiceId() == null || request.getAsdcResourceId() == null) + ? serviceTypesDAO.getByRequestFromNotASDC(request) : serviceTypesDAO.getByRequestFromASDC(request); 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); - + // Generate a new type id + String typeId = UUID.randomUUID().toString(); + serviceTypeObject = createDCAEServiceTypeDBO(typeId, request); + serviceTypesDAO.insert(serviceTypeObject); return Response.ok().entity(createDCAEServiceType(serviceTypeObject, uriInfo)).build(); } + // Service type with same composite key already exists so try to update + + String typeId = serviceTypeObject.getTypeId(); DCAEServicesDAO servicesDAO = InventoryDAOManager.getInstance().getDCAEServicesDAO(); - Integer count = servicesDAO.countByType(DCAEServiceObject.DCAEServiceStatus.RUNNING, typeName); + Integer count = servicesDAO.countByType(DCAEServiceObject.DCAEServiceStatus.RUNNING, typeId); - LOG.info(String.format("Checked num DCAE services running: %s, %d", typeName, count)); + LOG.info(String.format("Checked num DCAE services running: %s, %d", typeId, 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); + String message = String.format("DCAE services of type %s are still running: %d", typeId, 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)); + serviceTypeObject = createDCAEServiceTypeDBO(typeId, request); + serviceTypesDAO.update(serviceTypeObject); + return Response.ok().entity(serviceTypeObject).build(); + } + } - InventoryDAOManager.getInstance().getDCAEServiceTypeTransactionDAO().upsert(serviceTypeObject); + @Override + public Response dcaeServiceTypesTypeIdDelete(String typeId, UriInfo uriInfo, SecurityContext securityContext) + throws NotFoundException { + DCAEServiceTypesDAO serviceTypesDAO = InventoryDAOManager.getInstance().getDCAEServiceTypesDAO(); - return Response.ok().entity(serviceTypeObject).build(); + if (serviceTypesDAO.getByTypeId(typeId) == null) { + throw new NotFoundException(1, String.format("DCAE service type not found: %s", typeId)); + } else if (serviceTypesDAO.getByTypeIdActiveOnly(typeId) == null) { + return Response.status(Response.Status.GONE).build(); } + + serviceTypesDAO.deactivateExisting(typeId); + return Response.ok().build(); } } diff --git a/src/main/java/io/swagger/api/impl/DcaeServicesApiServiceImpl.java b/src/main/java/io/swagger/api/impl/DcaeServicesApiServiceImpl.java index 1861688..d1e790c 100644 --- a/src/main/java/io/swagger/api/impl/DcaeServicesApiServiceImpl.java +++ b/src/main/java/io/swagger/api/impl/DcaeServicesApiServiceImpl.java @@ -1,28 +1,25 @@ -package io.swagger.api.impl; - -/* - * ============LICENSE_START========================================== - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== +/*- + * ============LICENSE_START======================================================= + * dcae-inventory + * ================================================================================ + * 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 - * + * + * 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. - * + * ============LICENSE_END========================================================= */ +package io.swagger.api.impl; + import org.openecomp.dcae.inventory.clients.DCAEControllerClient; import org.openecomp.dcae.inventory.clients.DatabusControllerClient; import org.openecomp.dcae.inventory.daos.DCAEServiceComponentsDAO; @@ -66,7 +63,7 @@ public class DcaeServicesApiServiceImpl extends DcaeServicesApiService { 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.setTypeLink(DcaeServiceTypesApi.buildLinkForGet(uriInfo, "type", serviceObject.getTypeId())); service.setCreated(serviceObject.getCreated().toDate()); service.setModified(serviceObject.getModified().toDate()); service.setVnfId(serviceObject.getVnfId()); @@ -89,30 +86,34 @@ public class DcaeServicesApiServiceImpl extends DcaeServicesApiService { // 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())) + if (COMPONENT_SOURCE_DCAE_CONTROLLER.equals(sco.getComponentSource().toUpperCase(Locale.ENGLISH))) { + if (this.dcaeControllerClient != null) { + try { + DCAEControllerClient.ServiceInstance serviceInstance + = this.dcaeControllerClient.getServiceInstance(component.getComponentId()); + component.setStatus(serviceInstance.getStatus()); + // There's no specific location rather its inferred from the AIC 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); - } else { - LOG.warn(String.format("Feed/topic does not exist: %s", sco.getComponentId())); + } catch (DCAEControllerClientException e) { + LOG.warn(String.format("%s, %s", e.getMessage(), sco.toString())); + } + } + } else if (COMPONENT_SOURCE_DATA_BUS_CONTROLLER.equals(sco.getComponentSource().toUpperCase(Locale.ENGLISH))) { + if (this.databusControllerClient != null) { + 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())); } - } 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())); @@ -127,7 +128,7 @@ public class DcaeServicesApiServiceImpl extends DcaeServicesApiService { } @Override - public Response dcaeServicesGet(String typeName, String vnfId, String vnfType, String vnfLocation, + public Response dcaeServicesGet(String typeId, String vnfId, String vnfType, String vnfLocation, String componentType, Boolean shareable, DateTime created, Integer offset, UriInfo uriInfo, SecurityContext securityContext) { List<DCAEServiceObject> serviceObjects = new ArrayList<>(); @@ -147,8 +148,8 @@ public class DcaeServicesApiServiceImpl extends DcaeServicesApiService { List<String> whereClauses = new ArrayList<String>(); - if (typeName != null) { - whereClauses.add("ds.type_name = :typeName"); + if (typeId != null) { + whereClauses.add("ds.type_id = :typeId"); } if (vnfId != null) { @@ -156,7 +157,7 @@ public class DcaeServicesApiServiceImpl extends DcaeServicesApiService { } if (vnfType != null) { - whereClauses.add("ds.vnf_type = :vnfType"); + whereClauses.add("lower(ds.vnf_type) = lower(:vnfType)"); } if (vnfLocation != null) { @@ -184,8 +185,8 @@ public class DcaeServicesApiServiceImpl extends DcaeServicesApiService { Query<DCAEServiceObject> query = jdbiHandle.createQuery(sb.toString()).map(new DCAEServiceObjectMapper()); - if (typeName != null) { - query.bind("typeName", typeName); + if (typeId != null) { + query.bind("typeId", typeId); } if (vnfId != null) { @@ -240,14 +241,14 @@ public class DcaeServicesApiServiceImpl extends DcaeServicesApiService { Integer offsetPrev = offset - PAGINATION_PAGE_SIZE; if (offsetPrev >= 0) { - navigationLinks.setPreviousLink(DcaeServicesApi.buildLinkForGet(uriInfo, "prev", typeName, vnfId, vnfType, + navigationLinks.setPreviousLink(DcaeServicesApi.buildLinkForGet(uriInfo, "prev", typeId, 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, + navigationLinks.setNextLink(DcaeServicesApi.buildLinkForGet(uriInfo, "next", typeId, vnfId, vnfType, vnfLocation, componentType, shareable, created, offsetNext)); } @@ -278,8 +279,8 @@ public class DcaeServicesApiServiceImpl extends DcaeServicesApiService { 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()); + if (InventoryDAOManager.getInstance().getDCAEServiceTypesDAO().getByTypeIdActiveOnly(request.getTypeId()) == null) { + String errorMessage = String.format("DCAE service type does not exist: %s", request.getTypeId()); ApiResponseMessage message = new ApiResponseMessage(ApiResponseMessage.ERROR, errorMessage); return Response.status(422).entity(message).build(); } diff --git a/src/main/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImpl.java b/src/main/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImpl.java index 10bd7fa..09d3143 100644 --- a/src/main/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImpl.java +++ b/src/main/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImpl.java @@ -1,28 +1,25 @@ -package io.swagger.api.impl; - -/* - * ============LICENSE_START========================================== - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== +/*- + * ============LICENSE_START======================================================= + * dcae-inventory + * ================================================================================ + * 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 - * + * + * 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. - * + * ============LICENSE_END========================================================= */ +package io.swagger.api.impl; + import org.openecomp.dcae.inventory.daos.InventoryDAOManager; import org.openecomp.dcae.inventory.dbthings.models.DCAEServiceObject; import io.swagger.api.*; @@ -46,7 +43,7 @@ public class DcaeServicesGroupbyApiServiceImpl extends DcaeServicesGroupbyApiSer switch (propertyName) { case "type": - columnName = "type_name"; + columnName = "type_id"; break; case "vnfLocation": columnName = "vnf_location"; @@ -83,7 +80,7 @@ public class DcaeServicesGroupbyApiServiceImpl extends DcaeServicesGroupbyApiSer switch (propertyName) { case "type": - value.setDcaeServiceQueryLink(DcaeServicesApi.buildLinkForGetByTypeName(uriInfo, "dcae_services", + value.setDcaeServiceQueryLink(DcaeServicesApi.buildLinkForGetByTypeId(uriInfo, "dcae_services", propertyValue)); break; case "vnfLocation": |