diff options
author | 2019-04-22 17:47:33 -0400 | |
---|---|---|
committer | 2019-04-23 11:07:55 -0400 | |
commit | d5339481d3c3f24dd5faccb44dccd4addfd58499 (patch) | |
tree | dacae59a21608341fcce9cc0060399b15d487f47 /ms/cds-sdc-listener/application/src | |
parent | f332e6ecd2c0a9f26451f977c941f03ed8ab84dc (diff) |
SDC Listner Docker touchup
1.Reworked Dockerization of SDC Listener to follow
application/distribution+parent style;
2.Renamed CDS-SDClistener to just SDCListener
Issue-ID: CCSDK-1145
Change-Id: I007373d3a48fb8eb7042150bdbb37fc7fec346b3
Signed-off-by: Oleg Mitsura <oleg.mitsura@amdocs.com>
Diffstat (limited to 'ms/cds-sdc-listener/application/src')
26 files changed, 0 insertions, 1609 deletions
diff --git a/ms/cds-sdc-listener/application/src/main/docker/Dockerfile b/ms/cds-sdc-listener/application/src/main/docker/Dockerfile deleted file mode 100644 index 062f65767..000000000 --- a/ms/cds-sdc-listener/application/src/main/docker/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM openjdk:8-jdk-alpine - -ENV HTTP_PROXY ${HTTP_PROXY} -ENV HTTPS_PROXY ${HTTPS_PROXY} - -RUN mkdir -p /opt/app/onap/ /opt/app/onap/config -WORKDIR /opt/app/onap/ -COPY start.sh /opt/app/onap/ -COPY application.yml /opt/app/onap/config -RUN chmod 751 /opt/app/onap/start.sh -COPY cds-sdc-listener-application-0.4.2-SNAPSHOT.jar /opt/app/onap/cds-sdc-listener-distribution.jar -EXPOSE 9000 -ENTRYPOINT /opt/app/onap/start.sh diff --git a/ms/cds-sdc-listener/application/src/main/docker/docker-compose.yaml b/ms/cds-sdc-listener/application/src/main/docker/docker-compose.yaml deleted file mode 100644 index 1e7384744..000000000 --- a/ms/cds-sdc-listener/application/src/main/docker/docker-compose.yaml +++ /dev/null @@ -1,29 +0,0 @@ -version: '3.3' - -services: - cds-sdc-listener: - image: onap/cdssdclistener:latest - container_name: cdssdclistener - restart: always - environment: - asdcAddress: localhost:8443 - messageBusAddress: localhost - sdcusername: vid - password: Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U - pollingInterval: 15 - pollingTimeout: 15 - relevantArtifactTypes: TOSCA_CSAR - consumerGroup: cds-id-local - environmentName: AUTO - consumerId: cds-id-local - keyStorePassword: - keyStorePath: - activateServerTLSAuth: "false" - isUseHttpsWithDmaap: "false" - archivePath: /opt/app/onap/cds-sdc-listener/ - grpcAddress: localhost - grpcPort: 9111 - authHeader: Basic Y2NzZGthcHBzOmNjc2RrYXBwcw== - #port needed by Liveness probe - healthcheckPort: "9000" - sprintWebListenerEnabled: "true" diff --git a/ms/cds-sdc-listener/application/src/main/docker/start.sh b/ms/cds-sdc-listener/application/src/main/docker/start.sh deleted file mode 100755 index f24d15618..000000000 --- a/ms/cds-sdc-listener/application/src/main/docker/start.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -extraArgs=$@ -java -jar /opt/app/onap/cds-sdc-listener-distribution.jar \ --Dspring.config=/opt/app/onap/config/application.yml \ --Djava.security.egd=file:/dev/./urandom \ -${extraArgs} diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerApplication.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerApplication.java deleted file mode 100644 index 6f0f65323..000000000 --- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerApplication.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ -package org.onap.ccsdk.cds.cdssdclistener; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.properties.EnableConfigurationProperties; - -@SpringBootApplication -@EnableConfigurationProperties(CdsSdcListenerConfiguration.class) -public class CdsSdcListenerApplication { - public static void main(String[] args) { - SpringApplication.run(CdsSdcListenerApplication.class, args); - } -} diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfiguration.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfiguration.java deleted file mode 100644 index 3dfb07eb8..000000000 --- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfiguration.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ -package org.onap.ccsdk.cds.cdssdclistener; - -import java.util.List; -import org.onap.sdc.api.consumer.IConfiguration; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * In order to initiate a SDC distribution client we need to supply some pre-configuration values that - * distribution client needs. - */ -@ConfigurationProperties("listenerservice") -public class CdsSdcListenerConfiguration implements IConfiguration { - - public static final String TOSCA_CSAR = "TOSCA_CSAR"; - - @Value("${listenerservice.config.asdcAddress}") - private String asdcAddress; - - @Value("${listenerservice.config.messageBusAddress}") - private List<String> messageBusAddress; - - @Value("${listenerservice.config.user}") - private String user; - - @Value("${listenerservice.config.password}") - private String password; - - @Value("${listenerservice.config.pollingTimeout}") - private int pollingTimeout; - - @Value("${listenerservice.config.pollingInterval}") - private int pollingInterval; - - @Value("${listenerservice.config.relevantArtifactTypes}") - private List<String> relevantArtifactTypes; - - @Value("${listenerservice.config.consumerGroup}") - private String consumerGroup; - - @Value("${listenerservice.config.environmentName}") - private String envName; - - @Value("${listenerservice.config.consumerId}") - private String consumerId; - - @Value("${listenerservice.config.activateServerTLSAuth}") - private boolean activateServerTLSAuth; - - @Value("${listenerservice.config.isUseHttpsWithDmaap}") - private boolean isUseHttpsWithDmaap; - - @Override - public String getAsdcAddress() { - return asdcAddress; - } - - @Override - public List<String> getMsgBusAddress() { - return messageBusAddress; - } - - @Override - public String getUser() { - return user; - } - - @Override - public String getPassword() { - return password; - } - - @Override - public int getPollingInterval() { - return pollingInterval; - } - - @Override - public int getPollingTimeout() { - return pollingTimeout; - } - - @Override - public List<String> getRelevantArtifactTypes() { - return relevantArtifactTypes; - } - - @Override - public String getConsumerGroup() { - return consumerGroup; - } - - @Override - public String getEnvironmentName() { - return envName; - } - - @Override - public String getConsumerID() { - return consumerId; - } - - @Override - public String getKeyStorePath() { - return null; - } - - @Override - public String getKeyStorePassword() { - return null; - } - - @Override - public boolean activateServerTLSAuth() { - return activateServerTLSAuth; - } - - @Override - public boolean isFilterInEmptyResources() { - return false; - } - - @Override - public Boolean isUseHttpsWithDmaap() { - return isUseHttpsWithDmaap; - } -} - diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerNotificationCallback.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerNotificationCallback.java deleted file mode 100644 index 58c667c26..000000000 --- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerNotificationCallback.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ -package org.onap.ccsdk.cds.cdssdclistener; - -import static org.onap.sdc.utils.DistributionActionResultEnum.SUCCESS; -import java.io.File; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import org.onap.ccsdk.cds.cdssdclistener.dto.CdsSdcListenerDto; -import org.onap.ccsdk.cds.cdssdclistener.service.ListenerService; -import org.onap.ccsdk.cds.cdssdclistener.status.CdsSdcListenerStatus; -import org.onap.ccsdk.cds.cdssdclistener.util.FileUtil; -import org.onap.sdc.api.IDistributionClient; -import org.onap.sdc.api.consumer.INotificationCallback; -import org.onap.sdc.api.notification.IArtifactInfo; -import org.onap.sdc.api.notification.INotificationData; -import org.onap.sdc.api.results.IDistributionClientDownloadResult; -import org.onap.sdc.utils.DistributionStatusEnum; -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.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.stereotype.Component; - -@ConfigurationProperties("listenerservice") -@Component -@ComponentScan("org.onap.ccsdk.cds.cdssdclistener.dto") -public class CdsSdcListenerNotificationCallback implements INotificationCallback { - - @Autowired - private CdsSdcListenerDto cdsSdcListenerDto; - - @Autowired - private ListenerService listenerService; - - @Value("${listenerservice.config.archivePath}") - private String pathToStoreArchives; - - @Autowired - private CdsSdcListenerStatus listenerStatus; - - private static final Logger LOGGER = LoggerFactory.getLogger(CdsSdcListenerNotificationCallback.class); - - @Override - public void activateCallback(INotificationData notificationData) { - final String distributionId = notificationData.getDistributionID(); - cdsSdcListenerDto.setDistributionId(distributionId); - LOGGER.info("Received service distribution from SDC with the id {}", distributionId); - processNotification(notificationData); - } - - private void processNotification(INotificationData notificationData) { - final IDistributionClient distributionClient = cdsSdcListenerDto.getDistributionClient(); - notificationData.getServiceArtifacts() - .forEach(artifactInfo -> downloadCsarArtifacts(artifactInfo, distributionClient)); - } - - /** - * Download the TOSCA CSAR artifact and process it. - * - * @param info - Artifact information - * @param distributionClient - SDC distribution client - */ - private void downloadCsarArtifacts(IArtifactInfo info, IDistributionClient distributionClient) { - final String url = info.getArtifactURL(); - final String id = info.getArtifactUUID(); - - if (Objects.equals(info.getArtifactType(), CdsSdcListenerConfiguration.TOSCA_CSAR)) { - LOGGER.info("Trying to download the artifact from : {} and UUID is {} ", url, id); - - // Download the artifact - IDistributionClientDownloadResult result = distributionClient.download(info); - - if (!Objects.equals(result.getDistributionActionResult(), SUCCESS)) { - String errorMessage = String.format("Failed to download the artifact from : %s due to %s ", url, - result.getDistributionActionResult()); - listenerStatus.sendResponseStatusBackToSDC(cdsSdcListenerDto.getDistributionId(), - DistributionStatusEnum.COMPONENT_DONE_ERROR, errorMessage); - LOGGER.error(errorMessage); - } else { - LOGGER.info("Trying to write CSAR artifact to file with URL {} and UUID {}", url, id); - processCsarArtifact(result); - } - } - } - - public void processCsarArtifact(IDistributionClientDownloadResult result) { - Path cbaArchivePath = Paths.get(pathToStoreArchives, "cba-archive"); - Path csarArchivePath = Paths.get(pathToStoreArchives, "csar-archive"); - - // Extract and store the CSAR archive into local disk. - listenerService.extractCsarAndStore(result, csarArchivePath.toString()); - - Optional<List<File>> csarFiles = FileUtil.getFilesFromDisk(csarArchivePath); - - if (csarFiles.isPresent()) { - //Extract CBA archive from CSAR package and store it into local disk. - List<File> files = csarFiles.get(); - - if (!files.isEmpty()) { - final String archivePath = cbaArchivePath.toString(); - files.forEach(file -> listenerService.extractBluePrint(file.getAbsolutePath(), archivePath)); - files.forEach(file -> FileUtil.deleteFile(file, archivePath)); - } else { - LOGGER.error("The CSAR file is not present at this location {}", csarArchivePath); - } - } - - listenerService.saveBluePrintToCdsDatabase(cbaArchivePath, cdsSdcListenerDto.getManagedChannelForGrpc()); - } -} diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/client/CdsSdcListenerAuthClientInterceptor.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/client/CdsSdcListenerAuthClientInterceptor.java deleted file mode 100644 index bae4a3754..000000000 --- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/client/CdsSdcListenerAuthClientInterceptor.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ - -package org.onap.ccsdk.cds.cdssdclistener.client; - -import io.grpc.CallOptions; -import io.grpc.Channel; -import io.grpc.ClientCall; -import io.grpc.ClientInterceptor; -import io.grpc.ForwardingClientCall; -import io.grpc.Metadata; -import io.grpc.Metadata.Key; -import io.grpc.MethodDescriptor; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -/** - * To provide authentication with GRPC server. - */ -@ConfigurationProperties("listenerservice") -@Component -public class CdsSdcListenerAuthClientInterceptor implements ClientInterceptor { - - @Value("${listenerservice.config.authHeader}") - private String basicAuth; - - @Override - public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> methodDescriptor, - CallOptions callOptions, Channel channel) { - Key<String> authHeader = Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER); - return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>( - channel.newCall(methodDescriptor, callOptions)) { - @Override - public void start(Listener<RespT> responseListener, Metadata headers) { - headers.put(authHeader, basicAuth); - super.start(responseListener, headers); - } - }; - } -} diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/client/CdsSdcListenerClient.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/client/CdsSdcListenerClient.java deleted file mode 100644 index 8d6aca5cd..000000000 --- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/client/CdsSdcListenerClient.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ -package org.onap.ccsdk.cds.cdssdclistener.client; - -import java.util.Optional; -import org.onap.ccsdk.cds.cdssdclistener.CdsSdcListenerConfiguration; -import org.onap.ccsdk.cds.cdssdclistener.dto.CdsSdcListenerDto; -import org.onap.ccsdk.cds.cdssdclistener.CdsSdcListenerNotificationCallback; -import org.onap.ccsdk.cds.cdssdclistener.exceptions.CdsSdcListenerException; -import org.onap.sdc.api.IDistributionClient; -import org.onap.sdc.api.results.IDistributionClientResult; -import org.onap.sdc.impl.DistributionClientFactory; -import org.onap.sdc.utils.DistributionActionResultEnum; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.event.EventListener; -import org.springframework.stereotype.Component; - -@Component -@ComponentScan("org.onap.ccsdk.cds.cdssdclistener.dto") -public class CdsSdcListenerClient { - - private static Logger LOG = LoggerFactory.getLogger(CdsSdcListenerClient.class); - - @Autowired - private CdsSdcListenerConfiguration configuration; - - @Autowired - private CdsSdcListenerNotificationCallback notification; - - @Autowired - private CdsSdcListenerDto listenerDto; - - private IDistributionClient distributionClient; - - /** - * This method initializes the SDC Distribution client. - */ - @EventListener(ApplicationReadyEvent.class) - public void initSdcClient() throws CdsSdcListenerException { - LOG.info("Initialize the SDC distribution client"); - - distributionClient = Optional.of(DistributionClientFactory.createDistributionClient()) - .orElseThrow(() -> new CdsSdcListenerException("Could not able to create SDC Distribution client")); - - listenerDto.setManagedChannelForGrpc(); - - listenerDto.setDistributionClient(distributionClient); - - IDistributionClientResult result = distributionClient.init(configuration, notification); - startSdcClientBasedOnTheResult(result); - } - - private void startSdcClientBasedOnTheResult(IDistributionClientResult result) throws CdsSdcListenerException { - if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) { - throw new CdsSdcListenerException( - "SDC distribution client init failed with reason:" + result.getDistributionMessageResult()); - } - - LOG.info("Initialization of the SDC distribution client is complete"); - - // Start the client. - result = this.distributionClient.start(); - - if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) { - throw new CdsSdcListenerException( - "Startup of the SDC distribution client failed with reason: " + result.getDistributionMessageResult()); - } - } - - private void closeSdcDistributionclient() throws CdsSdcListenerException { - LOG.info("Closing SDC distribution client"); - IDistributionClientResult status = this.distributionClient.stop(); - if (status.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) { - throw new CdsSdcListenerException( - "Failed to close the SDC distribution client due to : " + status.getDistributionMessageResult()); - } - } -} diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/controller/HealthCheck.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/controller/HealthCheck.java deleted file mode 100644 index a1bb116bf..000000000 --- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/controller/HealthCheck.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ - -package org.onap.ccsdk.cds.cdssdclistener.controller; - -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.RestController; -import reactor.core.publisher.Mono; - -@RestController -@RequestMapping("/api/v1/sdclistener") -public class HealthCheck { - - @RequestMapping(path = "/healthcheck", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - Mono<String> ping() { - return Mono.just("{\"status\":\"UP\"}"); - } -} diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/dto/CdsSdcListenerDto.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/dto/CdsSdcListenerDto.java deleted file mode 100644 index 68669307e..000000000 --- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/dto/CdsSdcListenerDto.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ -package org.onap.ccsdk.cds.cdssdclistener.dto; - -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import org.onap.ccsdk.cds.cdssdclistener.client.CdsSdcListenerAuthClientInterceptor; -import org.onap.sdc.api.IDistributionClient; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -@Component -@ConfigurationProperties("listenerservice") -public class CdsSdcListenerDto { - - @Value("${listenerservice.config.grpcAddress}") - private String grpcAddress; - - @Value("${listenerservice.config.grpcPort}") - private int grpcPort; - - @Autowired - private CdsSdcListenerAuthClientInterceptor cdsSdcListenerAuthClientInterceptor; - - private IDistributionClient distributionClient; - private ManagedChannel managedChannel; - private String distributionId; - - public IDistributionClient getDistributionClient() { - return distributionClient; - } - - public void setDistributionClient(IDistributionClient distributionClient) { - this.distributionClient = distributionClient; - } - - public void setDistributionId(String id) { - this.distributionId = id; - } - - public String getDistributionId() { - return distributionId; - } - - public void setManagedChannelForGrpc() { - managedChannel = ManagedChannelBuilder.forAddress(grpcAddress, grpcPort) - .usePlaintext() - .intercept(cdsSdcListenerAuthClientInterceptor) - .build(); - } - - public ManagedChannel getManagedChannelForGrpc() { - return managedChannel; - } -} diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/exceptions/CdsSdcListenerException.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/exceptions/CdsSdcListenerException.java deleted file mode 100644 index eff5ef050..000000000 --- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/exceptions/CdsSdcListenerException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ -package org.onap.ccsdk.cds.cdssdclistener.exceptions; - -public class CdsSdcListenerException extends Exception { - - /** - * @param message The message to dump - */ - public CdsSdcListenerException(final String message) { - super(message); - } - - /** - * @param message The message to dump - * @param cause The Throwable cause object - */ - public CdsSdcListenerException(final String message, final Throwable cause) { - super(message, cause); - } -} diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcesssorHandler.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcesssorHandler.java deleted file mode 100644 index b05245392..000000000 --- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcesssorHandler.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ -package org.onap.ccsdk.cds.cdssdclistener.handler; - -import io.grpc.ManagedChannel; -import org.onap.ccsdk.cds.controllerblueprints.common.api.Status; -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementOutput; -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc; -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc.BluePrintManagementServiceBlockingStub; -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -@ConfigurationProperties("listenerservice") -@Component -public class BluePrintProcesssorHandler implements AutoCloseable { - - private static final Logger LOGGER = LoggerFactory.getLogger(BluePrintProcesssorHandler.class); - - private ManagedChannel channel; - - /** - * Sending CBA archive to CDS backend to store into its Database. - * - * @param request BluePrintManagementInput object holds CBA archive, its version and blueprints. - * @param managedChannel - ManagedChannel object helps to access the server or application end point. - * @return A response object - */ - public Status sendRequest(BluePrintUploadInput request, ManagedChannel managedChannel) { - LOGGER.info("Sending request to blueprint processor"); - - this.channel = managedChannel; - - final BluePrintManagementServiceBlockingStub syncStub = BluePrintManagementServiceGrpc.newBlockingStub(channel); - - // Send the request to CDS backend. - final BluePrintManagementOutput response = syncStub.uploadBlueprint(request); - - return response.getStatus(); - } - - @Override - public void close() { - if (channel != null) { - channel.shutdown(); - } - LOGGER.info("Stopping GRPC connection to CDS backend"); - } -} diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerService.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerService.java deleted file mode 100644 index e55aeb134..000000000 --- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerService.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ -package org.onap.ccsdk.cds.cdssdclistener.service; - -import io.grpc.ManagedChannel; -import java.nio.file.Path; -import org.onap.sdc.api.results.IDistributionClientDownloadResult; - -public interface ListenerService { - - /** - * Get the controller blueprint archive from CSAR package. - * - * @param csarArchivePath The path where CSAR archive is stored. - * @param cbaArchivePath The destination path where CBA will be stored. - */ - void extractBluePrint(String csarArchivePath, String cbaArchivePath); - - /** - * Store the Zip file into CDS database. - * - * @param path path where zip file exists. - * @param managedChannel To access the blueprint processor application end point - */ - void saveBluePrintToCdsDatabase(Path path, ManagedChannel managedChannel); - - /** - * Extract and store the csar package to local disk. - * - * @param result - IDistributionClientDownloadResult contains payload. - * @param csarArchivePath The destination path where CSAR will be stored. - */ - void extractCsarAndStore(IDistributionClientDownloadResult result, String csarArchivePath); -} diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImpl.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImpl.java deleted file mode 100644 index 1cf1a1bae..000000000 --- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImpl.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright © 2017-2019 AT&T, Bell Canada - * - * 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. - */ - -package org.onap.ccsdk.cds.cdssdclistener.service; - -import static java.nio.file.Files.walk; -import static org.onap.sdc.utils.DistributionStatusEnum.COMPONENT_DONE_ERROR; -import static org.onap.sdc.utils.DistributionStatusEnum.COMPONENT_DONE_OK; -import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Enumeration; -import java.util.List; -import java.util.Optional; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; -import org.apache.commons.io.FileUtils; -import org.apache.tomcat.util.http.fileupload.IOUtils; -import org.onap.ccsdk.cds.cdssdclistener.client.CdsSdcListenerAuthClientInterceptor; -import org.onap.ccsdk.cds.cdssdclistener.dto.CdsSdcListenerDto; -import org.onap.ccsdk.cds.cdssdclistener.handler.BluePrintProcesssorHandler; -import org.onap.ccsdk.cds.cdssdclistener.status.CdsSdcListenerStatus; -import org.onap.ccsdk.cds.cdssdclistener.util.FileUtil; -import org.onap.ccsdk.cds.controllerblueprints.common.api.Status; -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput; -import org.onap.ccsdk.cds.controllerblueprints.management.api.FileChunk; -import org.onap.sdc.api.results.IDistributionClientDownloadResult; -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.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -@Component -@ConfigurationProperties("listenerservice") -public class ListenerServiceImpl implements ListenerService { - - @Autowired - private BluePrintProcesssorHandler bluePrintProcesssorHandler; - - @Autowired - private CdsSdcListenerAuthClientInterceptor cdsSdcListenerAuthClientInterceptor; - - @Autowired - private CdsSdcListenerStatus listenerStatus; - - @Autowired - private CdsSdcListenerDto cdsSdcListenerDto; - - @Value("${listenerservice.config.grpcAddress}") - private String grpcAddress; - - @Value("${listenerservice.config.grpcPort}") - private int grpcPort; - - private static final String CBA_ZIP_PATH = "Artifacts/Resources/[a-zA-Z0-9-_]+/Deployment/CONTROLLER_BLUEPRINT_ARCHIVE/[a-zA-Z0-9-_]+[.]zip"; - private static final int SUCCESS_CODE = 200; - private static final Logger LOGGER = LoggerFactory.getLogger(ListenerServiceImpl.class); - - @Override - public void extractBluePrint(String csarArchivePath, String cbaArchivePath) { - Path cbaStorageDir = getStorageDirectory(cbaArchivePath); - try (ZipFile zipFile = new ZipFile(csarArchivePath)) { - Enumeration<? extends ZipEntry> entries = zipFile.entries(); - while (entries.hasMoreElements()) { - ZipEntry entry = entries.nextElement(); - String fileName = entry.getName(); - if (Pattern.matches(CBA_ZIP_PATH, fileName)) { - final String cbaArchiveName = Paths.get(fileName).getFileName().toString(); - LOGGER.info("Storing the CBA archive {}", cbaArchiveName); - storeBluePrint(zipFile, cbaArchiveName, cbaStorageDir, entry); - } - } - - } catch (Exception e) { - LOGGER.error("Failed to extract blueprint {}", e); - } - } - - private void storeBluePrint(ZipFile zipFile, String fileName, Path cbaArchivePath, ZipEntry entry) { - Path targetLocation = cbaArchivePath.resolve(fileName); - LOGGER.info("The target location for zip file is {}", targetLocation); - File targetZipFile = new File(targetLocation.toString()); - - try { - targetZipFile.createNewFile(); - } catch (IOException e) { - LOGGER.error("Could not able to create file {}", targetZipFile, e); - } - - try (InputStream inputStream = zipFile.getInputStream(entry); OutputStream out = new FileOutputStream( - targetZipFile)) { - IOUtils.copy(inputStream, out); - LOGGER.info("Successfully store the CBA archive {} at this location", targetZipFile); - } catch (Exception e) { - LOGGER.error("Failed to put zip file into target location {}, {}", targetLocation, e); - } - } - - @Override - public void saveBluePrintToCdsDatabase(Path cbaArchivePath, ManagedChannel channel) { - Optional<List<File>> zipFiles = FileUtil.getFilesFromDisk(cbaArchivePath); - zipFiles.ifPresent(files -> prepareRequestForCdsBackend(files, channel, cbaArchivePath.toString())); - } - - @Override - public void extractCsarAndStore(IDistributionClientDownloadResult result, String csarArchivePath) { - - // Create CSAR storage directory - Path csarStorageDir = getStorageDirectory(csarArchivePath); - byte[] payload = result.getArtifactPayload(); - String csarFileName = result.getArtifactFilename(); - Path targetLocation = csarStorageDir.resolve(csarFileName); - - LOGGER.info("The target location for the CSAR file is {}", targetLocation); - - File targetCsarFile = new File(targetLocation.toString()); - - try (FileOutputStream outFile = new FileOutputStream(targetCsarFile)) { - outFile.write(payload, 0, payload.length); - } catch (Exception e) { - LOGGER.error("Failed to put CSAR file into target location {}, {}", targetLocation, e); - } - } - - private Path getStorageDirectory(String path) { - Path fileStorageLocation = Paths.get(path).toAbsolutePath().normalize(); - - if (!fileStorageLocation.toFile().exists()) { - try { - return Files.createDirectories(fileStorageLocation); - } catch (IOException e) { - LOGGER.error("Fail to create directory {}, {}", e, fileStorageLocation); - } - } - return fileStorageLocation; - } - - private void prepareRequestForCdsBackend(List<File> files, ManagedChannel managedChannel, String path) { - final String distributionId = cdsSdcListenerDto.getDistributionId(); - - files.forEach(zipFile -> { - try { - final BluePrintUploadInput request = generateBluePrintUploadInputBuilder(zipFile); - - // Send request to CDS Backend. - final Status responseStatus = bluePrintProcesssorHandler.sendRequest(request, managedChannel); - - if (responseStatus.getCode() != SUCCESS_CODE) { - final String errorMessage = String.format("Failed to store the CBA archive into CDS DB due to %s", - responseStatus.getErrorMessage()); - listenerStatus.sendResponseStatusBackToSDC(distributionId, - COMPONENT_DONE_ERROR, errorMessage); - LOGGER.error(errorMessage); - - } else { - LOGGER.info(responseStatus.getMessage()); - listenerStatus.sendResponseStatusBackToSDC(distributionId, - COMPONENT_DONE_OK, null); - } - - } catch (Exception e) { - final String errorMessage = String.format("Failure due to %s", e.getMessage()); - listenerStatus.sendResponseStatusBackToSDC(distributionId, COMPONENT_DONE_ERROR, errorMessage); - LOGGER.error("Failure due to {}", e); - } finally { - FileUtil.deleteFile(zipFile, path); - } - }); - } - - private BluePrintUploadInput generateBluePrintUploadInputBuilder(File file) throws IOException { - byte[] bytes = FileUtils.readFileToByteArray(file); - FileChunk fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(bytes)).build(); - - return BluePrintUploadInput.newBuilder() - .setFileChunk(fileChunk) - .build(); - } -} diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/status/CdsSdcListenerStatus.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/status/CdsSdcListenerStatus.java deleted file mode 100644 index 60d3127f9..000000000 --- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/status/CdsSdcListenerStatus.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ -package org.onap.ccsdk.cds.cdssdclistener.status; - -import static org.onap.sdc.utils.DistributionActionResultEnum.SUCCESS; -import java.util.Objects; -import org.onap.ccsdk.cds.cdssdclistener.dto.CdsSdcListenerDto; -import org.onap.ccsdk.cds.cdssdclistener.util.BuilderUtil; -import org.onap.sdc.api.IDistributionClient; -import org.onap.sdc.api.consumer.IFinalDistrStatusMessage; -import org.onap.sdc.api.results.IDistributionClientResult; -import org.onap.sdc.impl.DistributionClientImpl; -import org.onap.sdc.utils.DistributionStatusEnum; -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.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.stereotype.Component; - -@Component -@ConfigurationProperties("listenerservice") -@ComponentScan("org.onap.ccsdk.cds.cdssdclistener.dto") -public class CdsSdcListenerStatus { - - private static final Logger LOGGER = LoggerFactory.getLogger(CdsSdcListenerStatus.class); - private static final String COMPONENT_NAME = "cds"; - - @Value("${listenerservice.config.consumerId}") - private String consumerId; - - @Autowired - private CdsSdcListenerDto cdsSdcListenerDto; - - /** - * Send the response back to SDC. - * - * @param distributionID SDC Distribution ID - * @param status Distribution status - * @param errorReason Reason of failure - */ - public void sendResponseStatusBackToSDC(String distributionID, DistributionStatusEnum status, String errorReason) { - - final IDistributionClient distributionClient = cdsSdcListenerDto.getDistributionClient(); - - IFinalDistrStatusMessage finalDistribution = new BuilderUtil<>(new DistributionStatusMessage()) - .build(builder -> { - builder.distributionID = distributionID; - builder.status = status; - builder.consumerID = consumerId; - builder.componentName = COMPONENT_NAME; - }).create(); - - if (errorReason == null) { - checkResponseStatusFromSdc(distributionClient.sendFinalDistrStatus(finalDistribution)); - } else { - checkResponseStatusFromSdc(distributionClient.sendFinalDistrStatus(finalDistribution, errorReason)); - } - } - - private void checkResponseStatusFromSdc(IDistributionClientResult result) { - if (!Objects.equals(result.getDistributionActionResult(), SUCCESS)) { - LOGGER.error("SDC failed to receive the response from cds-sdc listener due to {}", - result.getDistributionMessageResult()); - } else { - LOGGER.info("SDC successfully received the response"); - } - } -} diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/status/DistributionStatusMessage.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/status/DistributionStatusMessage.java deleted file mode 100644 index 676c85c98..000000000 --- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/status/DistributionStatusMessage.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ -package org.onap.ccsdk.cds.cdssdclistener.status; - -import org.onap.sdc.api.consumer.IFinalDistrStatusMessage; -import org.onap.sdc.utils.DistributionStatusEnum; - -public class DistributionStatusMessage implements IFinalDistrStatusMessage { - - public String componentName; - - public String consumerID; - - public String distributionID; - - public DistributionStatusEnum status; - - @Override - public String getDistributionID() { - return distributionID; - } - - @Override - public long getTimestamp() { - return 0; - } - - @Override - public DistributionStatusEnum getStatus() { - return status; - } - - @Override - public String getConsumerID() { - return consumerID; - } - - @Override - public String getComponentName() { - return componentName; - } -} diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/util/BuilderUtil.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/util/BuilderUtil.java deleted file mode 100644 index 4df545c82..000000000 --- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/util/BuilderUtil.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2019 Bell Canada. All rights reserved. - * - * NOTICE: All the intellectual and technical concepts contained herein are - * proprietary to Bell Canada and are protected by trade secret or copyright law. - * Unauthorized copying of this file, via any medium is strictly prohibited. - */ -package org.onap.ccsdk.cds.cdssdclistener.util; - -import java.util.function.Consumer; - -/** - * A generic builder for constructing an object. - * - * @param <T> - Any object - */ -public class BuilderUtil<T> { - - private final T object; - - public BuilderUtil(T instance) { - this.object = instance; - } - - public BuilderUtil<T> build(Consumer<T> consumer) { - consumer.accept(object); - return this; - } - - public T create() { - return object; - } -} diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/util/FileUtil.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/util/FileUtil.java deleted file mode 100644 index 11f4eade1..000000000 --- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/util/FileUtil.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2019 Bell Canada. All rights reserved. - * - * NOTICE: All the intellectual and technical concepts contained herein are - * proprietary to Bell Canada and are protected by trade secret or copyright law. - * Unauthorized copying of this file, via any medium is strictly prohibited. - */ - -package org.onap.ccsdk.cds.cdssdclistener.util; - -import static java.nio.file.Files.walk; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.commons.io.FileUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class FileUtil { - private static final Logger LOGGER = LoggerFactory.getLogger(FileUtils.class); - - private FileUtil() { - - } - - /** - * Delete the file. - * - * @param file - Given file - * @param path - Given path - */ - public static void deleteFile(File file, String path) { - boolean value = file.delete(); - if (!value) { - LOGGER.error("Failed to delete the file {} at the location {}", file, path); - } - } - - /** - * Extract files from the given path - * - * @param path where files reside. - * @return list of files. - */ - public static Optional<List<File>> getFilesFromDisk(Path path) { - try (Stream<Path> fileTree = walk(path)) { - // Get the list of files from the path - return Optional.of(fileTree.filter(Files::isRegularFile) - .map(Path::toFile) - .collect(Collectors.toList())); - } catch (IOException e) { - LOGGER.error("Failed to find the file due to", e); - } - return Optional.empty(); - } -} diff --git a/ms/cds-sdc-listener/application/src/main/resources/application.yml b/ms/cds-sdc-listener/application/src/main/resources/application.yml deleted file mode 100644 index b3f8443eb..000000000 --- a/ms/cds-sdc-listener/application/src/main/resources/application.yml +++ /dev/null @@ -1,27 +0,0 @@ -listenerservice: - config: - asdcAddress: ${asdcAddress:localhost:8443} - messageBusAddress: ${messageBusAddress:localhost} - user: ${sdcusername:vid} - password: ${password:Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U} - pollingInterval: ${pollingInterval:15} - pollingTimeout: ${pollingTimeout:60} - relevantArtifactTypes: ${relevantArtifactTypes:TOSCA_CSAR} - consumerGroup: ${consumerGroup:cds-id-local} - environmentName: ${environmentName:AUTO} - consumerId: ${consumerId:cds-id-local} - keyStorePassword: ${keyStorePassword} - keyStorePath: ${keyStorePath} - activateServerTLSAuth : ${activateServerTLSAuth:false} - isUseHttpsWithDmaap: ${isUseHttpsWithDmaap:false} - archivePath: ${archivePath:/opt/app/onap/cds-sdc-listener/} - grpcAddress: ${grpcAddress:localhost} - grpcPort: ${grpcPort:9111} - authHeader: ${authHeader:Basic Y2NzZGthcHBzOmNjc2RrYXBwcw==} -#port needed by Liveness probe -server: - port: ${healthcheckPort:9000} -#set spring.main.web-environment=false if you want to NOT to open a port for healthcheck. -spring: - main: - web-environment: ${sprintWebListenerEnabled:true} diff --git a/ms/cds-sdc-listener/application/src/main/resources/logback.xml b/ms/cds-sdc-listener/application/src/main/resources/logback.xml deleted file mode 100644 index b26cbcbe4..000000000 --- a/ms/cds-sdc-listener/application/src/main/resources/logback.xml +++ /dev/null @@ -1,33 +0,0 @@ -<!-- -Copyright (C) 2019 Bell Canada - -Unless otherwise specified, all software contained herein is licensed -under the Apache License, Version 2.0 (the License); -you may not use this software 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. ---> - -<configuration> - <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> - <encoder> - <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> - </encoder> - </appender> - - <root level="info"> - <appender-ref ref="STDOUT"/> - </root> - - <logger name="org.springframework" level="info"/> - <logger name="org.springframework.web" level="info"/> - <logger name="org.onap.ccsdk.cds" level="info"/> - -</configuration> diff --git a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerClientTest.java b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerClientTest.java deleted file mode 100644 index e980c24c6..000000000 --- a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerClientTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ -package org.onap.ccsdk.cds.cdssdclistener; - -import mockit.Expectations; -import mockit.Injectable; -import mockit.Mock; -import mockit.MockUp; -import mockit.Tested; -import mockit.VerificationsInOrder; -import mockit.integration.junit4.JMockit; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.ccsdk.cds.cdssdclistener.client.CdsSdcListenerClient; -import org.onap.ccsdk.cds.cdssdclistener.dto.CdsSdcListenerDto; -import org.onap.ccsdk.cds.cdssdclistener.exceptions.CdsSdcListenerException; -import org.onap.sdc.api.IDistributionClient; -import org.onap.sdc.api.results.IDistributionClientResult; -import org.onap.sdc.impl.DistributionClientFactory; -import org.onap.sdc.impl.DistributionClientResultImpl; -import org.onap.sdc.utils.DistributionActionResultEnum; - -@RunWith(JMockit.class) -public class CdsSdcListenerClientTest { - - @Tested - private CdsSdcListenerClient cdsSdcListenerClient; - - @Test - public void testInitCdsClientSuccesfully(@Injectable IDistributionClient distributionClient, - @Injectable CdsSdcListenerConfiguration configuration, - @Injectable CdsSdcListenerNotificationCallback notification, - @Injectable CdsSdcListenerDto cdsSdcListenerDto) throws CdsSdcListenerException { - - //Arrange - new MockUp<DistributionClientFactory>() { - @Mock - public IDistributionClient createDistributionClient() { - return distributionClient; - } - }; - - new Expectations() {{ - distributionClient.init(configuration, notification); - result = getResult(); - }}; - - new Expectations() {{ - distributionClient.start(); - result = getResult(); - }}; - - // Act - cdsSdcListenerClient.initSdcClient(); - - // Verify - new VerificationsInOrder() {{ - distributionClient.init(configuration, notification); - distributionClient.start(); - }}; - } - - public IDistributionClientResult getResult() { - return new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS, - DistributionActionResultEnum.SUCCESS.name()); - } -} diff --git a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfigurationTest.java b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfigurationTest.java deleted file mode 100644 index f940db2aa..000000000 --- a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfigurationTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ -package org.onap.ccsdk.cds.cdssdclistener; - -import static org.junit.Assert.assertEquals; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@EnableConfigurationProperties(CdsSdcListenerConfiguration.class) -@SpringBootTest(classes = {CdsSdcListenerConfigurationTest.class}) -public class CdsSdcListenerConfigurationTest { - - @Autowired - private CdsSdcListenerConfiguration listenerConfiguration; - - @Test - public void testCdsSdcListenerConfiguration() { - assertEquals(listenerConfiguration.getAsdcAddress(), "localhost:8443"); - assertEquals(listenerConfiguration.getMsgBusAddress().stream().findFirst().get(), "localhost"); - assertEquals(listenerConfiguration.getUser(), "vid"); - assertEquals(listenerConfiguration.getPassword(), "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U"); - assertEquals(listenerConfiguration.getPollingInterval(), 15); - assertEquals(listenerConfiguration.getPollingTimeout(), 60); - assertEquals(listenerConfiguration.getRelevantArtifactTypes().stream().findFirst().get(), "TOSCA_CSAR"); - assertEquals(listenerConfiguration.getConsumerGroup(), "cds-id-local"); - assertEquals(listenerConfiguration.getEnvironmentName(), "AUTO"); - assertEquals(listenerConfiguration.getConsumerID(), "cds-id-local"); - assertEquals(listenerConfiguration.activateServerTLSAuth(), false); - } -} diff --git a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcessorHandlerTest.java b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcessorHandlerTest.java deleted file mode 100644 index f700a7dd2..000000000 --- a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcessorHandlerTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ -package org.onap.ccsdk.cds.cdssdclistener.handler; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; -import io.grpc.inprocess.InProcessChannelBuilder; -import io.grpc.inprocess.InProcessServerBuilder; -import io.grpc.stub.StreamObserver; -import io.grpc.testing.GrpcCleanupRule; -import java.io.File; -import java.io.IOException; -import java.nio.file.Paths; -import org.apache.commons.io.FileUtils; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.ccsdk.cds.cdssdclistener.client.CdsSdcListenerAuthClientInterceptor; -import org.onap.ccsdk.cds.controllerblueprints.common.api.Status; -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementOutput; -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc.BluePrintManagementServiceImplBase; -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput; -import org.onap.ccsdk.cds.controllerblueprints.management.api.FileChunk; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@EnableConfigurationProperties({BluePrintProcesssorHandler.class, CdsSdcListenerAuthClientInterceptor.class}) -@SpringBootTest(classes = {BluePrintProcessorHandlerTest.class}) -public class BluePrintProcessorHandlerTest { - - @Autowired - private BluePrintProcesssorHandler bluePrintProcesssorHandler; - - @Autowired - private CdsSdcListenerAuthClientInterceptor cdsSdcListenerAuthClientInterceptor; - - @Rule - public GrpcCleanupRule grpcCleanup = new GrpcCleanupRule(); - - private static final String CBA_ARCHIVE = "src/test/resources/testcba.zip"; - private static final String SUCCESS_MSG = "Successfully uploaded CBA"; - private static final int SUCCESS_CODE = 200; - private ManagedChannel channel; - - @Before - public void setUp() throws IOException { - final BluePrintManagementServiceImplBase serviceImplBase = new BluePrintManagementServiceImplBase() { - @Override - public void uploadBlueprint(BluePrintUploadInput request, - StreamObserver<BluePrintManagementOutput> responseObserver) { - responseObserver.onNext(getBluePrintManagementOutput()); - responseObserver.onCompleted(); - } - }; - - // Generate server name. - String serverName = InProcessServerBuilder.generateName(); - - // Create a server, add service, start, and register. - grpcCleanup.register( - InProcessServerBuilder.forName(serverName).addService(serviceImplBase).directExecutor().build().start()); - - // Create a client channel. - channel = grpcCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build()); - } - - @Test - public void testApplicationEndPointSucess() throws IOException { - // Arrange - BluePrintUploadInput request = generateRequest(); - - // Act - Status output = bluePrintProcesssorHandler.sendRequest(request, channel); - - // Verify - assertEquals(SUCCESS_CODE, output.getCode()); - assertTrue(output.getMessage().contains(SUCCESS_MSG)); - } - - private BluePrintUploadInput generateRequest() throws IOException { - File file = Paths.get(CBA_ARCHIVE).toFile(); - byte[] bytes = FileUtils.readFileToByteArray(file); - FileChunk fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(bytes)).build(); - - return BluePrintUploadInput.newBuilder().setFileChunk(fileChunk).build(); - } - - private BluePrintManagementOutput getBluePrintManagementOutput() { - return BluePrintManagementOutput.newBuilder() - .setStatus(Status.newBuilder().setMessage(SUCCESS_MSG).setCode(200).build()) - .build(); - } -} diff --git a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImplTest.java b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImplTest.java deleted file mode 100644 index 359ee6cc4..000000000 --- a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImplTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * 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. - */ -package org.onap.ccsdk.cds.cdssdclistener.service; - -import static junit.framework.TestCase.assertTrue; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.apache.commons.io.FileUtils; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.onap.ccsdk.cds.cdssdclistener.CdsSdcListenerConfiguration; -import org.onap.ccsdk.cds.cdssdclistener.client.CdsSdcListenerAuthClientInterceptor; -import org.onap.ccsdk.cds.cdssdclistener.dto.CdsSdcListenerDto; -import org.onap.ccsdk.cds.cdssdclistener.handler.BluePrintProcesssorHandler; -import org.onap.ccsdk.cds.cdssdclistener.status.CdsSdcListenerStatus; -import org.onap.sdc.api.results.IDistributionClientDownloadResult; -import org.onap.sdc.impl.mock.DistributionClientResultStubImpl; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@EnableConfigurationProperties({CdsSdcListenerAuthClientInterceptor.class, - BluePrintProcesssorHandler.class, CdsSdcListenerDto.class, ListenerServiceImpl.class, CdsSdcListenerStatus.class, - CdsSdcListenerConfiguration.class}) -@SpringBootTest(classes = {ListenerServiceImplTest.class}) -public class ListenerServiceImplTest { - - private static final String CSAR_SAMPLE = "src/test/resources/service-Testsvc140.csar"; - private static final String ZIP_FILE = ".zip"; - private static final String CSAR_FILE = ".csar"; - private String csarArchivePath; - private Path tempDirectoryPath; - - @Rule - public TemporaryFolder folder = new TemporaryFolder(); - - @Autowired - private ListenerServiceImpl listenerService; - - @Before - public void setup() { - csarArchivePath = folder.getRoot().toString(); - tempDirectoryPath = Paths.get(csarArchivePath, "cds-sdc-listener-test"); - } - @Test - public void extractBluePrintSuccessfully() throws IOException { - // Act - listenerService.extractBluePrint(CSAR_SAMPLE, tempDirectoryPath.toString()); - - // Verify - String result = checkFileExists(tempDirectoryPath); - assertTrue(result.contains(ZIP_FILE)); - } - - @Test - public void storeCsarArtifactToFileSuccessfully() throws IOException { - // Arrange - DistributionClientDownloadResultStubImpl resultStub = new DistributionClientDownloadResultStubImpl(); - - // Act - listenerService.extractCsarAndStore(resultStub, tempDirectoryPath.toString()); - - // Verify - String result = checkFileExists(tempDirectoryPath); - assertTrue(result.contains(CSAR_FILE)); - } - - private String checkFileExists(Path path) throws IOException { - return Files.walk(path) - .filter(Files::isRegularFile) - .map(Path::toFile) - .findAny() - .get() - .getName(); - } - - public byte[] convertFileToByteArray(File file) { - try { - return FileUtils.readFileToByteArray(file); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } - - public class DistributionClientDownloadResultStubImpl extends DistributionClientResultStubImpl implements - IDistributionClientDownloadResult { - - public DistributionClientDownloadResultStubImpl() { - } - - public byte[] getArtifactPayload() { - File file = Paths.get(CSAR_SAMPLE).toFile(); - return convertFileToByteArray(file); - } - - public String getArtifactName() { - return "MackArtifactName"; - } - - public String getArtifactFilename() { - return "MackArtifactName.csar"; - } - } -} diff --git a/ms/cds-sdc-listener/application/src/test/resources/service-Testsvc140.csar b/ms/cds-sdc-listener/application/src/test/resources/service-Testsvc140.csar Binary files differdeleted file mode 100644 index 4aa0de72b..000000000 --- a/ms/cds-sdc-listener/application/src/test/resources/service-Testsvc140.csar +++ /dev/null diff --git a/ms/cds-sdc-listener/application/src/test/resources/testcba.zip b/ms/cds-sdc-listener/application/src/test/resources/testcba.zip Binary files differdeleted file mode 100644 index c886fe6bc..000000000 --- a/ms/cds-sdc-listener/application/src/test/resources/testcba.zip +++ /dev/null |