diff options
Diffstat (limited to 'plans/so/integration-etsi-testing/so-simulators')
34 files changed, 2008 insertions, 203 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml index 26815ad0..c51cae12 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml @@ -8,7 +8,7 @@ </parent> <artifactId>aai-simulator</artifactId> <properties> - <version.aai.schema>1.0.0</version.aai.schema> + <version.aai.schema>1.8.1</version.aai.schema> </properties> <dependencies> <dependency> diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java index 4a0ed1b9..1221beae 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java @@ -23,12 +23,12 @@ import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSH import static org.onap.so.aaisimulator.utils.Constants.CUSTOMER_TYPE; import static org.onap.so.aaisimulator.utils.Constants.CUSTOMER_URL; import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF; -import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF_VNF_ID; import static org.onap.so.aaisimulator.utils.Constants.SERVICE_RESOURCE_TYPE; import static org.onap.so.aaisimulator.utils.Constants.SERVICE_SUBSCRIPTION; import static org.onap.so.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getRequestErrorResponseEntity; import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getResourceVersion; +import java.util.List; import java.util.Optional; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.MediaType; @@ -36,7 +36,6 @@ import org.onap.aai.domain.yang.Customer; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.GenericVnfs; import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.RelationshipData; import org.onap.aai.domain.yang.ServiceInstance; import org.onap.aai.domain.yang.ServiceInstances; import org.onap.aai.domain.yang.ServiceSubscription; @@ -263,33 +262,32 @@ public class BusinessController { public ResponseEntity<?> getRelatedToGenericVnf(@PathVariable("global-customer-id") final String globalCustomerId, @PathVariable("service-type") final String serviceType, @PathVariable(name = "service-instance-id") final String serviceInstanceId, - @RequestParam(name = "vnf-name", required = true) final String vnfName, final HttpServletRequest request) { + @RequestParam(name = "vnf-name", required = false) final String vnfName, final HttpServletRequest request) { LOGGER.info( "Will retrieve generic vnf related to information for 'global customer id': {}, 'service type': {} and 'service instance id: '{} with vnfname: {}...", globalCustomerId, serviceType, serviceInstanceId, vnfName); - final Optional<Relationship> optional = - cacheServiceProvider.getRelationship(globalCustomerId, serviceType, serviceInstanceId, vnfName); + final List<String> relatedToVnfIds = + getRelatedToVnfIds(globalCustomerId, serviceType, serviceInstanceId, vnfName); - if (optional.isPresent()) { - - final Relationship relationship = optional.get(); - final Optional<RelationshipData> relationshipDataOptional = relationship.getRelationshipData().stream() - .filter(existing -> GENERIC_VNF_VNF_ID.equals(existing.getRelationshipKey())).findFirst(); - if (relationshipDataOptional.isPresent()) { - final RelationshipData relationshipData = relationshipDataOptional.get(); - final String vnfId = relationshipData.getRelationshipValue(); + if (!relatedToVnfIds.isEmpty()) { + final GenericVnfs genericVnfs = new GenericVnfs(); + relatedToVnfIds.stream().forEach(vnfId -> { final Optional<GenericVnf> genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(vnfId); if (genericVnfOptional.isPresent()) { - final GenericVnfs genericVnfs = new GenericVnfs(); - genericVnfs.getGenericVnf().add(genericVnfOptional.get()); - LOGGER.info("found service instance {} in cache", relationship); - return ResponseEntity.ok(genericVnfs); + final GenericVnf genericVnf = genericVnfOptional.get(); + LOGGER.info("found related-to generic-vnf {} in cache", genericVnf); + genericVnfs.getGenericVnf().add(genericVnf); } + }); + if (!genericVnfs.getGenericVnf().isEmpty()) { + LOGGER.info("Found {} related generic-vnfs", genericVnfs.getGenericVnf().size()); + return ResponseEntity.ok(genericVnfs); } } + LOGGER.error( "Couldn't find generic vnf related to information for 'global customer id': {}, 'service type': {} and 'service instance id: '{} with vnfname: {}...", globalCustomerId, serviceType, serviceInstanceId, vnfName); @@ -353,4 +351,12 @@ public class BusinessController { return getRequestErrorResponseEntity(request); } + + private List<String> getRelatedToVnfIds(final String globalCustomerId, final String serviceType, + final String serviceInstanceId, final String vnfName) { + if (vnfName != null) { + return cacheServiceProvider.getRelatedToVnfIds(globalCustomerId, serviceType, serviceInstanceId, vnfName); + } + return cacheServiceProvider.getRelatedToVnfIds(globalCustomerId, serviceType, serviceInstanceId); + } } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java index 7000fb3f..af3595a0 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java @@ -19,6 +19,7 @@ */ package org.onap.so.aaisimulator.service.providers; +import java.util.List; import java.util.Optional; import org.onap.aai.domain.yang.Customer; import org.onap.aai.domain.yang.Relationship; @@ -53,13 +54,16 @@ public interface CustomerCacheServiceProvider extends Clearable { boolean patchServiceInstance(final String globalCustomerId, final String serviceType, final String serviceInstanceId, final ServiceInstance serviceInstance); - Optional<Relationship> getRelationship(final String globalCustomerId, final String serviceType, - final String serviceInstanceId, final String vnfName); - Optional<Relationship> addRelationShip(final String globalCustomerId, final String serviceType, final String serviceInstanceId, final Relationship relationship, final String requestUri); boolean deleteSericeInstance(final String globalCustomerId, final String serviceType, final String serviceInstanceId, final String resourceVersion); + List<String> getRelatedToVnfIds(final String globalCustomerId, final String serviceType, + final String serviceInstanceId, final String vnfName); + + List<String> getRelatedToVnfIds(final String globalCustomerId, final String serviceType, + final String serviceInstanceId); + } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java index 7193ade1..7285faad 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java @@ -22,11 +22,14 @@ package org.onap.so.aaisimulator.service.providers; import static org.onap.so.aaisimulator.utils.CacheName.CUSTOMER_CACHE; import static org.onap.so.aaisimulator.utils.Constants.CUSTOMER_GLOBAL_CUSTOMER_ID; import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF; +import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF_VNF_ID; import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF_VNF_NAME; import static org.onap.so.aaisimulator.utils.Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_ID; import static org.onap.so.aaisimulator.utils.Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_NAME; import static org.onap.so.aaisimulator.utils.Constants.SERVICE_SUBSCRIPTION_SERVICE_TYPE; import static org.onap.so.aaisimulator.utils.HttpServiceUtils.getBiDirectionalRelationShipListRelatedLink; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -279,7 +282,7 @@ public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvid } @Override - public Optional<Relationship> getRelationship(final String globalCustomerId, final String serviceType, + public List<String> getRelatedToVnfIds(final String globalCustomerId, final String serviceType, final String serviceInstanceId, final String vnfName) { final Optional<ServiceInstance> optional = getServiceInstance(globalCustomerId, serviceType, serviceInstanceId); @@ -289,20 +292,53 @@ public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvid final RelationshipList relationshipList = serviceInstance.getRelationshipList(); if (relationshipList != null) { - final List<Relationship> relationship = relationshipList.getRelationship(); - return relationship.stream().filter( + final List<Relationship> relationships = relationshipList.getRelationship().stream().filter( relationShip -> relationShip.getRelatedToProperty().stream().filter(relatedToProperty -> { final String propertyKey = relatedToProperty.getPropertyKey(); final String propertyValue = relatedToProperty.getPropertyValue(); return GENERIC_VNF_VNF_NAME.equals(propertyKey) && propertyValue != null && propertyValue.equals(vnfName); - }).findFirst().isPresent()).findFirst(); + }).findFirst().isPresent()).collect(Collectors.toList()); + LOGGER.info("Found relationships {} for vnf-name: {}", relationships, vnfName); + return getGenericVnfIdsIfPresent(relationships); } LOGGER.warn("Relationship list is nulll ..."); } - LOGGER.error("Unable to RelationShip with property value: {}... ", vnfName); + LOGGER.error("Unable to find generic-vnf relationships with property value: {}... ", vnfName); + return Collections.emptyList(); + } - return Optional.empty(); + @Override + public List<String> getRelatedToVnfIds(final String globalCustomerId, final String serviceType, + final String serviceInstanceId) { + final Optional<ServiceInstance> optional = getServiceInstance(globalCustomerId, serviceType, serviceInstanceId); + + if (optional.isPresent()) { + LOGGER.info("Found service instance ..."); + final ServiceInstance serviceInstance = optional.get(); + final RelationshipList relationshipList = serviceInstance.getRelationshipList(); + + if (relationshipList != null) { + final List<Relationship> relationships = relationshipList.getRelationship(); + LOGGER.info("Relationships found {}", relationships); + return getGenericVnfIdsIfPresent(relationships); + } + LOGGER.warn("Relationship list is nulll ..."); + } + LOGGER.error("Unable to find generic-vnf relationships ... "); + return Collections.emptyList(); + } + + private List<String> getGenericVnfIdsIfPresent(final List<Relationship> relationships) { + final List<String> vnfIdsFound = new ArrayList<>(); + relationships.stream().forEach(relationship -> { + relationship.getRelationshipData().stream() + .filter(existing -> GENERIC_VNF_VNF_ID.equals(existing.getRelationshipKey())).findFirst() + .ifPresent(consume -> { + vnfIdsFound.add(consume.getRelationshipValue()); + }); + }); + return vnfIdsFound; } @Override diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java index c08c51ec..7da37794 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java @@ -361,6 +361,41 @@ public class BusinessControllerTest extends AbstractSpringBootTest { } @Test + public void test_putServiceInstanceRelatedTo_ableToRetrieveAllRelatedGenericVnfsFromCache() throws Exception { + + final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); + + invokeCustomerEndPointAndAssertResponse(); + + invokeServiceInstanceEndPointAndAssertResponse(); + + final String relationShipUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL, + BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); + + final ResponseEntity<Relationship> responseEntity2 = testRestTemplateService.invokeHttpPut(relationShipUrl, + TestUtils.getRelationShipJsonObject(), Relationship.class); + + assertEquals(HttpStatus.ACCEPTED, responseEntity2.getStatusCode()); + + final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); + final ResponseEntity<Void> genericVnfResponse = + testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class); + assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode()); + + final ResponseEntity<GenericVnfs> actual = + testRestTemplateService.invokeHttpGet(url + RELATED_TO_URL, GenericVnfs.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + + assertTrue(actual.hasBody()); + final GenericVnfs genericVnfs = actual.getBody(); + assertFalse(genericVnfs.getGenericVnf().isEmpty()); + final GenericVnf genericVnf = genericVnfs.getGenericVnf().get(0); + assertEquals(GENERIC_VNF_NAME, genericVnf.getVnfName()); + } + + + @Test public void test_DeleteSericeInstance_ServiceInstanceRemovedFromCache() throws Exception { final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); diff --git a/plans/so/integration-etsi-testing/so-simulators/package/docker/src/main/docker/docker-files/Dockerfile.so-simulator-base-image b/plans/so/integration-etsi-testing/so-simulators/package/docker/src/main/docker/docker-files/Dockerfile.so-simulator-base-image index efd7833f..f227c63f 100644 --- a/plans/so/integration-etsi-testing/so-simulators/package/docker/src/main/docker/docker-files/Dockerfile.so-simulator-base-image +++ b/plans/so/integration-etsi-testing/so-simulators/package/docker/src/main/docker/docker-files/Dockerfile.so-simulator-base-image @@ -8,7 +8,8 @@ ENV http_proxy=$HTTP_PROXY ENV https_proxy=$HTTPS_PROXY # Update the package list and upgrade installed packages -RUN apk update && apk upgrade +USER root +RUN apk update # Install commonly needed tools RUN apk --no-cache add curl netcat-openbsd sudo nss @@ -24,6 +25,8 @@ COPY scripts/start-app.sh /app RUN chown -R so:so /app && chmod 700 /app/*.sh +USER so + # Springboot configuration (required) VOLUME /app/config diff --git a/plans/so/integration-etsi-testing/so-simulators/package/docker/src/main/docker/docker-files/Dockerfile.workaround-job-container b/plans/so/integration-etsi-testing/so-simulators/package/docker/src/main/docker/docker-files/Dockerfile.workaround-job-container index faf8492c..795a015e 100644 --- a/plans/so/integration-etsi-testing/so-simulators/package/docker/src/main/docker/docker-files/Dockerfile.workaround-job-container +++ b/plans/so/integration-etsi-testing/so-simulators/package/docker/src/main/docker/docker-files/Dockerfile.workaround-job-container @@ -22,6 +22,7 @@ FROM docker.io/alpine # Install packages -RUN apk update && apk upgrade && apk add mysql-client && apk add bash +USER root +RUN apk upgrade && apk add mysql-client -RUN apk --no-cache add curl netcat-openbsd sudo nss +RUN apk --no-cache add bash curl netcat-openbsd sudo nss diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/pom.xml b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/pom.xml index 27e7c3ea..e694fef1 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/pom.xml +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/pom.xml @@ -10,6 +10,11 @@ <name>${project.artifactId}</name> <dependencies> <dependency> + <groupId>${project.parent.groupId}</groupId> + <artifactId>common</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> <exclusions> diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/configration/WebSecurityConfigImpl.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/configration/WebSecurityConfigImpl.java index b2c51369..a8ede989 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/configration/WebSecurityConfigImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/configration/WebSecurityConfigImpl.java @@ -20,15 +20,12 @@ package org.onap.so.sdcsimulator.configration; import org.onap.so.sdcsimulator.utils.Constants; +import org.onap.so.simulator.configuration.SimulatorSecurityConfigurer; +import org.onap.so.simulator.model.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; /** * @author waqas.ikram@ericsson.com @@ -36,18 +33,12 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; */ @Configuration @EnableWebSecurity -public class WebSecurityConfigImpl extends WebSecurityConfigurerAdapter { +public class WebSecurityConfigImpl extends SimulatorSecurityConfigurer { - private final String username; - private final String password; - private final String role; - public WebSecurityConfigImpl(@Value("${spring.security.username}") final String username, - @Value("${spring.security.password}") final String password, - @Value("${spring.security.role}") final String role) { - this.username = username; - this.password = password; - this.role = role; + @Autowired + public WebSecurityConfigImpl(final UserCredentials userCredentials) { + super(userCredentials.getUsers()); } @@ -57,15 +48,5 @@ public class WebSecurityConfigImpl extends WebSecurityConfigurerAdapter { .httpBasic(); } - @Bean - public BCryptPasswordEncoder passwordEncoder() { - return new BCryptPasswordEncoder(); - } - - @Autowired - public void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception { - auth.inMemoryAuthentication().passwordEncoder(passwordEncoder()).withUser(username).password(password) - .roles(role); - } } diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/CatalogController.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/CatalogController.java index 60c1865d..eebc08c6 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/CatalogController.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/CatalogController.java @@ -22,7 +22,9 @@ package org.onap.so.sdcsimulator.controller; import static org.onap.so.sdcsimulator.utils.Constants.CATALOG_URL; import java.util.Optional; import javax.ws.rs.core.MediaType; -import org.onap.so.sdcsimulator.providers.ResourceProvider; +import org.onap.so.sdcsimulator.models.AssetType; +import org.onap.so.sdcsimulator.models.Metadata; +import org.onap.so.sdcsimulator.providers.AssetProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -42,17 +44,23 @@ import org.springframework.web.bind.annotation.RequestMapping; public class CatalogController { private static final Logger LOGGER = LoggerFactory.getLogger(CatalogController.class); - private ResourceProvider resourceProvider; + private final AssetProvider assetProvider; @Autowired - public CatalogController(final ResourceProvider resourceProvider) { - this.resourceProvider = resourceProvider; + public CatalogController(final AssetProvider assetProvider) { + this.assetProvider = assetProvider; + } + + @GetMapping(value = "/resources", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> getResources() { + LOGGER.info("Running getResources ..."); + return ResponseEntity.ok().body(assetProvider.getAssetInfo(AssetType.RESOURCES)); } @GetMapping(value = "/resources/{csarId}/toscaModel", produces = MediaType.APPLICATION_OCTET_STREAM) - public ResponseEntity<byte[]> getCsar(@PathVariable("csarId") final String csarId) { + public ResponseEntity<byte[]> getResourceCsar(@PathVariable("csarId") final String csarId) { LOGGER.info("Running getCsar for {} ...", csarId); - final Optional<byte[]> resource = resourceProvider.getResource(csarId); + final Optional<byte[]> resource = assetProvider.getAsset(csarId, AssetType.RESOURCES); if (resource.isPresent()) { return new ResponseEntity<>(resource.get(), HttpStatus.OK); } @@ -61,4 +69,51 @@ public class CatalogController { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } + @GetMapping(value = "/resources/{csarId}/metadata", + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<Metadata> getResourceMetadata(@PathVariable("csarId") final String csarId) { + LOGGER.info("Running getResourceMetadata for {} ...", csarId); + final Optional<Metadata> resource = assetProvider.getMetadata(csarId, AssetType.RESOURCES); + if (resource.isPresent()) { + return new ResponseEntity<>(resource.get(), HttpStatus.OK); + } + LOGGER.error("Unable to find metadata for csarId: {}", csarId); + + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + + + @GetMapping(value = "/services", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> getServices() { + LOGGER.info("Running getServices ..."); + return ResponseEntity.ok().body(assetProvider.getAssetInfo(AssetType.SERVICES)); + } + + @GetMapping(value = "/services/{csarId}/toscaModel", produces = MediaType.APPLICATION_OCTET_STREAM) + public ResponseEntity<byte[]> getServiceCsar(@PathVariable("csarId") final String csarId) { + LOGGER.info("Running getServiceCsar for {} ...", csarId); + final Optional<byte[]> resource = assetProvider.getAsset(csarId, AssetType.SERVICES); + if (resource.isPresent()) { + return new ResponseEntity<>(resource.get(), HttpStatus.OK); + } + LOGGER.error("Unable to find csar: {}", csarId); + + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + + + @GetMapping(value = "/services/{csarId}/metadata", + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<Metadata> getServiceMetadata(@PathVariable("csarId") final String csarId) { + LOGGER.info("Running getServiceMetadata for {} ...", csarId); + final Optional<Metadata> resource = assetProvider.getMetadata(csarId, AssetType.SERVICES); + if (resource.isPresent()) { + return new ResponseEntity<>(resource.get(), HttpStatus.OK); + } + LOGGER.error("Unable to find metadata for csarId: {}", csarId); + + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + + } diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/Artifact.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/Artifact.java new file mode 100644 index 00000000..51bd18b1 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/Artifact.java @@ -0,0 +1,234 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.sdcsimulator.models; + +import java.io.Serializable; +import org.springframework.util.ObjectUtils; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class Artifact implements Serializable { + + private static final long serialVersionUID = 4106531921550274666L; + + @JsonProperty("artifactName") + private String artifactName; + + @JsonProperty("artifactType") + private String artifactType; + + @JsonProperty("artifactURL") + private String artifactUrl; + + @JsonProperty("artifactDescription") + private String artifactDescription; + + @JsonProperty("artifactChecksum") + private String artifactChecksum; + + @JsonProperty("artifactUUID") + private String artifactUuid; + + @JsonProperty("artifactVersion") + private String artifactVersion; + + @JsonProperty("artifactLabel") + private String artifactLabel; + + @JsonProperty("artifactGroupType") + private String artifactGroupType; + + public String getArtifactName() { + return artifactName; + } + + public void setArtifactName(final String artifactName) { + this.artifactName = artifactName; + } + + public Artifact artifactName(final String artifactName) { + this.artifactName = artifactName; + return this; + } + + public String getArtifactType() { + return artifactType; + } + + public void setArtifactType(final String artifactType) { + this.artifactType = artifactType; + } + + public Artifact artifactType(final String artifactType) { + this.artifactType = artifactType; + return this; + } + + public String getArtifactUrl() { + return artifactUrl; + } + + public void setArtifactUrl(final String artifactUrl) { + this.artifactUrl = artifactUrl; + } + + public Artifact artifactUrl(final String artifactURL) { + this.artifactUrl = artifactURL; + return this; + } + + public String getArtifactDescription() { + return artifactDescription; + } + + public void setArtifactDescription(final String artifactDescription) { + this.artifactDescription = artifactDescription; + } + + public Artifact artifactDescription(final String artifactDescription) { + this.artifactDescription = artifactDescription; + return this; + } + + public String getArtifactChecksum() { + return artifactChecksum; + } + + public void setArtifactChecksum(final String artifactChecksum) { + this.artifactChecksum = artifactChecksum; + } + + public Artifact artifactChecksum(final String artifactChecksum) { + this.artifactChecksum = artifactChecksum; + return this; + } + + public String getArtifactUuid() { + return artifactUuid; + } + + public void setArtifactUuid(final String artifactUuid) { + this.artifactUuid = artifactUuid; + } + + public Artifact artifactUuid(final String artifactUuid) { + this.artifactUuid = artifactUuid; + return this; + } + + public String getArtifactVersion() { + return artifactVersion; + } + + public void setArtifactVersion(final String artifactVersion) { + this.artifactVersion = artifactVersion; + } + + public Artifact artifactVersion(final String artifactVersion) { + this.artifactVersion = artifactVersion; + return this; + } + + public String getArtifactLabel() { + return artifactLabel; + } + + public void setArtifactLabel(final String artifactLabel) { + this.artifactLabel = artifactLabel; + } + + public Artifact artifactLabel(final String artifactLabel) { + this.artifactLabel = artifactLabel; + return this; + } + + public String getArtifactGroupType() { + return artifactGroupType; + } + + public void setArtifactGroupType(final String artifactGroupType) { + this.artifactGroupType = artifactGroupType; + } + + public Artifact artifactGroupType(final String artifactGroupType) { + this.artifactGroupType = artifactGroupType; + return this; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((artifactChecksum == null) ? 0 : artifactChecksum.hashCode()); + result = prime * result + ((artifactDescription == null) ? 0 : artifactDescription.hashCode()); + result = prime * result + ((artifactGroupType == null) ? 0 : artifactGroupType.hashCode()); + result = prime * result + ((artifactLabel == null) ? 0 : artifactLabel.hashCode()); + result = prime * result + ((artifactName == null) ? 0 : artifactName.hashCode()); + result = prime * result + ((artifactType == null) ? 0 : artifactType.hashCode()); + result = prime * result + ((artifactUrl == null) ? 0 : artifactUrl.hashCode()); + result = prime * result + ((artifactUuid == null) ? 0 : artifactUuid.hashCode()); + result = prime * result + ((artifactVersion == null) ? 0 : artifactVersion.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof AssetInfo) { + final Artifact other = (Artifact) obj; + return ObjectUtils.nullSafeEquals(artifactChecksum, other.artifactChecksum) + && ObjectUtils.nullSafeEquals(artifactDescription, other.artifactDescription) + && ObjectUtils.nullSafeEquals(artifactGroupType, other.artifactGroupType) + && ObjectUtils.nullSafeEquals(artifactLabel, other.artifactLabel) + && ObjectUtils.nullSafeEquals(artifactGroupType, other.artifactGroupType) + && ObjectUtils.nullSafeEquals(artifactName, other.artifactName) + && ObjectUtils.nullSafeEquals(artifactType, other.artifactType) + && ObjectUtils.nullSafeEquals(artifactUrl, other.artifactUrl) + && ObjectUtils.nullSafeEquals(artifactUuid, other.artifactUuid) + && ObjectUtils.nullSafeEquals(artifactVersion, other.artifactVersion); + + + } + return false; + + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class Artifact {\n"); + sb.append(" artifactName: ").append(artifactName).append("\n"); + sb.append(" artifactType: ").append(artifactType).append("\n"); + sb.append(" artifactURL: ").append(artifactUrl).append("\n"); + sb.append(" artifactDescription: ").append(artifactDescription).append("\n"); + sb.append(" artifactChecksum: ").append(artifactChecksum).append("\n"); + sb.append(" artifactUUID: ").append(artifactUuid).append("\n"); + sb.append(" artifactVersion: ").append(artifactVersion).append("\n"); + sb.append(" artifactLabel: ").append(artifactLabel).append("\n"); + sb.append(" artifactGroupType: ").append(artifactGroupType).append("\n"); + + sb.append("}"); + return sb.toString(); + + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/AssetInfo.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/AssetInfo.java new file mode 100644 index 00000000..17bcdda8 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/AssetInfo.java @@ -0,0 +1,248 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.sdcsimulator.models; + +import java.io.Serializable; +import org.springframework.util.ObjectUtils; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class AssetInfo implements Serializable { + + private static final long serialVersionUID = 3967660000071162759L; + + @JsonProperty("uuid") + private String uuid; + + @JsonProperty("invariantUUID") + private String invariantUuid; + + @JsonProperty("name") + private String name; + + @JsonProperty("version") + private String version; + + @JsonProperty("toscaModelURL") + private String toscaModelUrl; + + @JsonProperty("category") + private String category; + + @JsonProperty("resourceType") + private String resourceType; + + @JsonProperty("lifecycleState") + private String lifecycleState; + + @JsonProperty("lastUpdaterUserId") + private String lastUpdaterUserId; + + @JsonProperty("toscaResourceName") + private String toscaResourceName; + + public String getUuid() { + return uuid; + } + + public void setUuid(final String uuid) { + this.uuid = uuid; + } + + public AssetInfo uuid(final String uuid) { + this.uuid = uuid; + return this; + } + + public String getInvariantUuid() { + return invariantUuid; + } + + public void setInvariantUuid(final String invariantUuid) { + this.invariantUuid = invariantUuid; + } + + public AssetInfo invariantUuid(final String invariantUuid) { + this.invariantUuid = invariantUuid; + return this; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public AssetInfo name(final String name) { + this.name = name; + return this; + } + + public String getVersion() { + return version; + } + + public void setVersion(final String version) { + this.version = version; + } + + public AssetInfo version(final String version) { + this.version = version; + return this; + } + + public String getToscaModelUrl() { + return toscaModelUrl; + } + + public void setToscaModelUrl(final String toscaModelUrl) { + this.toscaModelUrl = toscaModelUrl; + } + + public AssetInfo toscaModelUrl(final String toscaModelUrl) { + this.toscaModelUrl = toscaModelUrl; + return this; + } + + public String getCategory() { + return category; + } + + public void setCategory(final String category) { + this.category = category; + } + + public AssetInfo category(final String category) { + this.category = category; + return this; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(final String resourceType) { + this.resourceType = resourceType; + } + + public AssetInfo resourceType(final String resourceType) { + this.resourceType = resourceType; + return this; + } + + public String getLifecycleState() { + return lifecycleState; + } + + public void setLifecycleState(final String lifecycleState) { + this.lifecycleState = lifecycleState; + } + + public AssetInfo lifecycleState(final String lifecycleState) { + this.lifecycleState = lifecycleState; + return this; + } + + public String getLastUpdaterUserId() { + return lastUpdaterUserId; + } + + public void setLastUpdaterUserId(final String lastUpdaterUserId) { + this.lastUpdaterUserId = lastUpdaterUserId; + } + + public AssetInfo lastUpdaterUserId(final String lastUpdaterUserId) { + this.lastUpdaterUserId = lastUpdaterUserId; + return this; + } + + public String getToscaResourceName() { + return toscaResourceName; + } + + public void setToscaResourceName(final String toscaResourceName) { + this.toscaResourceName = toscaResourceName; + } + + public AssetInfo toscaResourceName(final String toscaResourceName) { + this.toscaResourceName = toscaResourceName; + return this; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((category == null) ? 0 : category.hashCode()); + result = prime * result + ((invariantUuid == null) ? 0 : invariantUuid.hashCode()); + result = prime * result + ((lastUpdaterUserId == null) ? 0 : lastUpdaterUserId.hashCode()); + result = prime * result + ((lifecycleState == null) ? 0 : lifecycleState.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode()); + result = prime * result + ((toscaModelUrl == null) ? 0 : toscaModelUrl.hashCode()); + result = prime * result + ((uuid == null) ? 0 : uuid.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + + return result; + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof AssetInfo) { + final AssetInfo other = (AssetInfo) obj; + return ObjectUtils.nullSafeEquals(category, other.category) + && ObjectUtils.nullSafeEquals(invariantUuid, other.invariantUuid) + && ObjectUtils.nullSafeEquals(lastUpdaterUserId, other.lastUpdaterUserId) + && ObjectUtils.nullSafeEquals(lifecycleState, other.lifecycleState) + && ObjectUtils.nullSafeEquals(name, other.name) + && ObjectUtils.nullSafeEquals(resourceType, other.resourceType) + && ObjectUtils.nullSafeEquals(toscaModelUrl, other.toscaModelUrl) + && ObjectUtils.nullSafeEquals(uuid, other.uuid) + && ObjectUtils.nullSafeEquals(version, other.version); + + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class "); + sb.append(this.getClass().getName()); + sb.append(" {\n"); + sb.append(" uuid: ").append(uuid).append("\n"); + sb.append(" invariantUuid: ").append(invariantUuid).append("\n"); + sb.append(" name: ").append(name).append("\n"); + sb.append(" version: ").append(version).append("\n"); + sb.append(" toscaModelUrl: ").append(toscaModelUrl).append("\n"); + sb.append(" category: ").append(category).append("\n"); + sb.append(" lifecycleState: ").append(lifecycleState).append("\n"); + sb.append(" lastUpdaterUserId: ").append(lastUpdaterUserId).append("\n"); + + sb.append("}"); + return sb.toString(); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/AssetType.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/AssetType.java new file mode 100644 index 00000000..a86e0630 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/AssetType.java @@ -0,0 +1,114 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.sdcsimulator.models; + +import static org.onap.so.sdcsimulator.utils.Constants.CATALOG_URL; +import static org.onap.so.sdcsimulator.utils.Constants.FORWARD_SLASH; +import java.io.File; +import java.io.IOException; +import org.springframework.core.io.Resource; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public enum AssetType { + + RESOURCES { + @Override + public AssetInfo getAssetInfo(final Resource resource) throws IOException { + return OBJ_MAPPER.readValue(resource.getInputStream(), ResourceAssetInfo.class); + } + + @Override + public AssetInfo getAssetInfo(final File file) throws IOException { + return OBJ_MAPPER.readValue(file, ResourceAssetInfo.class); + } + + @Override + public Metadata getMetadata(final Resource resource) throws IOException { + return OBJ_MAPPER.readValue(resource.getInputStream(), ResourceMetadata.class); + } + + @Override + public Metadata getMetadata(final File file) throws IOException { + return OBJ_MAPPER.readValue(file, ResourceMetadata.class); + } + + }, + SERVICES { + @Override + public AssetInfo getAssetInfo(final Resource resource) throws IOException { + return OBJ_MAPPER.readValue(resource.getInputStream(), ServiceAssetInfo.class); + } + + @Override + public AssetInfo getAssetInfo(final File file) throws IOException { + return OBJ_MAPPER.readValue(file, ServiceAssetInfo.class); + } + + @Override + public Metadata getMetadata(final Resource resource) throws IOException { + return OBJ_MAPPER.readValue(resource.getInputStream(), ServiceMetadata.class); + } + + @Override + public Metadata getMetadata(final File file) throws IOException { + return OBJ_MAPPER.readValue(file, ServiceMetadata.class); + } + + }; + + private static final ObjectMapper OBJ_MAPPER = + new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + + public abstract AssetInfo getAssetInfo(final Resource resource) throws IOException; + + public abstract AssetInfo getAssetInfo(final File file) throws IOException; + + public abstract Metadata getMetadata(final Resource resource) throws IOException; + + public abstract Metadata getMetadata(final File file) throws IOException; + + public String getToscaModelUrl(final String filename) { + return CATALOG_URL + FORWARD_SLASH + this.toString().toLowerCase() + FORWARD_SLASH + filename + "/toscaModel"; + } + + public AssetInfo getDefaultAssetInfo(final String filename) { + AssetInfo defaultValue = null; + + if (this.equals(RESOURCES)) { + defaultValue = new ResourceAssetInfo().subCategory("Network Service"); + } else if (this.equals(SERVICES)) { + defaultValue = new ServiceAssetInfo().distributionStatus("DISTRIBUTED"); + } else { + defaultValue = new AssetInfo(); + } + + return defaultValue.uuid(filename).invariantUuid(filename).name(filename).version("1.0") + .toscaModelUrl(getToscaModelUrl(filename)).category("Generic").lifecycleState("CERTIFIED") + .lastUpdaterUserId("SDC_SIMULATOR"); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/Metadata.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/Metadata.java new file mode 100644 index 00000000..4836fc16 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/Metadata.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.sdcsimulator.models; + +import java.util.HashSet; +import java.util.Set; +import org.springframework.util.ObjectUtils; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class Metadata extends AssetInfo { + + private static final long serialVersionUID = 2754071491333890698L; + + @JsonProperty("resources") + private Set<Resource> resources = new HashSet<>(); + + @JsonProperty("artifacts") + private Set<Artifact> artifacts = new HashSet<>(); + + + public Set<Resource> getResources() { + return resources; + } + + public void setResources(final Set<Resource> resources) { + this.resources = resources; + } + + public Metadata resources(final Set<Resource> resources) { + this.resources = resources; + return this; + } + + public Set<Artifact> getArtifacts() { + return artifacts; + } + + public void setArtifacts(final Set<Artifact> artifacts) { + this.artifacts = artifacts; + } + + public Metadata artifacts(Set<Artifact> artifacts) { + this.artifacts = artifacts; + return this; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + super.hashCode(); + result = prime * result + ((resources == null) ? 0 : resources.hashCode()); + result = prime * result + ((artifacts == null) ? 0 : artifacts.hashCode()); + + return result; + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof Metadata) { + final Metadata other = (Metadata) obj; + return super.equals(obj) && ObjectUtils.nullSafeEquals(resources, other.resources) + && ObjectUtils.nullSafeEquals(artifacts, other.artifacts); + + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append(super.toString()); + sb.deleteCharAt(sb.length() - 1); + sb.append(" resources: ").append(resources).append("\n"); + sb.append(" artifacts: ").append(artifacts).append("\n"); + + sb.append("}"); + return sb.toString(); + } + + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/Resource.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/Resource.java new file mode 100644 index 00000000..6eb3734b --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/Resource.java @@ -0,0 +1,198 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.sdcsimulator.models; + +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; +import org.springframework.util.ObjectUtils; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class Resource implements Serializable { + + private static final long serialVersionUID = -8014206400770867160L; + + @JsonProperty("resourceInstanceName") + private String resourceInstanceName; + + @JsonProperty("resourceName") + private String resourceName; + + @JsonProperty("resourceInvariantUUID") + private String resourceInvariantUuid; + + @JsonProperty("resourceVersion") + private String resourceVersion; + + @JsonProperty("resoucreType") + private String resourceType; + + @JsonProperty("resourceUUID") + private String resourceUuid; + + @JsonProperty("artifacts") + private Set<Artifact> artifacts = new HashSet<>(); + + public String getResourceInstanceName() { + return resourceInstanceName; + } + + public void setResourceInstanceName(final String resourceInstanceName) { + this.resourceInstanceName = resourceInstanceName; + } + + public Resource resourceInstanceName(final String resourceInstanceName) { + this.resourceInstanceName = resourceInstanceName; + return this; + } + + public String getResourceName() { + return resourceName; + } + + public void setResourceName(final String resourceName) { + this.resourceName = resourceName; + } + + public Resource resourceName(final String resourceName) { + this.resourceName = resourceName; + return this; + } + + public String getResourceInvariantUuid() { + return resourceInvariantUuid; + } + + public void setResourceInvariantUuid(final String resourceInvariantUuid) { + this.resourceInvariantUuid = resourceInvariantUuid; + } + + public Resource resourceInvariantUuid(final String resourceInvariantUuid) { + this.resourceInvariantUuid = resourceInvariantUuid; + return this; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public void setResourceVersion(final String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + public Resource resourceVersion(final String resourceVersion) { + this.resourceVersion = resourceVersion; + return this; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(final String resourceType) { + this.resourceType = resourceType; + } + + public Resource resourceType(final String resourceType) { + this.resourceType = resourceType; + return this; + } + + public String getResourceUuid() { + return resourceUuid; + } + + public void setResourceUuid(final String resourceUuid) { + this.resourceUuid = resourceUuid; + } + + public Resource resourceUUID(final String resourceUuid) { + this.resourceUuid = resourceUuid; + return this; + } + + public Set<Artifact> getArtifacts() { + return artifacts; + } + + public void setArtifacts(final Set<Artifact> artifacts) { + this.artifacts = artifacts; + } + + public Resource artifacts(final Set<Artifact> artifacts) { + this.artifacts = artifacts; + return this; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((artifacts == null) ? 0 : artifacts.hashCode()); + result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode()); + result = prime * result + ((resourceInstanceName == null) ? 0 : resourceInstanceName.hashCode()); + result = prime * result + ((resourceInvariantUuid == null) ? 0 : resourceInvariantUuid.hashCode()); + result = prime * result + ((resourceName == null) ? 0 : resourceName.hashCode()); + result = prime * result + ((resourceUuid == null) ? 0 : resourceUuid.hashCode()); + result = prime * result + ((resourceVersion == null) ? 0 : resourceVersion.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof Resource) { + final Resource other = (Resource) obj; + return ObjectUtils.nullSafeEquals(resourceInstanceName, other.resourceInstanceName) + && ObjectUtils.nullSafeEquals(resourceName, other.resourceName) + && ObjectUtils.nullSafeEquals(resourceInvariantUuid, other.resourceInvariantUuid) + && ObjectUtils.nullSafeEquals(resourceVersion, other.resourceVersion) + && ObjectUtils.nullSafeEquals(resourceType, other.resourceType) + && ObjectUtils.nullSafeEquals(resourceUuid, other.resourceUuid) + && ObjectUtils.nullSafeEquals(artifacts, other.artifacts); + } + return false; + + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class Resource {\n"); + sb.append(" resourceInstanceName: ").append(resourceInstanceName).append("\n"); + sb.append(" resourceName: ").append(resourceName).append("\n"); + sb.append(" resourceInvariantUuid: ").append(resourceInvariantUuid).append("\n"); + sb.append(" resourceVersion: ").append(resourceVersion).append("\n"); + sb.append(" resourceType: ").append(resourceType).append("\n"); + sb.append(" resourceUuid: ").append(resourceUuid).append("\n"); + sb.append(" artifacts: ").append(artifacts).append("\n"); + + sb.append("}"); + return sb.toString(); + + } + + + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ResourceAssetInfo.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ResourceAssetInfo.java new file mode 100644 index 00000000..352070a7 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ResourceAssetInfo.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.sdcsimulator.models; + +import org.springframework.util.ObjectUtils; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class ResourceAssetInfo extends AssetInfo { + + private static final long serialVersionUID = -6812049917047990700L; + + @JsonProperty("subCategory") + private String subCategory; + + public String getSubCategory() { + return subCategory; + } + + public void setSubCategory(final String subCategory) { + this.subCategory = subCategory; + } + + public ResourceAssetInfo subCategory(final String subCategory) { + this.subCategory = subCategory; + return this; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + super.hashCode(); + result = prime * result + ((subCategory == null) ? 0 : subCategory.hashCode()); + + return result; + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof ResourceAssetInfo) { + final ResourceAssetInfo other = (ResourceAssetInfo) obj; + return super.equals(obj) && ObjectUtils.nullSafeEquals(subCategory, other.subCategory); + + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append(super.toString()); + sb.deleteCharAt(sb.length() - 1); + sb.append(" subCategory: ").append(subCategory).append("\n"); + + sb.append("}"); + return sb.toString(); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ResourceMetadata.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ResourceMetadata.java new file mode 100644 index 00000000..9ff02c43 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ResourceMetadata.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.sdcsimulator.models; + +import java.io.Serializable; +import org.springframework.util.ObjectUtils; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class ResourceMetadata extends Metadata implements Serializable { + + private static final long serialVersionUID = -6812049917047990700L; + + @JsonProperty("subCategory") + private String subCategory; + + public String getSubCategory() { + return subCategory; + } + + public void setSubCategory(final String subCategory) { + this.subCategory = subCategory; + } + + public ResourceMetadata subCategory(final String subCategory) { + this.subCategory = subCategory; + return this; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + super.hashCode(); + result = prime * result + ((subCategory == null) ? 0 : subCategory.hashCode()); + + return result; + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof ResourceMetadata) { + final ResourceMetadata other = (ResourceMetadata) obj; + return super.equals(obj) && ObjectUtils.nullSafeEquals(subCategory, other.subCategory); + + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append(super.toString()); + sb.deleteCharAt(sb.length() - 1); + sb.append(" subCategory: ").append(subCategory).append("\n"); + + sb.append("}"); + return sb.toString(); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ServiceAssetInfo.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ServiceAssetInfo.java new file mode 100644 index 00000000..f1fa2bc9 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ServiceAssetInfo.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.sdcsimulator.models; + +import org.springframework.util.ObjectUtils; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class ServiceAssetInfo extends AssetInfo { + + private static final long serialVersionUID = 1487426510731947767L; + + @JsonProperty("distributionStatus") + private String distributionStatus; + + public String getDistributionStatus() { + return distributionStatus; + } + + public void setDistributionStatus(final String distributionStatus) { + this.distributionStatus = distributionStatus; + } + + public ServiceAssetInfo distributionStatus(final String distributionStatus) { + this.distributionStatus = distributionStatus; + return this; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + super.hashCode(); + result = prime * result + ((distributionStatus == null) ? 0 : distributionStatus.hashCode()); + + return result; + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof ServiceAssetInfo) { + final ServiceAssetInfo other = (ServiceAssetInfo) obj; + return super.equals(obj) && ObjectUtils.nullSafeEquals(distributionStatus, other.distributionStatus); + + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append(super.toString()); + sb.deleteCharAt(sb.length() - 1); + sb.append(" distributionStatus: ").append(distributionStatus).append("\n"); + + sb.append("}"); + return sb.toString(); + } + + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ServiceMetadata.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ServiceMetadata.java new file mode 100644 index 00000000..5a2a8ade --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/models/ServiceMetadata.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.sdcsimulator.models; + +import java.io.Serializable; +import org.springframework.util.ObjectUtils; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class ServiceMetadata extends Metadata implements Serializable { + + private static final long serialVersionUID = -5677805295913361365L; + @JsonProperty("distributionStatus") + private String distributionStatus; + + public String getDistributionStatus() { + return distributionStatus; + } + + public void setDistributionStatus(final String distributionStatus) { + this.distributionStatus = distributionStatus; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + super.hashCode(); + result = prime * result + ((distributionStatus == null) ? 0 : distributionStatus.hashCode()); + + return result; + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof ServiceMetadata) { + final ServiceMetadata other = (ServiceMetadata) obj; + return super.equals(obj) && ObjectUtils.nullSafeEquals(distributionStatus, other.distributionStatus); + + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append(super.toString()); + sb.deleteCharAt(sb.length() - 1); + sb.append(" distributionStatus: ").append(distributionStatus).append("\n"); + + sb.append("}"); + return sb.toString(); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/ResourceProvider.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/AssetProvider.java index 4d5dcdd0..3ea077d4 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/ResourceProvider.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/AssetProvider.java @@ -20,17 +20,23 @@ package org.onap.so.sdcsimulator.providers; -import java.io.IOException; -import java.io.InputStream; import java.util.Optional; +import java.util.Set; +import org.onap.so.sdcsimulator.models.AssetInfo; +import org.onap.so.sdcsimulator.models.AssetType; +import org.onap.so.sdcsimulator.models.Metadata; /** * @author Eoin Hanan (eoin.hanan@est.tech) + * @author Waqas Ikram (waqas.ikram@est.tech) + * */ -public interface ResourceProvider { +public interface AssetProvider { - Optional<byte[]> getResource(final String csarId); + Optional<byte[]> getAsset(final String csarId, final AssetType assetType); - Optional<InputStream> getInputStream(final String csarId) throws IOException; + Set<AssetInfo> getAssetInfo(final AssetType assetType); + + Optional<Metadata> getMetadata(final String csarId, final AssetType assetType); } diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/AssetProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/AssetProviderImpl.java new file mode 100644 index 00000000..8996d249 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/AssetProviderImpl.java @@ -0,0 +1,216 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.sdcsimulator.providers; + +import static org.onap.so.sdcsimulator.utils.Constants.DOT_CSAR; +import static org.onap.so.sdcsimulator.utils.Constants.DOT_JSON; +import static org.onap.so.sdcsimulator.utils.Constants.FORWARD_SLASH; +import static org.onap.so.sdcsimulator.utils.Constants.MAIN_RESOURCE_FOLDER; +import static org.onap.so.sdcsimulator.utils.Constants.WILD_CARD_REGEX; +import static org.springframework.core.io.support.ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; +import org.onap.so.sdcsimulator.models.AssetInfo; +import org.onap.so.sdcsimulator.models.AssetType; +import org.onap.so.sdcsimulator.models.Metadata; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.stereotype.Service; +import org.springframework.util.StreamUtils; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + */ +@Service +public class AssetProviderImpl implements AssetProvider { + + private static final Logger LOGGER = LoggerFactory.getLogger(AssetProvider.class); + + private final String resourceLocation; + + private final ResourcePatternResolver resourcePatternResolver; + + @Autowired + public AssetProviderImpl(@Value("${sdc.resource.location:/app/csars/}") final String resourceLocation, + final ResourcePatternResolver resourcePatternResolver) { + this.resourceLocation = resourceLocation; + this.resourcePatternResolver = resourcePatternResolver; + } + + @Override + public Optional<byte[]> getAsset(final String csarId, final AssetType assetType) { + try { + final Optional<InputStream> optionalInputStream = getInputStream(csarId, assetType); + if (optionalInputStream.isPresent()) { + return Optional.of(StreamUtils.copyToByteArray(optionalInputStream.get())); + } + } catch (final IOException ioException) { + LOGGER.warn("Unable to create file stream ...", ioException); + } + + return Optional.empty(); + } + + @Override + public Set<AssetInfo> getAssetInfo(final AssetType assetType) { + final Set<AssetInfo> result = new HashSet<>(); + + final Path dir = Paths.get(resourceLocation).resolve(assetType.toString()); + if (Files.exists(dir)) { + try (final DirectoryStream<Path> stream = Files.newDirectoryStream(dir, WILD_CARD_REGEX + DOT_CSAR)) { + for (final Path entry : stream) { + final String filename = getFilenameWithoutExtension(entry); + result.add(getAssetInfo(assetType, filename, entry)); + } + } catch (final IOException ioException) { + LOGGER.error("Unable to find assetInfo on filesystem", ioException); + } + } + + try { + final String classPathdir = MAIN_RESOURCE_FOLDER + assetType.toString() + FORWARD_SLASH; + final String csarFileLocationPattern = CLASSPATH_ALL_URL_PREFIX + classPathdir + WILD_CARD_REGEX + DOT_CSAR; + final Resource[] resources = resourcePatternResolver.getResources(csarFileLocationPattern); + if (resources != null) { + + for (final Resource resource : resources) { + final String filename = getFilenameWithoutExtension(resource.getFilename()); + result.add(getAssetInfo(assetType, filename, resource)); + } + } + + } catch (final IOException ioException) { + LOGGER.error("Unable to find assetInfo in classpath", ioException); + } + + return result; + } + + @Override + public Optional<Metadata> getMetadata(final String csarId, final AssetType assetType) { + final Path dir = Paths.get(resourceLocation).resolve(assetType.toString()); + final Path metadataFilePath = dir.resolve(csarId + DOT_JSON); + try { + if (Files.exists(metadataFilePath)) { + LOGGER.info("Found metadata file on file system using path: {}", metadataFilePath); + + return Optional.of(assetType.getMetadata(metadataFilePath.toFile())); + + } + } catch (final IOException ioException) { + LOGGER.error("Unable to find metadata file on filesystem", ioException); + } + + + try { + final String path = MAIN_RESOURCE_FOLDER + assetType.toString() + FORWARD_SLASH + csarId + DOT_JSON; + LOGGER.warn("Couldn't find metadata file on file system '{}', will search it in classpath", path); + final ClassPathResource classPathResource = getClassPathResource(path); + if (classPathResource.exists()) { + LOGGER.info("Found metadata file in classpath using path: {}", path); + return Optional.of(assetType.getMetadata(classPathResource)); + } + } catch (final IOException ioException) { + LOGGER.error("Unable to find metadata file in classpath", ioException); + } + LOGGER.error("Couldn't find metadata file in classpath ...."); + return Optional.empty(); + } + + private AssetInfo getAssetInfo(final AssetType assetType, final String filename, final Resource resource) + throws IOException { + final Resource jsonResource = resource.createRelative(filename + DOT_JSON); + + if (jsonResource != null && jsonResource.exists()) { + final AssetInfo assetInfo = assetType.getAssetInfo(jsonResource); + assetInfo.setUuid(filename); + assetInfo.setToscaModelUrl(assetType.getToscaModelUrl(filename)); + LOGGER.info("Found AssetInfo file in classpath: {}", assetInfo); + return assetInfo; + + } + + final AssetInfo assetInfo = assetType.getDefaultAssetInfo(filename); + LOGGER.info("Returning AssetInfo: {}", assetInfo); + return assetInfo; + + } + + private AssetInfo getAssetInfo(final AssetType assetType, final String filename, final Path entry) + throws IOException { + final Path assetJsonFilePath = entry.getParent().resolve(filename + DOT_JSON); + if (Files.exists(assetJsonFilePath)) { + final AssetInfo assetInfo = assetType.getAssetInfo(assetJsonFilePath.toFile()); + assetInfo.setUuid(filename); + assetInfo.setToscaModelUrl(assetType.getToscaModelUrl(filename)); + LOGGER.info("Found AssetInfo file on file system: {}", assetInfo); + return assetInfo; + + } + final AssetInfo assetInfo = assetType.getDefaultAssetInfo(filename); + LOGGER.info("Returning AssetInfo: {}", assetInfo); + return assetInfo; + } + + private String getFilenameWithoutExtension(final String filename) { + return filename.substring(0, filename.lastIndexOf('.')); + } + + private String getFilenameWithoutExtension(final Path file) { + return getFilenameWithoutExtension(file.getFileName().toString()); + } + + private Optional<InputStream> getInputStream(final String csarId, final AssetType assetType) throws IOException { + final Path filePath = Paths.get(resourceLocation, assetType.toString(), csarId + DOT_CSAR); + if (Files.exists(filePath)) { + LOGGER.info("Found csar on file system using path: {}", filePath); + return Optional.of(Files.newInputStream(filePath)); + } + LOGGER.warn("Couldn't find file on file system '{}', will search it in classpath", filePath); + + final String path = MAIN_RESOURCE_FOLDER + assetType.toString() + FORWARD_SLASH + csarId + DOT_CSAR; + final ClassPathResource classPathResource = getClassPathResource(path); + if (classPathResource.exists()) { + LOGGER.info("Found csar in classpath using path: {}", path); + return Optional.of(classPathResource.getInputStream()); + } + + LOGGER.error("Couldn't find csar in classpath ...."); + return Optional.empty(); + } + + private ClassPathResource getClassPathResource(final String path) { + return new ClassPathResource(path, this.getClass()); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/ResourceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/ResourceProviderImpl.java deleted file mode 100644 index 192ac896..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/ResourceProviderImpl.java +++ /dev/null @@ -1,88 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.sdcsimulator.providers; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Optional; -import org.onap.so.sdcsimulator.utils.Constants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.core.io.ClassPathResource; -import org.springframework.stereotype.Service; -import org.springframework.util.StreamUtils; - -/** - * @author Eoin Hanan (eoin.hanan@est.tech) - */ -@Service -public class ResourceProviderImpl implements ResourceProvider { - - private static final Logger LOGGER = LoggerFactory.getLogger(ResourceProvider.class); - - private final String resourceLocation; - - public ResourceProviderImpl(@Value("${sdc.resource.location:/app/csars/}") final String resourceLocation) { - this.resourceLocation = resourceLocation; - } - - @Override - public Optional<byte[]> getResource(final String csarId) { - try { - final Optional<InputStream> optionalInputStream = getInputStream(csarId); - if (optionalInputStream.isPresent()) { - return Optional.of(StreamUtils.copyToByteArray(optionalInputStream.get())); - } - } catch (final IOException ioException) { - LOGGER.warn("Unable to create file stream ...", ioException); - } - - return Optional.empty(); - } - - @Override - public Optional<InputStream> getInputStream(final String csarId) throws IOException { - final Path filePath = Paths.get(resourceLocation, csarId + ".csar"); - if (Files.exists(filePath)) { - return Optional.of(Files.newInputStream(filePath)); - } - - LOGGER.info("Couldn't find file on file system '{}', will return default csar", filePath); - final ClassPathResource classPathResource = new ClassPathResource(getDefaultCsarPath(), this.getClass()); - if (classPathResource.exists()) { - return Optional.of(classPathResource.getInputStream()); - } - - LOGGER.error("Couldn't find default csar in classpath ...."); - return Optional.empty(); - } - - /* - * Used in test - */ - String getDefaultCsarPath() { - return Constants.DEFAULT_CSAR_PATH; - } -}
\ No newline at end of file diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/utils/Constants.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/utils/Constants.java index e8412574..4822b4fc 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/utils/Constants.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/utils/Constants.java @@ -25,21 +25,23 @@ package org.onap.so.sdcsimulator.utils; */ public class Constants { + public static final String MAIN_RESOURCE_FOLDER = "/csar/"; + public static final String BASE_URL = "/sdc/v1"; public static final String CATALOG_URL = BASE_URL + "/catalog"; public static final String HEALTHY = "healthy"; - public static final String DEFAULT_CSAR_NAME = "default_csar_file"; - public static final String DOT = "."; + public static final String WILD_CARD_REGEX = "*"; + public static final String DOT_CSAR = DOT + "csar"; - public static final String DEFAULT_CSAR_NAME_WITH_EXT = DEFAULT_CSAR_NAME + DOT_CSAR; + public static final String DOT_JSON = DOT + "json"; - public static final String DEFAULT_CSAR_PATH = "/csar/" + DEFAULT_CSAR_NAME_WITH_EXT; + public static final String FORWARD_SLASH = "/"; private Constants() {} } diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/application.yaml b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/application.yaml index 5bb7950a..8ae1e8ac 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/application.yaml +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/application.yaml @@ -5,7 +5,12 @@ server: ssl-enable: false spring: security: - username: mso - #password: Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U - password: $2a$04$Lcu/DWdyXsl/a3A0iqHTfOX1.zHQ3DlQS/nOPfafT.9pWbeEqlF7W - role: mso
\ No newline at end of file + users: + - username: mso + #password: Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U + password: $2a$04$Lcu/DWdyXsl/a3A0iqHTfOX1.zHQ3DlQS/nOPfafT.9pWbeEqlF7W + role: mso + - username: modeling + #password: Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U + password: $2a$04$Lcu/DWdyXsl/a3A0iqHTfOX1.zHQ3DlQS/nOPfafT.9pWbeEqlF7W + role: mso
\ No newline at end of file diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/csar/RESOURCES/73522444-e8e9-49c1-be29-d355800aa349.csar b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/csar/RESOURCES/73522444-e8e9-49c1-be29-d355800aa349.csar Binary files differnew file mode 100644 index 00000000..db8f12d8 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/csar/RESOURCES/73522444-e8e9-49c1-be29-d355800aa349.csar diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/csar/RESOURCES/73522444-e8e9-49c1-be29-d355800aa349.json b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/csar/RESOURCES/73522444-e8e9-49c1-be29-d355800aa349.json new file mode 100644 index 00000000..1ca1e7d4 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/csar/RESOURCES/73522444-e8e9-49c1-be29-d355800aa349.json @@ -0,0 +1,116 @@ +{ + "uuid": "73522444-e8e9-49c1-be29-d355800aa349", + "invariantUUID": "037f7b1b-5c62-44c1-b806-f92fe8970171", + "name": "EtsiVnfCSIT3", + "version": "1.0", + "toscaModelURL": "/sdc/v1/catalog/resources/73522444-e8e9-49c1-be29-d355800aa349/toscaModel", + "category": "Generic", + "subCategory": "Network Service", + "resourceType": "VF", + "lifecycleState": "CERTIFIED", + "lastUpdaterUserId": "cs0008", + "lastUpdaterFullName": "Carlos Santana", + "toscaResourceName": "org.openecomp.resource.vf.Etsivnfcsit3", + "resources": [ + { + "resourceInstanceName": "Cp_vgw_mux_gw_private_net", + "resourceName": "VDU Cp", + "resourceInvariantUUID": "3e4b8692-e6b1-44e9-90b1-6c5f1abf469c", + "resourceVersion": "1.0", + "resoucreType": "CP", + "resourceUUID": "72b9cd47-e8b7-4033-bb1a-fa30e45e3233" + }, + { + "resourceInstanceName": "Cp_vgw_onap_private", + "resourceName": "VDU Cp", + "resourceInvariantUUID": "3e4b8692-e6b1-44e9-90b1-6c5f1abf469c", + "resourceVersion": "1.0", + "resoucreType": "CP", + "resourceUUID": "72b9cd47-e8b7-4033-bb1a-fa30e45e3233" + }, + { + "resourceInstanceName": "LLU_VNF", + "resourceName": "VNF", + "resourceInvariantUUID": "a85aa428-cdb6-4e96-b873-0c20bfd22cac", + "resourceVersion": "1.0", + "resoucreType": "VFC", + "resourceUUID": "bbe67a58-6fd6-4849-abdf-f6a73dbdd594" + }, + { + "resourceInstanceName": "VDU_vgw_0", + "resourceName": "VDU Compute", + "resourceInvariantUUID": "d211a1fd-ae0d-4b33-9076-76defafa7adc", + "resourceVersion": "1.0", + "resoucreType": "VFC", + "resourceUUID": "5dcd4cc9-2db5-49aa-a51a-a0eb4124df4c" + }, + { + "resourceInstanceName": "VL_mux_gw_private_net", + "resourceName": "VnfVirtualLink", + "resourceInvariantUUID": "a9351632-8045-4422-bda6-fdbf4c472b2b", + "resourceVersion": "1.0", + "resoucreType": "VL", + "resourceUUID": "22ba6824-e467-4f6a-87df-ccc8bee01fe4" + }, + { + "resourceInstanceName": "Cp_vgw_cpe_public", + "resourceName": "VDU Cp", + "resourceInvariantUUID": "3e4b8692-e6b1-44e9-90b1-6c5f1abf469c", + "resourceVersion": "1.0", + "resoucreType": "CP", + "resourceUUID": "72b9cd47-e8b7-4033-bb1a-fa30e45e3233" + }, + { + "resourceInstanceName": "Cp_vgw_public", + "resourceName": "VDU Cp", + "resourceInvariantUUID": "3e4b8692-e6b1-44e9-90b1-6c5f1abf469c", + "resourceVersion": "1.0", + "resoucreType": "CP", + "resourceUUID": "72b9cd47-e8b7-4033-bb1a-fa30e45e3233" + }, + { + "resourceInstanceName": "VL_cpe_public", + "resourceName": "VnfVirtualLink", + "resourceInvariantUUID": "a9351632-8045-4422-bda6-fdbf4c472b2b", + "resourceVersion": "1.0", + "resoucreType": "VL", + "resourceUUID": "22ba6824-e467-4f6a-87df-ccc8bee01fe4" + } + ], + "artifacts": [ + { + "artifactName": "vf-license-model.xml", + "artifactType": "VF_LICENSE", + "artifactURL": "/sdc/v1/catalog/resources/73522444-e8e9-49c1-be29-d355800aa349/artifacts/3e964c48-c539-41b6-b504-52905fbe1f93", + "artifactDescription": "VF license file", + "artifactChecksum": "MDAwOTQ0NWYzNzMzYjJmYjBlODc2ODUyY2MzOTIyMjQ=", + "artifactUUID": "3e964c48-c539-41b6-b504-52905fbe1f93", + "artifactVersion": "1", + "artifactLabel": "vflicense", + "artifactGroupType": "DEPLOYMENT" + }, + { + "artifactName": "vgw6.csar", + "artifactType": "ETSI_PACKAGE", + "artifactURL": "/sdc/v1/catalog/resources/73522444-e8e9-49c1-be29-d355800aa349/artifacts/0737049a-204d-4009-932a-57a48119f5eb", + "artifactDescription": "Artifact created from csar", + "artifactChecksum": "ZjAyYjhmYzJkY2ExZjMyYzk1ZjlmNjk0YzkzNDNhY2Y=", + "artifactUUID": "0737049a-204d-4009-932a-57a48119f5eb", + "artifactVersion": "1", + "artifactLabel": "vgw6csar", + "artifactGroupType": "DEPLOYMENT" + }, + { + "artifactName": "vendor-license-model.xml", + "artifactType": "VENDOR_LICENSE", + "artifactURL": "/sdc/v1/catalog/resources/73522444-e8e9-49c1-be29-d355800aa349/artifacts/f17c8eed-cf1f-44cd-a2b3-2caee9c34b17", + "artifactDescription": " Vendor license file", + "artifactChecksum": "NzY2ZGUzODNkNWEwNjM1MjRiMjNiNDY1ZWNkNWQyOTg=", + "artifactUUID": "f17c8eed-cf1f-44cd-a2b3-2caee9c34b17", + "artifactVersion": "1", + "artifactLabel": "vendorlicense", + "artifactGroupType": "DEPLOYMENT" + } + ], + "description": "test" +}
\ No newline at end of file diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/csar/SERVICES/9bb8c882-44a1-4b67-a12c-5a998e18d6ba.csar b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/csar/SERVICES/9bb8c882-44a1-4b67-a12c-5a998e18d6ba.csar Binary files differnew file mode 100644 index 00000000..6504cb1a --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/csar/SERVICES/9bb8c882-44a1-4b67-a12c-5a998e18d6ba.csar diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/csar/SERVICES/9bb8c882-44a1-4b67-a12c-5a998e18d6ba.json b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/csar/SERVICES/9bb8c882-44a1-4b67-a12c-5a998e18d6ba.json new file mode 100644 index 00000000..7c742382 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/csar/SERVICES/9bb8c882-44a1-4b67-a12c-5a998e18d6ba.json @@ -0,0 +1,62 @@ +{ + "uuid": "9bb8c882-44a1-4b67-a12c-5a998e18d6ba", + "invariantUUID": "388a89d0-3d3d-47f8-8621-32b7b12975d4", + "name": "EtsiNsServiceCSIT1", + "version": "1.0", + "toscaModelURL": "/sdc/v1/catalog/services/9bb8c882-44a1-4b67-a12c-5a998e18d6ba/toscaModel", + "category": "ETSI Network Service", + "lifecycleState": "CERTIFIED", + "lastUpdaterUserId": "cs0008", + "distributionStatus": "DISTRIBUTED", + "lastUpdaterFullName": "Carlos Santana", + "resources": [{ + "resourceInstanceName": "EtsiVnfCSIT3 0", + "resourceName": "EtsiVnfCSIT3", + "resourceInvariantUUID": "037f7b1b-5c62-44c1-b806-f92fe8970171", + "resourceVersion": "1.0", + "resoucreType": "VF", + "resourceUUID": "73522444-e8e9-49c1-be29-d355800aa349", + "artifacts": [{ + "artifactName": "vf-license-model.xml", + "artifactType": "VF_LICENSE", + "artifactURL": "/sdc/v1/catalog/services/9bb8c882-44a1-4b67-a12c-5a998e18d6ba/resourceInstances/etsivnfcsit30/artifacts/3e964c48-c539-41b6-b504-52905fbe1f93", + "artifactDescription": "VF license file", + "artifactChecksum": "MDAwOTQ0NWYzNzMzYjJmYjBlODc2ODUyY2MzOTIyMjQ=", + "artifactUUID": "3e964c48-c539-41b6-b504-52905fbe1f93", + "artifactVersion": "1", + "artifactLabel": "vflicense", + "artifactGroupType": "DEPLOYMENT" + }, { + "artifactName": "vgw6.csar", + "artifactType": "ETSI_PACKAGE", + "artifactURL": "/sdc/v1/catalog/services/9bb8c882-44a1-4b67-a12c-5a998e18d6ba/resourceInstances/etsivnfcsit30/artifacts/0737049a-204d-4009-932a-57a48119f5eb", + "artifactDescription": "Artifact created from csar", + "artifactChecksum": "ZjAyYjhmYzJkY2ExZjMyYzk1ZjlmNjk0YzkzNDNhY2Y=", + "artifactUUID": "0737049a-204d-4009-932a-57a48119f5eb", + "artifactVersion": "1", + "artifactLabel": "vgw6csar", + "artifactGroupType": "DEPLOYMENT" + }, { + "artifactName": "vendor-license-model.xml", + "artifactType": "VENDOR_LICENSE", + "artifactURL": "/sdc/v1/catalog/services/9bb8c882-44a1-4b67-a12c-5a998e18d6ba/resourceInstances/etsivnfcsit30/artifacts/f17c8eed-cf1f-44cd-a2b3-2caee9c34b17", + "artifactDescription": " Vendor license file", + "artifactChecksum": "NzY2ZGUzODNkNWEwNjM1MjRiMjNiNDY1ZWNkNWQyOTg=", + "artifactUUID": "f17c8eed-cf1f-44cd-a2b3-2caee9c34b17", + "artifactVersion": "1", + "artifactLabel": "vendorlicense", + "artifactGroupType": "DEPLOYMENT" + }] + }], + "artifacts": [{ + "artifactName": "ns.csar", + "artifactType": "OTHER", + "artifactURL": "/sdc/v1/catalog/services/9bb8c882-44a1-4b67-a12c-5a998e18d6ba/artifacts/a6b88549-cf1f-4c08-9088-c5e3067db1c9", + "artifactDescription": "ns", + "artifactChecksum": "ODBmYmU0MDRkZWIxNGVkY2NjODkxMGE4MmZlMTNmOGU=", + "artifactUUID": "a6b88549-cf1f-4c08-9088-c5e3067db1c9", + "artifactVersion": "1", + "artifactLabel": "ns", + "artifactGroupType": "DEPLOYMENT" + }] +}
\ No newline at end of file diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/csar/default_csar_file.csar b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/csar/default_csar_file.csar Binary files differdeleted file mode 100644 index 63b70ec6..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/resources/csar/default_csar_file.csar +++ /dev/null diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java index ca55f495..e3d040da 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java @@ -23,20 +23,23 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.util.Base64; -import java.util.Optional; +import java.util.Set; +import java.util.UUID; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.onap.so.sdcsimulator.controller.CatalogController; -import org.onap.so.sdcsimulator.providers.ResourceProvider; +import org.onap.so.sdcsimulator.models.ResourceAssetInfo; +import org.onap.so.sdcsimulator.models.ResourceMetadata; +import org.onap.so.sdcsimulator.models.ServiceAssetInfo; +import org.onap.so.sdcsimulator.models.ServiceMetadata; import org.onap.so.sdcsimulator.utils.Constants; +import org.onap.so.simulator.model.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.context.annotation.Configuration; +import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -56,6 +59,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @Configuration public class CatalogControllerTest { + private static final String SUB_CATEGORY = "Network Service"; + + private static final String DISTRIBUTION_STATUS = "DISTRIBUTED"; + + private static final String SERVICE_ID = "9bb8c882-44a1-4b67-a12c-5a998e18d6ba"; + + private static final String RESOURCE_ID = "73522444-e8e9-49c1-be29-d355800aa349"; + private static final String PASSWORD = "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U"; @LocalServerPort @@ -64,42 +75,121 @@ public class CatalogControllerTest { @Autowired private TestRestTemplate restTemplate; - @Value("${spring.security.username}") - private String username; + @Autowired + private UserCredentials userCredentials; + + @Test + public void test_getResourceCsar_validCsarId_matchContent() { + + final String url = getBaseUrl() + "/resources/" + RESOURCE_ID + "/toscaModel"; + + final ResponseEntity<byte[]> response = + restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), byte[].class); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertTrue(response.hasBody()); + assertEquals(117247, response.getBody().length); + + } @Test - public void test_getCsar_validCsarId_matchContent() { + public void test_getServiceCsar_validCsarId_matchContent() { - final String url = getBaseUrl() + "/resources/" + Constants.DEFAULT_CSAR_NAME + "/toscaModel"; + final String url = getBaseUrl() + "/services/" + SERVICE_ID + "/toscaModel"; final ResponseEntity<byte[]> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), byte[].class); assertEquals(HttpStatus.OK, response.getStatusCode()); assertTrue(response.hasBody()); - assertEquals(3982, response.getBody().length); + assertEquals(147743, response.getBody().length); + + } + + @Test + public void test_getResources_validResourcesFromClassPath() { + + final ResponseEntity<Set<ResourceAssetInfo>> response = + restTemplate.exchange(getBaseUrl() + "/resources", HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), + new ParameterizedTypeReference<Set<ResourceAssetInfo>>() {}); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertTrue(response.hasBody()); + assertEquals(1, response.getBody().size()); + assertEquals(SUB_CATEGORY, response.getBody().iterator().next().getSubCategory()); + + } + + @Test + public void test_getServices_validServicesFromClassPath() { + + final ResponseEntity<Set<ServiceAssetInfo>> response = + restTemplate.exchange(getBaseUrl() + "/services", HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), + new ParameterizedTypeReference<Set<ServiceAssetInfo>>() {}); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertTrue(response.hasBody()); + assertEquals(1, response.getBody().size()); + assertEquals(DISTRIBUTION_STATUS, response.getBody().iterator().next().getDistributionStatus()); } @Test - public void test_getCsar_invalidCsar_internalServerError() { - final ResourceProvider mockedResourceProvider = Mockito.mock(ResourceProvider.class); - Mockito.when(mockedResourceProvider.getResource(Mockito.anyString())).thenReturn(Optional.empty()); - final CatalogController objUnderTest = new CatalogController(mockedResourceProvider); + public void test_getResourceCsar_invalidCsar_internalServerError() { + final String url = getBaseUrl() + "/resources/" + UUID.randomUUID().toString() + "/toscaModel"; + + final ResponseEntity<byte[]> response = + restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), byte[].class); - final ResponseEntity<byte[]> response = objUnderTest.getCsar(Constants.DEFAULT_CSAR_NAME); assertFalse(response.hasBody()); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); } + @Test + public void test_getResourceMetadata_validMetadataFileInClasspath_matchContent() { + + final String url = getBaseUrl() + "/resources/" + RESOURCE_ID + "/metadata"; + + final ResponseEntity<ResourceMetadata> response = + restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), ResourceMetadata.class); + + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertTrue(response.hasBody()); + final ResourceMetadata actual = response.getBody(); + assertEquals(8, actual.getResources().size()); + assertEquals(3, actual.getArtifacts().size()); + assertEquals(SUB_CATEGORY, actual.getSubCategory()); + + } + + @Test + public void test_getServiceMetadata_validMetadataFileInClasspath_matchContent() { + + final String url = getBaseUrl() + "/services/" + SERVICE_ID + "/metadata"; + + final ResponseEntity<ServiceMetadata> response = + restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), ServiceMetadata.class); + + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertTrue(response.hasBody()); + final ServiceMetadata actual = response.getBody(); + assertEquals(1, actual.getResources().size()); + assertEquals(1, actual.getArtifacts().size()); + assertEquals(DISTRIBUTION_STATUS, actual.getDistributionStatus()); + + } + + private String getBaseUrl() { return "http://localhost:" + port + Constants.CATALOG_URL; } private HttpHeaders getHttpHeaders() { final HttpHeaders requestHeaders = new HttpHeaders(); - requestHeaders.add("Authorization", getBasicAuth(username)); + requestHeaders.add("Authorization", getBasicAuth(userCredentials.getUsers().get(0).getUsername())); requestHeaders.setContentType(MediaType.APPLICATION_JSON); return requestHeaders; } diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/providers/ResourceProviderImplTest.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/providers/AssetProviderImplTest.java index a7cb5dd7..24f5c754 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/providers/ResourceProviderImplTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/providers/AssetProviderImplTest.java @@ -22,61 +22,68 @@ package org.onap.so.sdcsimulator.providers; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertFalse; +import static org.onap.so.sdcsimulator.models.AssetType.RESOURCES; +import static org.onap.so.sdcsimulator.utils.Constants.DOT_CSAR; +import static org.onap.so.sdcsimulator.utils.Constants.FORWARD_SLASH; +import static org.onap.so.sdcsimulator.utils.Constants.MAIN_RESOURCE_FOLDER; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.UUID; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.onap.so.sdcsimulator.utils.Constants; import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.util.StreamUtils; /** * @author Waqas Ikram (waqas.ikram@est.tech) * @author Eoin Hanan (eoin.hanan@est.tech) */ -public class ResourceProviderImplTest { +public class AssetProviderImplTest { + + private static final String VNF_RESOURCE_ID = "73522444-e8e9-49c1-be29-d355800aa349"; @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); - private static final String DUMMY_CONTENT = "Hell world"; + private static final String DUMMY_CONTENT = "Hello world"; + + private final PathMatchingResourcePatternResolver resourcePatternResolver = + new PathMatchingResourcePatternResolver(); @Test public void test_getResource_withValidPath_matchContent() throws IOException { - final File folder = temporaryFolder.newFolder(); - final Path file = Files.createFile(folder.toPath().resolve("empty.csar")); + final File folder = temporaryFolder.newFolder(RESOURCES.toString()); + final String uuid = UUID.randomUUID().toString(); + final Path file = Files.createFile(folder.toPath().resolve(uuid + DOT_CSAR)); Files.write(file, DUMMY_CONTENT.getBytes()); - final ResourceProviderImpl objUnderTest = new ResourceProviderImpl(folder.getPath()); + final AssetProviderImpl objUnderTest = new AssetProviderImpl(folder.getParent(), resourcePatternResolver); - assertArrayEquals(DUMMY_CONTENT.getBytes(), objUnderTest.getResource("empty").get()); + assertArrayEquals(DUMMY_CONTENT.getBytes(), objUnderTest.getAsset(uuid, RESOURCES).get()); } @Test public void test_getResource_withoutValidPath_matchContent() throws IOException { - final ClassPathResource classPathResource = new ClassPathResource(Constants.DEFAULT_CSAR_PATH, this.getClass()); + final String validCsarPath = MAIN_RESOURCE_FOLDER + RESOURCES + FORWARD_SLASH + VNF_RESOURCE_ID + DOT_CSAR; + final ClassPathResource classPathResource = new ClassPathResource(validCsarPath, this.getClass()); final byte[] expectedResult = StreamUtils.copyToByteArray(classPathResource.getInputStream()); - final ResourceProviderImpl objUnderTest = new ResourceProviderImpl(""); + final AssetProviderImpl objUnderTest = new AssetProviderImpl("", resourcePatternResolver); - assertArrayEquals(expectedResult, objUnderTest.getResource(Constants.DEFAULT_CSAR_NAME).get()); + assertArrayEquals(expectedResult, objUnderTest.getAsset(VNF_RESOURCE_ID, RESOURCES).get()); } @Test - public void test_getResource_unbleToreadFileFromClasspath_emptyOptional() throws IOException { - - final ResourceProviderImpl objUnderTest = new ResourceProviderImpl("") { - @Override - String getDefaultCsarPath() { - return "/some/dummy/path"; - } - }; - assertFalse(objUnderTest.getResource(Constants.DEFAULT_CSAR_NAME).isPresent()); + public void test_getResource_unbleToReadFileFromClasspath_emptyOptional() throws IOException { + + final AssetProviderImpl objUnderTest = new AssetProviderImpl("", resourcePatternResolver); + assertFalse(objUnderTest.getAsset(UUID.randomUUID().toString(), RESOURCES).isPresent()); } } diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/model/Vnfds.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/model/Vnfds.java index cf550067..6fe696ee 100644 --- a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/model/Vnfds.java +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/model/Vnfds.java @@ -31,6 +31,17 @@ public class Vnfds { public void setVnfcList(final List<Vnfc> vnfclist) { this.vnfclist = vnfclist; } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class Vnfd {\n"); + sb.append(" vnfdId: ").append(vnfdId).append("\n"); + sb.append(" vnfclist: ").append(vnfclist).append("\n"); + sb.append("}"); + return sb.toString(); + } + } @@ -82,8 +93,20 @@ public class Vnfds { this.grantResourceId = grantResourceId; } - } + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class Vnfc {\n"); + sb.append(" vnfcId: ").append(vnfcId).append("\n"); + sb.append(" type: ").append(type).append("\n"); + sb.append(" vduId: ").append(vduId).append("\n"); + sb.append(" resourceTemplateId: ").append(resourceTemplateId).append("\n"); + sb.append(" grantResourceId: ").append(grantResourceId).append("\n"); + sb.append("}"); + return sb.toString(); + } + } public List<Vnfd> getVnfdList() { return vnfdList; @@ -94,4 +117,15 @@ public class Vnfds { this.vnfdList = vnfdList; } + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class Vnfds {\n"); + sb.append(" vnfdList: ").append(vnfdList).append("\n"); + sb.append("}"); + return sb.toString(); + } + + + } diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/services/InstantiateOperationProgressor.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/services/InstantiateOperationProgressor.java index 0a5444b9..6b483548 100644 --- a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/services/InstantiateOperationProgressor.java +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/services/InstantiateOperationProgressor.java @@ -40,9 +40,10 @@ public class InstantiateOperationProgressor extends OperationProgressor { @Override protected List<GrantsAddResources> getAddResources(final String vnfdId) { final List<GrantsAddResources> resources = new ArrayList<>(); - + LOGGER.info("Will find GrantsAddResources for vnfdId: {}", vnfdId); for (final Vnfd vnfd : vnfds.getVnfdList()) { if (vnfd.getVnfdId().equals(vnfdId)) { + LOGGER.info("Found vnfd: {}", vnfd); for (final Vnfc vnfc : vnfd.getVnfcList()) { final GrantsAddResources addResource = new GrantsAddResources(); vnfc.setGrantResourceId(UUID.randomUUID().toString()); @@ -80,9 +81,12 @@ public class InstantiateOperationProgressor extends OperationProgressor { addResource.getVimConnectionId()); } LOGGER.info("VIM connections in grant response: {}", mapOfGrantResourceIdToVimConnectionId); + final String vnfInstanceId = operation.getVnfInstanceId(); + + LOGGER.info("vnfds: {}", vnfds); for (final Vnfd vnfd : vnfds.getVnfdList()) { - if (vnfd.getVnfdId().equals(svnfmService.getVnf(operation.getVnfInstanceId()).getVnfdId())) { + if (vnfd.getVnfdId().equals(svnfmService.getVnf(vnfInstanceId).getVnfdId())) { for (final Vnfc vnfc : vnfd.getVnfcList()) { final InlineResponse201InstantiatedVnfInfoVnfcResourceInfo vnfcResourceInfoItem = new InlineResponse201InstantiatedVnfInfoVnfcResourceInfo(); diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/services/TerminateOperationProgressor.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/services/TerminateOperationProgressor.java index bd729f3a..9257e49f 100644 --- a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/services/TerminateOperationProgressor.java +++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/main/java/org/onap/so/svnfm/simulator/services/TerminateOperationProgressor.java @@ -12,12 +12,15 @@ import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.LcnVnfLcmOpera import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201.InstantiationStateEnum; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfoResourceHandle; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfoVnfcResourceInfo; -import org.onap.so.svnfm.simulator.model.Vnfds; -import org.onap.so.svnfm.simulator.repository.VnfOperationRepository; import org.onap.so.svnfm.simulator.config.ApplicationConfig; import org.onap.so.svnfm.simulator.model.VnfOperation; +import org.onap.so.svnfm.simulator.model.Vnfds; +import org.onap.so.svnfm.simulator.repository.VnfOperationRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class TerminateOperationProgressor extends OperationProgressor { + private static final Logger LOGGER = LoggerFactory.getLogger(TerminateOperationProgressor.class); public TerminateOperationProgressor(final VnfOperation operation, final SvnfmService svnfmService, final VnfOperationRepository vnfOperationRepository, final ApplicationConfig applicationConfig, @@ -33,9 +36,12 @@ public class TerminateOperationProgressor extends OperationProgressor { @Override protected List<GrantsAddResources> getRemoveResources(final String vnfdId) { final List<GrantsAddResources> resources = new ArrayList<>(); + LOGGER.info("Will find RemoveResources for vnfdId: {}", vnfdId); + final String vnfInstanceId = operation.getVnfInstanceId(); final org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201 vnf = - svnfmService.getVnf(operation.getVnfInstanceId()); + svnfmService.getVnf(vnfInstanceId); + LOGGER.info("Found InlineResponse201: {} for vnfInstanceId: {}", vnf, vnfInstanceId); for (final InlineResponse201InstantiatedVnfInfoVnfcResourceInfo vnfc : vnf.getInstantiatedVnfInfo() .getVnfcResourceInfo()) { final GrantsAddResources addResource = new GrantsAddResources(); |