diff options
author | Ravi Mantena <rx908f@att.com> | 2021-02-04 14:28:22 -0500 |
---|---|---|
committer | Ravi Mantena <rx908f@att.com> | 2021-02-08 14:10:16 -0500 |
commit | 9347a895ad097b0e67dd0208bc824672940d23cd (patch) | |
tree | d7cb5e1d162926f43d467517ccc726dde5a46b8d | |
parent | 0a405a9b4515f960d36d254032db680e97ab1e94 (diff) |
Distributing Blueprint to DCAE Dashboard Issue-ID: DCAEGEN2-2385>
Change-Id: Ib32f36ddf8efdbf27443d6bb4f1a3e624c82205c
Signed-off-by: Ravi Mantena <rx908f@att.com>
13 files changed, 716 insertions, 44 deletions
diff --git a/mod2/catalog-service/pom.xml b/mod2/catalog-service/pom.xml index 9a82b7b..ff425cf 100644 --- a/mod2/catalog-service/pom.xml +++ b/mod2/catalog-service/pom.xml @@ -3,7 +3,7 @@ ~ ============LICENSE_START======================================================= ~ org.onap.dcae ~ ================================================================================ - ~ Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + ~ Copyright (c) 2020-2021 AT&T Intellectual Property. All rights reserved. ~ ================================================================================ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. @@ -110,6 +110,11 @@ <version>4.2.2</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <version>20190722</version> + </dependency> </dependencies> <dependencyManagement> diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/DeploymentArtifact.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/DeploymentArtifact.java index 600c735..72bba72 100644 --- a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/DeploymentArtifact.java +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/DeploymentArtifact.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.dcae * ================================================================================ - * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,10 @@ package org.onap.dcaegen2.platform.mod.model.deploymentartifact; +import java.util.ArrayList; +import java.util.List; import lombok.Data; +import org.onap.dcaegen2.platform.mod.model.policymodel.DistributionInfo; import org.springframework.data.mongodb.core.mapping.Document; import java.util.Map; @@ -48,4 +51,6 @@ public class DeploymentArtifact { private Map<String, Object> specificationInfo; + private DistributionInfo distributionInfo; + } diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/util/BlueprintDistributionUtils.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/util/BlueprintDistributionUtils.java new file mode 100644 index 0000000..2860a39 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/util/BlueprintDistributionUtils.java @@ -0,0 +1,140 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.util; + +import java.util.HashMap; +import java.util.Map; +import javax.annotation.PostConstruct; +import org.onap.dcaegen2.platform.mod.model.exceptions.policymodel.PolicyModelDistributionEnvNotFoundException; +import org.onap.dcaegen2.platform.mod.model.policymodel.EnvInfo; +import org.onap.dcaegen2.platform.mod.model.policymodel.PolicyModelDistributionEnv; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +/** + * Policy Model Service Utils to get URL, Username, Password, Webclient + */ + +@Component +public class BlueprintDistributionUtils { + + @Value("${dcae.platform.url.path}") + private String urlpath; + + @Value("${dcae.platform.dev.server}") + private String devServer; + + @Value("${dcae.platform.dev.port}") + private String devServerPort; + + @Value("${dcae.platform.dev.user}") + private String devServerUser; + + @Value("${dcae.platform.dev.password}") + private String devServerUserPassword; + + @Value("${dcae.platform.pst.server}") + private String pstServer; + + @Value("${dcae.platform.pst.port}") + private String pstServerPort; + + @Value("${dcae.platform.pst.user}") + private String pstServerUser; + + @Value("${dcae.platform.pst.password}") + private String pstServerUserPassword; + + @Value("${dcae.platform.ete.server}") + private String eteServer; + + @Value("${dcae.platform.ete.port}") + private String eteServerPort; + + @Value("${dcae.platform.ete.user}") + private String eteServerUser; + + @Value("${dcae.platform.ete.password}") + private String eteServerUserPassword; + + @Value("${dcae.platform.prod.server}") + private String prodServer; + + @Value("${dcae.platform.prod.port}") + private String prodServerPort; + + @Value("${dcae.platform.prod.user}") + private String prodServerUser; + + @Value("${dcae.platform.prod.password}") + private String prodServerUserPassword; + + Map<String, EnvInfo> envMap; + + /** + * Creates a Blueprint Distribution Dashboard URL for the Environment requested + */ + @PostConstruct + public void init() { + envMap = new HashMap<>(); + envMap.put(PolicyModelDistributionEnv.DEV.name(), EnvInfo.builder().url("https://"+ devServer + ":" + devServerPort + urlpath).username(devServerUser).password(devServerUserPassword).build()); + envMap.put(PolicyModelDistributionEnv.PST.name(), EnvInfo.builder().url("https://"+ pstServer + ":" + pstServerPort + urlpath).username(pstServerUser).password(pstServerUserPassword).build()); + envMap.put(PolicyModelDistributionEnv.ETE.name(), EnvInfo.builder().url("https://"+ eteServer + ":" + eteServerPort + urlpath).username(eteServerUser).password(eteServerUserPassword).build()); + envMap.put(PolicyModelDistributionEnv.PROD.name(), EnvInfo.builder().url("https://"+ prodServer + ":" + prodServerPort + urlpath).username(prodServerUser).password(prodServerUserPassword).build()); + } + + /** + * Generates a Blueprint Distribution Dashboard URL for the Environment + * + * @param env + * @return + */ + public String getBlueprintDashboardURL(String env) { + if(!envMap.containsKey(env)) throw new PolicyModelDistributionEnvNotFoundException(String.format("Blueprint Dashboard Environment with env %s invalid", env)); + return envMap.get(env).getUrl(); + } + + /** + * Generates a Blueprint Distribution Dashboard UserName for the Environment + * + * @param env + * @return + */ + + public String getBlueprintDashboardUserName(String env) { + if(!envMap.containsKey(env)) throw new PolicyModelDistributionEnvNotFoundException(String.format("Blueprint Dashboard Environment with env %s invalid", env)); + return envMap.get(env).getUsername(); + } + + + /** + * Generates a Blueprint Distribution Dashboard Password for the Environment + * + * @param env + * @return + */ + + public String getBlueprintDashboardPassword(String env) { + if(!envMap.containsKey(env)) throw new PolicyModelDistributionEnvNotFoundException(String.format("Blueprint Dashboard Environment with env %s invalid", env)); + return envMap.get(env).getPassword(); + } + +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/util/PolicyModelUtils.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/util/PolicyModelUtils.java index 30e13ea..347e66b 100644 --- a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/util/PolicyModelUtils.java +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/util/PolicyModelUtils.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.dcae * ================================================================================ - * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,55 +46,55 @@ import java.util.Map; @Component public class PolicyModelUtils { - @Value("${url.path}") + @Value("${policymodel.url.path}") private String urlpath; - @Value("${dev.server}") + @Value("${policymodel.dev.server}") private String devServer; - @Value("${dev.port}") + @Value("${policymodel.dev.port}") private String devServerPort; - @Value("${dev.user}") + @Value("${policymodel.dev.user}") private String devServerUser; - @Value("${dev.password}") + @Value("${policymodel.dev.password}") private String devServerUserPassword; - @Value("${pst.server}") + @Value("${policymodel.pst.server}") private String pstServer; - @Value("${pst.port}") + @Value("${policymodel.pst.port}") private String pstServerPort; - @Value("${pst.user}") + @Value("${policymodel.pst.user}") private String pstServerUser; - @Value("${pst.password}") + @Value("${policymodel.pst.password}") private String pstServerUserPassword; - @Value("${ete.server}") + @Value("${policymodel.ete.server}") private String eteServer; - @Value("${ete.port}") + @Value("${policymodel.ete.port}") private String eteServerPort; - @Value("${ete.user}") + @Value("${policymodel.ete.user}") private String eteServerUser; - @Value("${ete.password}") + @Value("${policymodel.ete.password}") private String eteServerUserPassword; - @Value("${prod.server}") + @Value("${policymodel.prod.server}") private String prodServer; - @Value("${prod.port}") + @Value("${policymodel.prod.port}") private String prodServerPort; - @Value("${prod.user}") + @Value("${policymodel.prod.user}") private String prodServerUser; - @Value("${prod.password}") + @Value("${policymodel.prod.password}") private String prodServerUserPassword; Map<String, EnvInfo> envMap; diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/util/SSLUtils.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/util/SSLUtils.java new file mode 100644 index 0000000..a5d313d --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/util/SSLUtils.java @@ -0,0 +1,69 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.util; + +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + +public final class SSLUtils { + + static { + // for localhost testing only + HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier() { + public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) { + return true; + } + }); + } + + private static final TrustManager[] UNQUESTIONING_TRUST_MANAGER = new TrustManager[] { new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { + return null; + } + + public void checkClientTrusted(X509Certificate[] certs, String authType) { + } + + public void checkServerTrusted(X509Certificate[] certs, String authType) { + } + } }; + + public static void turnOffSslChecking() throws NoSuchAlgorithmException, KeyManagementException { + // Install the all-trusting trust manager + final SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, UNQUESTIONING_TRUST_MANAGER, null); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + } + + public static void turnOnSslChecking() throws KeyManagementException, NoSuchAlgorithmException { + // Return it to the initial state (discovered by reflection, now hardcoded) + SSLContext.getInstance("SSL").init(null, null, null); + } + + private SSLUtils() { + throw new UnsupportedOperationException("Do not instantiate libraries."); + } +}
\ No newline at end of file diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/BlueprintDistributionController.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/BlueprintDistributionController.java new file mode 100644 index 0000000..36fbb2f --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/BlueprintDistributionController.java @@ -0,0 +1,51 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.onap.dcaegen2.platform.mod.model.policymodel.PolicyModelDistributionEnv; +import org.onap.dcaegen2.platform.mod.web.service.blueprintdistributionservice.BlueprintDistributionService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping(value = "/api/deployment-artifact") +@Api(tags = "Graph", description = "API to distribute Blueprint to DCAE") +public class BlueprintDistributionController { + + @Autowired + private BlueprintDistributionService blueprintDistributionService; + + @PostMapping(value = "/{deploymentArtifactId}/distribute") + @ApiOperation("Distribution of Blueprint to DCAE") + public ResponseEntity distributeBlueprint(@PathVariable(value = "deploymentArtifactId") String deploymentArtifactId + ,@RequestParam PolicyModelDistributionEnv env){ + + return blueprintDistributionService.distributeBlueprint(deploymentArtifactId,env.name()); + } + +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/blueprintdistributionservice/BlueprintDistributionService.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/blueprintdistributionservice/BlueprintDistributionService.java new file mode 100644 index 0000000..6f7ca68 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/blueprintdistributionservice/BlueprintDistributionService.java @@ -0,0 +1,34 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.blueprintdistributionservice; + + +import org.springframework.http.ResponseEntity; + +/** + * An interface to access Blueprint Distribution Services + */ + +public interface BlueprintDistributionService { + + public ResponseEntity distributeBlueprint(String deploymentArtifactId, String env); + +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/blueprintdistributionservice/BlueprintDistributionServiceImpl.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/blueprintdistributionservice/BlueprintDistributionServiceImpl.java new file mode 100644 index 0000000..6ae367c --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/blueprintdistributionservice/BlueprintDistributionServiceImpl.java @@ -0,0 +1,113 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.blueprintdistributionservice; + +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.json.JSONObject; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifact; +import org.onap.dcaegen2.platform.mod.model.policymodel.DistributionInfo; +import org.onap.dcaegen2.platform.mod.model.policymodel.PolicyModelStatus; +import org.onap.dcaegen2.platform.mod.model.restapi.ErrorResponse; +import org.onap.dcaegen2.platform.mod.model.restapi.SuccessResponse; +import org.onap.dcaegen2.platform.mod.util.BlueprintDistributionUtils; +import org.onap.dcaegen2.platform.mod.util.SSLUtils; +import org.onap.dcaegen2.platform.mod.web.service.deploymentartifact.DeploymentArtifactGateway; +import org.onap.dcaegen2.platform.mod.web.service.deploymentartifact.DeploymentArtifactService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +@Setter +@Slf4j +public class BlueprintDistributionServiceImpl implements BlueprintDistributionService{ + + @Autowired + private DeploymentArtifactService deploymentArtifactService; + + @Autowired + private BlueprintDistributionUtils blueprintDistributionUtils; + + @Autowired + private DeploymentArtifactGateway deploymentArtifactGateway; + + @Autowired + private RestTemplate restTemplate; + + public ResponseEntity distributeBlueprint(String deploymentArtifactId, String env){ + DeploymentArtifact deploymentArtifact = deploymentArtifactService.findDeploymentArtifactById(deploymentArtifactId); + return postBlueprintToDcae(deploymentArtifact,env); + } + + private ResponseEntity postBlueprintToDcae(DeploymentArtifact deploymentArtifact, String env){ + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.setBasicAuth(blueprintDistributionUtils.getBlueprintDashboardUserName(env),blueprintDistributionUtils.getBlueprintDashboardPassword(env)); + + DistributionInfo distributionInfo = DistributionInfo.builder().url(blueprintDistributionUtils.getBlueprintDashboardURL(env)).build(); + deploymentArtifact.setDistributionInfo(distributionInfo); + JSONObject blueprintJsonObject = prepareBlueprintJsonObject(deploymentArtifact); + HttpEntity<String> request = new HttpEntity<>(blueprintJsonObject.toString(), headers); + + try{ + SSLUtils.turnOffSslChecking(); + String response = restTemplate.postForObject(blueprintDistributionUtils.getBlueprintDashboardURL(env),request,String.class); + log.info(response); + log.info(String.format("Distributed Blueprint to DCAE: %s", blueprintJsonObject.toString())); + distributionInfo.setStatus(PolicyModelStatus.SUCCESS); + deploymentArtifactGateway.save(deploymentArtifact); + blueprintJsonObject.put("distributionInfoStatus", PolicyModelStatus.SUCCESS.name()); + return new ResponseEntity<>(new SuccessResponse(blueprintJsonObject.toString()), HttpStatus.OK); + }catch (Exception e) { + log.error("Failed to push Blueprint to DCAE"); + log.error(e.getMessage()); + distributionInfo.setStatus(PolicyModelStatus.FAILED); + deploymentArtifactGateway.save(deploymentArtifact); + return new ResponseEntity<>(new ErrorResponse(e.getMessage()), HttpStatus.BAD_REQUEST); + } + } + + private JSONObject prepareBlueprintJsonObject(DeploymentArtifact deploymentArtifact) { + JSONObject blueprintJsonObject = new JSONObject(); + blueprintJsonObject.put("owner","dcae_mod"); + blueprintJsonObject.put("typeName",deploymentArtifact.getFileName()); + blueprintJsonObject.put("typeVersion",deploymentArtifact.getVersion()); + blueprintJsonObject.put("blueprintTemplate",deploymentArtifact.getContent()); + blueprintJsonObject.put("application","DCAE"); + blueprintJsonObject.put("component","dcae"); + blueprintJsonObject.put("distributionInfoUrl", deploymentArtifact.getDistributionInfo().getUrl()); + return blueprintJsonObject; + } + + @Bean + private RestTemplate getRestTemplate(){ + return new RestTemplate(); + } + +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/policymodel/PolicyModelServiceImpl.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/policymodel/PolicyModelServiceImpl.java index 58fc447..a5dcfd0 100644 --- a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/policymodel/PolicyModelServiceImpl.java +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/policymodel/PolicyModelServiceImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.dcae * ================================================================================ - * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,16 +52,16 @@ import java.util.List; @Slf4j public class PolicyModelServiceImpl implements PolicyModelService { - @Value("${dev.server}") + @Value("${policymodel.dev.server}") private String devServer; - @Value("${dev.port}") + @Value("${policymodel.dev.port}") private String devServerPort; - @Value("${dev.user}") + @Value("${policymodel.dev.user}") private String devServerUser; - @Value("${dev.password}") + @Value("${policymodel.dev.password}") private String devServerPassword; @Autowired diff --git a/mod2/catalog-service/src/main/resources/application.properties b/mod2/catalog-service/src/main/resources/application.properties index 93c7883..9930866 100644 --- a/mod2/catalog-service/src/main/resources/application.properties +++ b/mod2/catalog-service/src/main/resources/application.properties @@ -2,7 +2,7 @@ # ============LICENSE_START======================================================= # org.onap.dcae # ================================================================================ -# Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2020-2021 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,26 +25,51 @@ spring.data.mongodb.database=dcae_mod -#Distribution Info Environment details +# Policy Model Distribution Info Environment details -url.path=/policy/api/v1/policytypes +policymodel.url.path=/policy/api/v1/policytypes -dev.server=10.12.6.2 -dev.port=30522 -dev.user=healthcheck -dev.password=PASSWORD_GOES_HERE +policymodel.dev.server=10.12.6.2 +policymodel.dev.port=30522 +policymodel.dev.user=healthcheck +policymodel.dev.password=PASSWORD_GOES_HERE -pst.server=policy-api -pst.port=6969 -pst.user=healthcheck -pst.password=PASSWORD_GOES_HERE +policymodel.pst.server=policy-api +policymodel.pst.port=6969 +policymodel.pst.user=healthcheck +policymodel.pst.password=PASSWORD_GOES_HERE -ete.server=policy-api -ete.port=6969 -ete.user=healthcheck -ete.password=PASSWORD_GOES_HERE +policymodel.ete.server=policy-api +policymodel.ete.port=6969 +policymodel.ete.user=healthcheck +policymodel.ete.password=PASSWORD_GOES_HERE -prod.server=policy-api -prod.port=6969 -prod.user=healthcheck -prod.password=PASSWORD_GOES_HERE
\ No newline at end of file +policymodel.prod.server=policy-api +policymodel.prod.port=6969 +policymodel.prod.user=healthcheck +policymodel.prod.password=PASSWORD_GOES_HERE + + +# Blueprint Distribution Info Environment details + +dcae.platform.url.path=/ccsdk-app/nb-api/v2/blueprints + +dcae.platform.dev.server:10.12.5.222 +dcae.platform.dev.port:30418 +dcae.platform.dev.user=su1234 +dcae.platform.dev.password=PASSWORD_GOES_HERE + +dcae.platform.pst.server:10.12.5.222 +dcae.platform.pst.port:30418 +dcae.platform.pst.user=su1234 +dcae.platform.pst.password=PASSWORD_GOES_HERE + +dcae.platform.ete.server:10.12.5.222 +dcae.platform.ete.port:30418 +dcae.platform.ete.user=su1234 +dcae.platform.ete.password=PASSWORD_GOES_HERE + +dcae.platform.prod.server:10.12.5.222 +dcae.platform.prod.port:30418 +dcae.platform.prod.user=su1234 +dcae.platform.prod.password=PASSWORD_GOES_HERE
\ No newline at end of file diff --git a/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/objectmothers/BlueprintDistributionObjectMother.java b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/objectmothers/BlueprintDistributionObjectMother.java new file mode 100644 index 0000000..3d06f26 --- /dev/null +++ b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/objectmothers/BlueprintDistributionObjectMother.java @@ -0,0 +1,29 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.objectmothers; + +public class BlueprintDistributionObjectMother { + public static final String BP_DISTRIBUTION_ENV = "DEV"; + public static final String BP_DISTRIBUTION_MODEL_ID = "5f74ed7877b37173993057f5"; + public static final String BP_DISTRIBUTION_USER = "User1"; + public static final String BP_DISTRIBUTION_PWD = "pwd"; + +} diff --git a/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/BlueprintDistributionControllerTest.java b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/BlueprintDistributionControllerTest.java new file mode 100644 index 0000000..7414116 --- /dev/null +++ b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/BlueprintDistributionControllerTest.java @@ -0,0 +1,76 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.onap.dcaegen2.platform.mod.objectmothers.BlueprintDistributionObjectMother.BP_DISTRIBUTION_ENV; +import static org.onap.dcaegen2.platform.mod.objectmothers.BlueprintDistributionObjectMother.BP_DISTRIBUTION_MODEL_ID; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.onap.dcaegen2.platform.mod.model.restapi.SuccessResponse; +import org.onap.dcaegen2.platform.mod.web.controller.BlueprintDistributionController; +import org.onap.dcaegen2.platform.mod.web.service.blueprintdistributionservice.BlueprintDistributionService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.web.servlet.MockMvc; + +@ExtendWith(SpringExtension.class) +@WebMvcTest(BlueprintDistributionController.class) +public class BlueprintDistributionControllerTest { + + @Autowired + MockMvc mockMvc; + + @MockBean + private BlueprintDistributionService mockBlueprintDistributionService; + + @BeforeEach + void setup() { + } + + + @Test + void test_distributeBlueprintById_shouldReturn201AndResponseBody() throws Exception { + + ResponseEntity mockResponseEntity = new ResponseEntity<>(new SuccessResponse("Success"), HttpStatus.OK); + + when(mockBlueprintDistributionService + .distributeBlueprint(BP_DISTRIBUTION_MODEL_ID,BP_DISTRIBUTION_ENV)).thenReturn(mockResponseEntity); + + mockMvc.perform(post("/api/deployment-artifact/" + BP_DISTRIBUTION_MODEL_ID + "/distribute") + .param("env",BP_DISTRIBUTION_ENV).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + + verify(mockBlueprintDistributionService, times(1)).distributeBlueprint(BP_DISTRIBUTION_MODEL_ID,BP_DISTRIBUTION_ENV); + } + +}
\ No newline at end of file diff --git a/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/service/BlueprintDistributionServiceImplImplTest.java b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/service/BlueprintDistributionServiceImplImplTest.java new file mode 100644 index 0000000..0a8a785 --- /dev/null +++ b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/service/BlueprintDistributionServiceImplImplTest.java @@ -0,0 +1,125 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.onap.dcaegen2.platform.mod.objectmothers.BlueprintDistributionObjectMother.BP_DISTRIBUTION_ENV; +import static org.onap.dcaegen2.platform.mod.objectmothers.BlueprintDistributionObjectMother.BP_DISTRIBUTION_MODEL_ID; +import static org.onap.dcaegen2.platform.mod.objectmothers.BlueprintDistributionObjectMother.BP_DISTRIBUTION_PWD; +import static org.onap.dcaegen2.platform.mod.objectmothers.BlueprintDistributionObjectMother.BP_DISTRIBUTION_USER; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifact; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifactStatus; +import org.onap.dcaegen2.platform.mod.objectmothers.DeploymentArtifactObjectMother; +import org.onap.dcaegen2.platform.mod.util.BlueprintDistributionUtils; +import org.onap.dcaegen2.platform.mod.web.service.blueprintdistributionservice.BlueprintDistributionServiceImpl; +import org.onap.dcaegen2.platform.mod.web.service.deploymentartifact.DeploymentArtifactGateway; +import org.onap.dcaegen2.platform.mod.web.service.deploymentartifact.DeploymentArtifactServiceImpl; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +@ExtendWith(MockitoExtension.class) +class BlueprintDistributionServiceImplImplTest { + + @Spy + private BlueprintDistributionServiceImpl mockBlueprintDistributionServiceImpl = new BlueprintDistributionServiceImpl(); + + @Mock + private DeploymentArtifactServiceImpl deploymentArtifactService; + + @Mock + private BlueprintDistributionUtils blueprintDistributionUtils; + + @Mock + private DeploymentArtifactGateway deploymentArtifactGateway; + + @Mock + private RestTemplate restTemplate; + + DeploymentArtifact deploymentArtifact; + + + + @BeforeEach + void initialize(){ + mockBlueprintDistributionServiceImpl.setDeploymentArtifactService(deploymentArtifactService); + mockBlueprintDistributionServiceImpl.setDeploymentArtifactGateway(deploymentArtifactGateway); + mockBlueprintDistributionServiceImpl.setBlueprintDistributionUtils(blueprintDistributionUtils); + mockBlueprintDistributionServiceImpl.setRestTemplate(restTemplate); + deploymentArtifact = DeploymentArtifactObjectMother.createDeploymentArtifactDAO(DeploymentArtifactStatus.IN_DEV); + } + + + @Test + void test_distributeBlueprintReturnSucess() { + + when(deploymentArtifactService.findDeploymentArtifactById(BP_DISTRIBUTION_MODEL_ID)).thenReturn(deploymentArtifact); + when(blueprintDistributionUtils.getBlueprintDashboardURL(BP_DISTRIBUTION_ENV)).thenReturn("/url"); + when(blueprintDistributionUtils.getBlueprintDashboardUserName(BP_DISTRIBUTION_ENV)).thenReturn(BP_DISTRIBUTION_USER); + when(blueprintDistributionUtils.getBlueprintDashboardPassword(BP_DISTRIBUTION_ENV)).thenReturn(BP_DISTRIBUTION_PWD); + + ResponseEntity expected = mockBlueprintDistributionServiceImpl.distributeBlueprint(BP_DISTRIBUTION_MODEL_ID,BP_DISTRIBUTION_ENV); + + assertThat(expected.getStatusCode()).isEqualTo(HttpStatus.OK); + verify(deploymentArtifactService, times(1)).findDeploymentArtifactById(BP_DISTRIBUTION_MODEL_ID); + verify(blueprintDistributionUtils, times(2)).getBlueprintDashboardURL(BP_DISTRIBUTION_ENV); + verify(blueprintDistributionUtils, times(1)).getBlueprintDashboardUserName(BP_DISTRIBUTION_ENV); + verify(blueprintDistributionUtils, times(1)).getBlueprintDashboardPassword(BP_DISTRIBUTION_ENV); + verify(deploymentArtifactGateway, times(1)).save(any()); + + } + + @Test + void test_distributeBlueprintReturnBadRequest() { + + when(deploymentArtifactService.findDeploymentArtifactById(BP_DISTRIBUTION_MODEL_ID)).thenReturn(deploymentArtifact); + when(blueprintDistributionUtils.getBlueprintDashboardURL(BP_DISTRIBUTION_ENV)).thenReturn("/url"); + when(blueprintDistributionUtils.getBlueprintDashboardUserName(BP_DISTRIBUTION_ENV)).thenReturn(BP_DISTRIBUTION_USER); + when(blueprintDistributionUtils.getBlueprintDashboardPassword(BP_DISTRIBUTION_ENV)).thenReturn(BP_DISTRIBUTION_PWD); + when(restTemplate.postForObject(blueprintDistributionUtils.getBlueprintDashboardURL(BP_DISTRIBUTION_ENV), + HttpEntity.class,String.class)).thenReturn("Bad request"); + + ResponseEntity expected = mockBlueprintDistributionServiceImpl.distributeBlueprint(BP_DISTRIBUTION_MODEL_ID,BP_DISTRIBUTION_ENV); + + assertThat(expected.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); + verify(deploymentArtifactService, times(1)).findDeploymentArtifactById(BP_DISTRIBUTION_MODEL_ID); + verify(blueprintDistributionUtils, times(3)).getBlueprintDashboardURL(BP_DISTRIBUTION_ENV); + verify(blueprintDistributionUtils, times(1)).getBlueprintDashboardUserName(BP_DISTRIBUTION_ENV); + verify(blueprintDistributionUtils, times(1)).getBlueprintDashboardPassword(BP_DISTRIBUTION_ENV); + verify(deploymentArtifactGateway, times(1)).save(any()); + + } + + + +}
\ No newline at end of file |