diff options
author | liboNet <libo.zhu@intel.com> | 2019-03-27 00:49:32 +0800 |
---|---|---|
committer | liboNet <libo.zhu@intel.com> | 2019-03-27 09:34:10 +0800 |
commit | f0944b0dffa4904161cf40d5da13d5d2d34b0cbe (patch) | |
tree | dcb176160f96f35139cfc603db5cc36b755f3d60 /artifactbroker/plugins/reception-plugins | |
parent | 7e291b8ebf625519d44c240cbee83521317d52ee (diff) |
add SDC client and reception handle
. add reception framework wraps handle and subplug interface
. add plugins include sdc handler now.
. add forward acts the post interface for specified item like artifact
. add model acts for the sepcifeid item like CSAR
. update pom.xml and package/pom.xml to includes all submodules
. Fix the compile issue by typo and change groupid to framework
Change-Id: Idbff0ca612045c6ee52ba23cd305f2764c9600f8
Issue-ID: MULTICLOUD-514
Signed-off-by: liboNet <libo.zhu@intel.com>
Diffstat (limited to 'artifactbroker/plugins/reception-plugins')
29 files changed, 2726 insertions, 0 deletions
diff --git a/artifactbroker/plugins/reception-plugins/pom.xml b/artifactbroker/plugins/reception-plugins/pom.xml new file mode 100644 index 0000000..d6a8ccc --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/pom.xml @@ -0,0 +1,55 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 2018 Ericsson. 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. + + SPDX-License-Identifier: Apache-2.0 + ============LICENSE_END========================================================= +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.multicloud.framework</groupId> + <artifactId>multicloud-framework-artifactbroker-plugins</artifactId> + <version>1.3.0-SNAPSHOT</version> + </parent> + + <artifactId>multicloud-framework-artifactbroker-reception-plugins</artifactId> + <name>${project.artifactId}</name> + <description>[${project.parent.artifactId}] module contains plugins for reception of policies.</description> + + <dependencies> + <dependency> + <groupId>org.onap.multicloud.framework</groupId> + <artifactId>multicloud-framework-artifactbroker-reception</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.sdc.sdc-tosca</groupId> + <artifactId>sdc-tosca</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.onap.sdc.sdc-distribution-client</groupId> + <artifactId>sdc-distribution-client</artifactId> + <version>1.3.0</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> +</project> diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/ComponentDoneStatusMessage.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/ComponentDoneStatusMessage.java new file mode 100644 index 0000000..581681b --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/ComponentDoneStatusMessage.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import org.onap.sdc.api.consumer.IComponentDoneStatusMessage; +import org.onap.sdc.utils.DistributionStatusEnum; + +/** + * This class represents the component done status of the distribution service. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public class ComponentDoneStatusMessage implements IComponentDoneStatusMessage { + + private String consumerId; + private String distributionId; + private DistributionStatusEnum distributionStatus; + private long timestamp; + + /** + * Constructor for instantiating {@link ComponentDoneStatusMessage} class. + * + * @param messageBuilder the message builder + */ + public ComponentDoneStatusMessage(final ComponentDoneStatusMessageBuilder messageBuilder) { + this.consumerId = messageBuilder.getConsumerId(); + this.distributionId = messageBuilder.getDistributionId(); + this.distributionStatus = messageBuilder.getDistributionStatus(); + this.timestamp = messageBuilder.getTimestamp(); + } + + @Override + public DistributionStatusEnum getStatus() { + return distributionStatus; + } + + @Override + public String getDistributionID() { + return distributionId; + } + + @Override + public long getTimestamp() { + return timestamp; + } + + @Override + public String getConsumerID() { + return consumerId; + } + + @Override + public String getComponentName() { + return "POLICY"; + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/ComponentDoneStatusMessageBuilder.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/ComponentDoneStatusMessageBuilder.java new file mode 100644 index 0000000..567ae8d --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/ComponentDoneStatusMessageBuilder.java @@ -0,0 +1,112 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import org.onap.sdc.utils.DistributionStatusEnum; + +/** + * This class builds an instance of {@link ComponentDoneStatusMessage} class. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public class ComponentDoneStatusMessageBuilder { + + private String consumerId; + private String distributionId; + private DistributionStatusEnum distributionStatus; + private long timestamp; + + /** + * Returns consumer id of this {@link ComponentDoneStatusMessageBuilder} instance. + * + * @return the consumerId + */ + public String getConsumerId() { + return consumerId; + } + + /** + * Returns distribution id of this {@link ComponentDoneStatusMessageBuilder} instance. + * + * @return the distributionId + */ + public String getDistributionId() { + return distributionId; + } + + /** + * Returns distribution status of this {@link ComponentDoneStatusMessageBuilder} instance. + * + * @return the distributionStatus + */ + public DistributionStatusEnum getDistributionStatus() { + return distributionStatus; + } + + /** + * Returns time of this {@link ComponentDoneStatusMessageBuilder} instance. + * + * @return the timestamp + */ + public long getTimestamp() { + return timestamp; + } + + /** + * Set consumer id url to this {@link ComponentDoneStatusMessageBuilder} instance. + * + * @param consumerId the consumerId to set + */ + public ComponentDoneStatusMessageBuilder setConsumerId(final String consumerId) { + this.consumerId = consumerId; + return this; + } + + /** + * Set distribution id to this {@link ComponentDoneStatusMessageBuilder} instance. + * + * @param distributionId the distributionId to set + */ + public ComponentDoneStatusMessageBuilder setDistributionId(final String distributionId) { + this.distributionId = distributionId; + return this; + } + + /** + * Set distribution status to this {@link ComponentDoneStatusMessageBuilder} instance. + * + * @param distributionStatus the distributionStatus to set + */ + public ComponentDoneStatusMessageBuilder setDistributionStatus(final DistributionStatusEnum distributionStatus) { + this.distributionStatus = distributionStatus; + return this; + } + + /** + * Set time to this {@link ComponentDoneStatusMessageBuilder} instance. + * + * @param timestamp the timestamp to set + */ + public ComponentDoneStatusMessageBuilder setTimestamp(final long timestamp) { + this.timestamp = timestamp; + return this; + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/DistributionStatusMessage.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/DistributionStatusMessage.java new file mode 100644 index 0000000..436c061 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/DistributionStatusMessage.java @@ -0,0 +1,77 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import org.onap.sdc.api.consumer.IDistributionStatusMessage; +import org.onap.sdc.utils.DistributionStatusEnum; + +/** + * This class represents the distribution status of the distribution service. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public class DistributionStatusMessage implements IDistributionStatusMessage { + + private String artifactUrl; + private String consumerId; + private String distributionId; + private DistributionStatusEnum distributionStatus; + private long timestamp; + + /** + * Constructor for instantiating {@link DistributionStatusMessage} class. + * + * @param messageBuilder the message builder + */ + public DistributionStatusMessage(final DistributionStatusMessageBuilder messageBuilder) { + this.artifactUrl = messageBuilder.getArtifactUrl(); + this.consumerId = messageBuilder.getConsumerId(); + this.distributionId = messageBuilder.getDistributionId(); + this.distributionStatus = messageBuilder.getDistributionStatus(); + this.timestamp = messageBuilder.getTimestamp(); + } + + @Override + public String getArtifactURL() { + return artifactUrl; + } + + @Override + public String getConsumerID() { + return consumerId; + } + + @Override + public String getDistributionID() { + return distributionId; + } + + @Override + public DistributionStatusEnum getStatus() { + return distributionStatus; + } + + @Override + public long getTimestamp() { + return timestamp; + } + +} diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/DistributionStatusMessageBuilder.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/DistributionStatusMessageBuilder.java new file mode 100644 index 0000000..b83a768 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/DistributionStatusMessageBuilder.java @@ -0,0 +1,132 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import org.onap.sdc.utils.DistributionStatusEnum; + +/** + * This class builds an instance of {@link DistributionStatusMessage} class. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public class DistributionStatusMessageBuilder { + + private String artifactUrl; + private String consumerId; + private String distributionId; + private DistributionStatusEnum distributionStatus; + private long timestamp; + + /** + * Returns artifact url of this {@link DistributionStatusMessageBuilder} instance. + * + * @return the artifactUrl + */ + public String getArtifactUrl() { + return artifactUrl; + } + + /** + * Returns consumer id of this {@link DistributionStatusMessageBuilder} instance. + * + * @return the consumerId + */ + public String getConsumerId() { + return consumerId; + } + + /** + * Returns distribution id of this {@link DistributionStatusMessageBuilder} instance. + * + * @return the distributionId + */ + public String getDistributionId() { + return distributionId; + } + + /** + * Returns distribution status of this {@link DistributionStatusMessageBuilder} instance. + * + * @return the distributionStatus + */ + public DistributionStatusEnum getDistributionStatus() { + return distributionStatus; + } + + /** + * Returns time of this {@link DistributionStatusMessageBuilder} instance. + * + * @return the timestamp + */ + public long getTimestamp() { + return timestamp; + } + + /** + * Set artifact url to this {@link DistributionStatusMessageBuilder} instance. + * + * @param artifactUrl the artifactUrl to set + */ + public DistributionStatusMessageBuilder setArtifactUrl(final String artifactUrl) { + this.artifactUrl = artifactUrl; + return this; + } + + /** + * Set consumer id url to this {@link DistributionStatusMessageBuilder} instance. + * + * @param consumerId the consumerId to set + */ + public DistributionStatusMessageBuilder setConsumerId(final String consumerId) { + this.consumerId = consumerId; + return this; + } + + /** + * Set distribution id to this {@link DistributionStatusMessageBuilder} instance. + * + * @param distributionId the distributionId to set + */ + public DistributionStatusMessageBuilder setDistributionId(final String distributionId) { + this.distributionId = distributionId; + return this; + } + + /** + * Set distribution status to this {@link DistributionStatusMessageBuilder} instance. + * + * @param distributionStatus the distributionStatus to set + */ + public DistributionStatusMessageBuilder setDistributionStatus(final DistributionStatusEnum distributionStatus) { + this.distributionStatus = distributionStatus; + return this; + } + + /** + * Set time to this {@link DistributionStatusMessageBuilder} instance. + * + * @param timestamp the timestamp to set + */ + public DistributionStatusMessageBuilder setTimestamp(final long timestamp) { + this.timestamp = timestamp; + return this; + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java new file mode 100644 index 0000000..941cdd6 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java @@ -0,0 +1,120 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel Corp. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE; + +import java.io.File; +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.WatchEvent; +import java.nio.file.WatchKey; +import java.nio.file.WatchService; + +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; + +import org.onap.policy.common.parameters.ParameterService; +import org.onap.policy.distribution.model.Csar; +import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; +import org.onap.policy.distribution.reception.handling.AbstractReceptionHandler; + +/** + * Handles reception of inputs from File System which can be used to decode policies. + */ +public class FileSystemReceptionHandler extends AbstractReceptionHandler { + private boolean running = false; + private static final Logger LOGGER = FlexLogger.getLogger(FileSystemReceptionHandler.class); + + @Override + protected void initializeReception(final String parameterGroupName) { + LOGGER.debug("FileSystemReceptionHandler init..."); + try { + final FileSystemReceptionHandlerConfigurationParameterGroup handlerParameters = + ParameterService.get(parameterGroupName); + main(handlerParameters.getWatchPath()); + } catch (final Exception ex) { + LOGGER.error(ex); + } + running = false; + LOGGER.debug("FileSystemReceptionHandler main loop exited..."); + } + + @Override + public void destroy() { + // Tear down subscription etc + running = false; + } + + public boolean isRunning() { + return running; + } + + /** + * Main entry point. + * + * @param watchPath Path to watch + */ + public void main(String watchPath) throws IOException { + try (final WatchService watcher = FileSystems.getDefault().newWatchService()) { + final Path dir = Paths.get(watchPath); + dir.register(watcher, ENTRY_CREATE); + LOGGER.debug("Watch Service registered for dir: " + dir.getFileName()); + startMainLoop(watcher, dir); + } catch (final InterruptedException ex) { + LOGGER.debug(ex); + Thread.currentThread().interrupt(); + } + } + + @SuppressWarnings("unchecked") + protected void startMainLoop(WatchService watcher, Path dir) throws InterruptedException { + WatchKey key; + running = true; + while (running) { + key = watcher.take(); + + for (final WatchEvent<?> event : key.pollEvents()) { + final WatchEvent<Path> ev = (WatchEvent<Path>) event; + final Path fileName = ev.context(); + LOGGER.debug("new CSAR found: " + fileName); + createPolicyInputAndCallHandler(dir.toString() + File.separator + fileName.toString()); + LOGGER.debug("CSAR complete: " + fileName); + } + final boolean valid = key.reset(); + if (!valid) { + LOGGER.error("Watch key no longer valid!"); + break; + } + } + } + + protected void createPolicyInputAndCallHandler(final String fileName) { + try { + final Csar csarObject = new Csar(fileName); + inputReceived(csarObject); + } catch (final PolicyDecodingException ex) { + LOGGER.error(ex); + } + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterBuilder.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterBuilder.java new file mode 100644 index 0000000..37a1698 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterBuilder.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel Corp. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +/** + * This class builds an instance of {@link FileSystemReceptionHandlerConfigurationParameterGroup} class. + * + */ +public class FileSystemReceptionHandlerConfigurationParameterBuilder { + + private String watchPath; + + /** + * Set watchPath to this {@link FileSystemReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param watchPath the watchPath + */ + public FileSystemReceptionHandlerConfigurationParameterBuilder setWatchPath(final String watchPath) { + this.watchPath = watchPath; + return this; + } + + + /** + * Returns the watchPath of this {@link FileSystemReceptionHandlerConfigurationParameterBuilder} instance. + * + * @return the watchPath + */ + public String getWatchPath() { + return watchPath; + } +} + + diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterGroup.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterGroup.java new file mode 100644 index 0000000..457cd5e --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterGroup.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import java.io.File; + +import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.ValidationStatus; +import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup; + +/** + * This class handles reading, parsing and validating of the Policy SDC Service Distribution parameters from Json + * format, which strictly adheres to the interface:IConfiguration, defined by SDC SDK. + */ +public class FileSystemReceptionHandlerConfigurationParameterGroup extends ReceptionHandlerConfigurationParameterGroup { + + private String watchPath; + + /** + * The constructor for instantiating {@link FileSystemReceptionHandlerConfigurationParameterGroup} class. + * + * @param builder the SDC configuration builder + */ + public FileSystemReceptionHandlerConfigurationParameterGroup( + final FileSystemReceptionHandlerConfigurationParameterBuilder builder) { + watchPath = builder.getWatchPath(); + } + + public String getWatchPath() { + return watchPath; + } + + /** + * {@inheritDoc}. + */ + @Override + public GroupValidationResult validate() { + final GroupValidationResult validationResult = new GroupValidationResult(this); + validatePathElement(validationResult, watchPath, "watchPath"); + return validationResult; + } + + + /** + * Validate the string element. + * + * @param validationResult the result object + * @param element the element to validate + * @param elementName the element name for error message + */ + private void validatePathElement(final GroupValidationResult validationResult, final String element, + final String elementName) { + boolean valid = false; + if (element != null) { + File file = new File(element); + if (file.exists() && file.isDirectory()) { + valid = true; + } + } + if (!valid) { + validationResult.setResult(elementName, ValidationStatus.INVALID, + elementName + " must be a valid directory"); + } + } +} + diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcClientHandler.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcClientHandler.java new file mode 100644 index 0000000..f69fb15 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcClientHandler.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import java.util.Timer; +import java.util.TimerTask; + +/** + * This class implements TimerTask for calling life cycle methods of SdcClient iteratively after specified interval + * until the operation is successful. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public class SdcClientHandler extends TimerTask { + + private SdcReceptionHandler sdcReceptionHandler; + private SdcClientOperationType operationType; + private Timer timer; + + public enum SdcClientOperationType { + START, STOP + } + + /** + * Constructs an instance of {@link SdcClientHandler} class. + * + * @param sdcReceptionHandler the sdcReceptionHandler + */ + public SdcClientHandler(final SdcReceptionHandler sdcReceptionHandler, final SdcClientOperationType operationType, + final long retryDelay) { + this.sdcReceptionHandler = sdcReceptionHandler; + this.operationType = operationType; + timer = new Timer(false); + timer.scheduleAtFixedRate(this, 0, retryDelay * 1000L); + } + + /** + * {@inheritDoc}. + */ + @Override + public void run() { + if (SdcClientOperationType.START.equals(operationType)) { + sdcReceptionHandler.initializeSdcClient(); + sdcReceptionHandler.startSdcClient(); + } else { + sdcReceptionHandler.stopSdcClient(); + } + } + + /** + * {@inheritDoc}. + */ + @Override + public boolean cancel() { + timer.cancel(); + return true; + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcConfiguration.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcConfiguration.java new file mode 100644 index 0000000..04c978b --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcConfiguration.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import java.util.List; +import org.onap.sdc.api.consumer.IConfiguration; + +/** + * This class represents the configurations needed for SDC Client. + * + */ +public class SdcConfiguration implements IConfiguration { + + private SdcReceptionHandlerConfigurationParameterGroup configParameters = null; + + /** + * Constructor for instantiating {@link SdcConfiguration}. + * + * @param configParameters the SDC Client configuration parameters + */ + public SdcConfiguration(final SdcReceptionHandlerConfigurationParameterGroup configParameters) { + this.configParameters = configParameters; + } + + @Override + public String getAsdcAddress() { + return configParameters.getAsdcAddress(); + } + + @Override + public List<String> getMsgBusAddress() { + return configParameters.getMessageBusAddress(); + } + + @Override + public String getUser() { + return configParameters.getUser(); + } + + @Override + public String getPassword() { + return configParameters.getPassword(); + } + + @Override + public int getPollingInterval() { + return configParameters.getPollingInterval(); + } + + @Override + public int getPollingTimeout() { + return configParameters.getPollingTimeout(); + } + + @Override + public List<String> getRelevantArtifactTypes() { + return configParameters.getArtifactTypes(); + } + + @Override + public String getConsumerGroup() { + return configParameters.getConsumerGroup(); + } + + @Override + public String getEnvironmentName() { + return configParameters.getEnvironmentName(); + } + + @Override + public String getConsumerID() { + return configParameters.getConsumerId(); + } + + @Override + public String getKeyStorePassword() { + return configParameters.getKeyStorePassword(); + } + + @Override + public String getKeyStorePath() { + return configParameters.getKeyStorePath(); + } + + @Override + public boolean activateServerTLSAuth() { + return configParameters.isActiveServerTlsAuth(); + } + + @Override + public boolean isFilterInEmptyResources() { + return configParameters.isFilterInEmptyResources(); + } + + @Override + public Boolean isUseHttpsWithDmaap() { + return configParameters.isUseHttpsWithDmaap(); + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java new file mode 100644 index 0000000..0d100f8 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java @@ -0,0 +1,382 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; +import org.onap.policy.common.parameters.ParameterService; +import org.onap.policy.distribution.model.Csar; +import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; +import org.onap.policy.distribution.reception.handling.AbstractReceptionHandler; +import org.onap.policy.distribution.reception.handling.sdc.SdcClientHandler.SdcClientOperationType; +import org.onap.policy.distribution.reception.handling.sdc.exceptions.ArtifactDownloadException; +import org.onap.policy.distribution.reception.statistics.DistributionStatisticsManager; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.consumer.IComponentDoneStatusMessage; +import org.onap.sdc.api.consumer.IDistributionStatusMessage; +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.api.results.IDistributionClientResult; +import org.onap.sdc.impl.DistributionClientFactory; +import org.onap.sdc.utils.DistributionActionResultEnum; +import org.onap.sdc.utils.DistributionStatusEnum; + +/** + * Handles reception of inputs from ONAP Service Design and Creation (SDC) from which policies may be decoded. + */ +public class SdcReceptionHandler extends AbstractReceptionHandler implements INotificationCallback { + + private static final Logger LOGGER = FlexLogger.getLogger(SdcReceptionHandler.class); + private static final String SECONDS = "Seconds"; + + private SdcReceptionHandlerStatus sdcReceptionHandlerStatus = SdcReceptionHandlerStatus.STOPPED; + private IDistributionClient distributionClient; + private SdcConfiguration sdcConfig; + private volatile int nbOfNotificationsOngoing = 0; + private int retryDelay; + private SdcClientHandler sdcClientHandler; + + private enum DistributionStatusType { + DOWNLOAD, DEPLOY + } + + @Override + protected void initializeReception(final String parameterGroupName) { + final SdcReceptionHandlerConfigurationParameterGroup handlerParameters = + ParameterService.get(parameterGroupName); + retryDelay = handlerParameters.getRetryDelay() < 30 ? 30 : handlerParameters.getRetryDelay(); + sdcConfig = new SdcConfiguration(handlerParameters); + distributionClient = createSdcDistributionClient(); + sdcClientHandler = new SdcClientHandler(this, SdcClientOperationType.START, retryDelay); + } + + @Override + public void destroy() { + if (distributionClient != null) { + sdcClientHandler = new SdcClientHandler(this, SdcClientOperationType.STOP, retryDelay); + } + } + + @Override + public void activateCallback(final INotificationData notificationData) { + LOGGER.debug("Receieved the notification from SDC with ID: " + notificationData.getDistributionID()); + changeSdcReceptionHandlerStatus(SdcReceptionHandlerStatus.BUSY); + processCsarServiceArtifacts(notificationData); + changeSdcReceptionHandlerStatus(SdcReceptionHandlerStatus.IDLE); + LOGGER.debug("Processed the notification from SDC with ID: " + notificationData.getDistributionID()); + } + + /** + * Method to change the status of this reception handler instance. + * + * @param newStatus the new status + */ + private final synchronized void changeSdcReceptionHandlerStatus(final SdcReceptionHandlerStatus newStatus) { + switch (newStatus) { + case INIT: + case STOPPED: + sdcReceptionHandlerStatus = newStatus; + break; + case IDLE: + handleIdleStatusChange(newStatus); + break; + case BUSY: + ++nbOfNotificationsOngoing; + sdcReceptionHandlerStatus = newStatus; + break; + default: + break; + } + } + + /** + * Creates an instance of {@link IDistributionClient} from {@link DistributionClientFactory}. + * + * @return the {@link IDistributionClient} instance + */ + protected IDistributionClient createSdcDistributionClient() { + return DistributionClientFactory.createDistributionClient(); + } + + /** + * Method to initialize the SDC client. + * + */ + protected void initializeSdcClient() { + + LOGGER.debug("Initializing the SDC Client..."); + if (sdcReceptionHandlerStatus != SdcReceptionHandlerStatus.STOPPED) { + LOGGER.error("The SDC Client is already initialized"); + return; + } + final IDistributionClientResult clientResult = distributionClient.init(sdcConfig, this); + if (!clientResult.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) { + LOGGER.error("SDC client initialization failed with reason:" + clientResult.getDistributionMessageResult() + + ". Initialization will be retried after " + retryDelay + SECONDS); + return; + } + LOGGER.debug("SDC Client is initialized successfully"); + changeSdcReceptionHandlerStatus(SdcReceptionHandlerStatus.INIT); + } + + /** + * Method to start the SDC client. + * + */ + protected void startSdcClient() { + + LOGGER.debug("Going to start the SDC Client..."); + if (sdcReceptionHandlerStatus != SdcReceptionHandlerStatus.INIT) { + LOGGER.error("The SDC Client is not initialized"); + return; + } + final IDistributionClientResult clientResult = distributionClient.start(); + if (!clientResult.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) { + LOGGER.error("SDC client start failed with reason:" + clientResult.getDistributionMessageResult() + + ". Start will be retried after " + retryDelay + SECONDS); + return; + } + LOGGER.debug("SDC Client is started successfully"); + changeSdcReceptionHandlerStatus(SdcReceptionHandlerStatus.IDLE); + sdcClientHandler.cancel(); + } + + /** + * Method to stop the SDC client. + * + */ + protected void stopSdcClient() { + LOGGER.debug("Going to stop the SDC Client..."); + final IDistributionClientResult clientResult = distributionClient.stop(); + if (!clientResult.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) { + LOGGER.error("SDC client stop failed with reason:" + clientResult.getDistributionMessageResult() + + ". Stop will be retried after " + retryDelay + SECONDS); + return; + } + LOGGER.debug("SDC Client is stopped successfully"); + changeSdcReceptionHandlerStatus(SdcReceptionHandlerStatus.STOPPED); + sdcClientHandler.cancel(); + } + + /** + * Method to process csar service artifacts from incoming SDC notification. + * + * @param notificationData the notification from SDC + */ + public void processCsarServiceArtifacts(final INotificationData notificationData) { + boolean artifactsProcessedSuccessfully = true; + DistributionStatisticsManager.updateTotalDistributionCount(); + for (final IArtifactInfo artifact : notificationData.getServiceArtifacts()) { + try { + final IDistributionClientDownloadResult resultArtifact = + downloadTheArtifact(artifact, notificationData); + final Path filePath = writeArtifactToFile(artifact, resultArtifact); + final Csar csarObject = new Csar(filePath.toString()); + inputReceived(csarObject); + sendDistributionStatus(DistributionStatusType.DEPLOY, artifact.getArtifactURL(), + notificationData.getDistributionID(), DistributionStatusEnum.DEPLOY_OK, null); + deleteArtifactFile(filePath); + } catch (final ArtifactDownloadException | PolicyDecodingException exp) { + LOGGER.error("Failed to process csar service artifacts ", exp); + artifactsProcessedSuccessfully = false; + sendDistributionStatus(DistributionStatusType.DEPLOY, artifact.getArtifactURL(), + notificationData.getDistributionID(), DistributionStatusEnum.DEPLOY_ERROR, + "Failed to deploy the artifact due to: " + exp.getMessage()); + } + } + if (artifactsProcessedSuccessfully) { + DistributionStatisticsManager.updateDistributionSuccessCount(); + sendComponentDoneStatus(notificationData.getDistributionID(), DistributionStatusEnum.COMPONENT_DONE_OK, + null); + } else { + DistributionStatisticsManager.updateDistributionFailureCount(); + sendComponentDoneStatus(notificationData.getDistributionID(), DistributionStatusEnum.COMPONENT_DONE_ERROR, + "Failed to process the artifact"); + } + } + + /** + * Method to download the distribution artifact. + * + * @param artifact the artifact + * @return the download result + * @throws ArtifactDownloadException if download fails + */ + private IDistributionClientDownloadResult downloadTheArtifact(final IArtifactInfo artifact, + final INotificationData notificationData) throws ArtifactDownloadException { + + DistributionStatisticsManager.updateTotalDownloadCount(); + final IDistributionClientDownloadResult downloadResult = distributionClient.download(artifact); + if (!downloadResult.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) { + DistributionStatisticsManager.updateDownloadFailureCount(); + final String message = "Failed to download artifact with name: " + artifact.getArtifactName() + " due to: " + + downloadResult.getDistributionMessageResult(); + LOGGER.error(message); + sendDistributionStatus(DistributionStatusType.DOWNLOAD, artifact.getArtifactURL(), + notificationData.getDistributionID(), DistributionStatusEnum.DOWNLOAD_ERROR, message); + throw new ArtifactDownloadException(message); + } + DistributionStatisticsManager.updateDownloadSuccessCount(); + sendDistributionStatus(DistributionStatusType.DOWNLOAD, artifact.getArtifactURL(), + notificationData.getDistributionID(), DistributionStatusEnum.DOWNLOAD_OK, null); + return downloadResult; + } + + /** + * Method to write the downloaded distribution artifact to local file system. + * + * @param artifact the notification artifact + * @param resultArtifact the download result artifact + * @return the local path of written file + * @throws ArtifactDownloadException if error occurs while writing the artifact + */ + private Path writeArtifactToFile(final IArtifactInfo artifact, + final IDistributionClientDownloadResult resultArtifact) throws ArtifactDownloadException { + try { + final byte[] payloadBytes = resultArtifact.getArtifactPayload(); + final File tempArtifactFile = File.createTempFile(artifact.getArtifactName(), ".csar"); + try (FileOutputStream fileOutputStream = new FileOutputStream(tempArtifactFile)) { + fileOutputStream.write(payloadBytes, 0, payloadBytes.length); + return tempArtifactFile.toPath(); + } + } catch (final Exception exp) { + final String message = "Failed to write artifact to local repository"; + LOGGER.error(message, exp); + throw new ArtifactDownloadException(message, exp); + } + } + + /** + * Method to delete the downloaded notification artifact from local file system. + * + * @param filePath the path of file + */ + private void deleteArtifactFile(final Path filePath) { + try { + Files.deleteIfExists(filePath); + } catch (final IOException exp) { + LOGGER.error("Failed to delete the downloaded artifact file", exp); + } + } + + /** + * Sends the distribution status to SDC using the input values. + * + * @param statusType the status type + * @param artifactUrl the artifact url + * @param distributionId the distribution id + * @param status the status + * @param errorReason the error reason + */ + private void sendDistributionStatus(final DistributionStatusType statusType, final String artifactUrl, + final String distributionId, final DistributionStatusEnum status, final String errorReason) { + + IDistributionClientResult clientResult; + final DistributionStatusMessageBuilder messageBuilder = new DistributionStatusMessageBuilder() + .setArtifactUrl(artifactUrl).setConsumerId(sdcConfig.getConsumerID()).setDistributionId(distributionId) + .setDistributionStatus(status).setTimestamp(System.currentTimeMillis()); + final IDistributionStatusMessage message = new DistributionStatusMessage(messageBuilder); + if (DistributionStatusType.DOWNLOAD.equals(statusType)) { + if (errorReason != null) { + clientResult = distributionClient.sendDownloadStatus(message, errorReason); + } else { + clientResult = distributionClient.sendDownloadStatus(message); + } + } else { + if (errorReason != null) { + clientResult = distributionClient.sendDeploymentStatus(message, errorReason); + } else { + clientResult = distributionClient.sendDeploymentStatus(message); + } + } + final StringBuilder loggerMessage = new StringBuilder(); + loggerMessage.append("distribution status to SDC with values - ").append("DistributionId") + .append(distributionId).append(" Artifact: ").append(artifactUrl).append(" StatusType: ") + .append(statusType.name()).append(" Status: ").append(status.name()); + if (errorReason != null) { + loggerMessage.append(" ErrorReason: ").append(errorReason); + } + if (!clientResult.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) { + loggerMessage.insert(0, "Failed sending "); + LOGGER.debug(loggerMessage); + } else { + loggerMessage.insert(0, "Successfully Sent "); + LOGGER.debug(loggerMessage); + } + } + + /** + * Sends the component done status to SDC using the input values. + * + * @param distributionId the distribution Id + * @param status the distribution status + * @param errorReason the error reason + */ + private void sendComponentDoneStatus(final String distributionId, final DistributionStatusEnum status, + final String errorReason) { + IDistributionClientResult clientResult; + final ComponentDoneStatusMessageBuilder messageBuilder = new ComponentDoneStatusMessageBuilder() + .setConsumerId(sdcConfig.getConsumerID()).setDistributionId(distributionId) + .setDistributionStatus(status).setTimestamp(System.currentTimeMillis()); + final IComponentDoneStatusMessage message = new ComponentDoneStatusMessage(messageBuilder); + if (errorReason == null) { + clientResult = distributionClient.sendComponentDoneStatus(message); + } else { + clientResult = distributionClient.sendComponentDoneStatus(message, errorReason); + } + + final StringBuilder loggerMessage = new StringBuilder(); + loggerMessage.append("component done status to SDC with values - ").append("DistributionId") + .append(distributionId).append(" Status: ").append(status.name()); + if (errorReason != null) { + loggerMessage.append(" ErrorReason: ").append(errorReason); + } + if (!clientResult.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) { + loggerMessage.insert(0, "Failed sending "); + LOGGER.debug(loggerMessage); + } else { + loggerMessage.insert(0, "Successfully Sent "); + LOGGER.debug(loggerMessage); + } + } + + /** + * Handle the status change of {@link SdcReceptionHandler} to Idle. + * + * @param newStatus the new status + */ + private void handleIdleStatusChange(final SdcReceptionHandlerStatus newStatus) { + if (nbOfNotificationsOngoing > 1) { + --nbOfNotificationsOngoing; + } else { + nbOfNotificationsOngoing = 0; + sdcReceptionHandlerStatus = newStatus; + } + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterBuilder.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterBuilder.java new file mode 100644 index 0000000..65305c1 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterBuilder.java @@ -0,0 +1,357 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import java.util.List; + +/** + * This class builds an instance of {@link SdcReceptionHandlerConfigurationParameterGroup} class. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public class SdcReceptionHandlerConfigurationParameterBuilder { + + private boolean activeserverTlsAuth; + private boolean filterinEmptyResources; + private boolean useHttpsWithDmaap; + private int pollingTimeout; + private int pollingInterval; + private String user; + private String password; + private String consumerId; + private String consumerGroup; + private String asdcAddress; + private String environmentName; + private String keystorePath; + private String keystorePassword; + private List<String> messageBusAddress; + private List<String> artifactTypes; + private int retryDelay; + + /** + * Set activeserverTlsAuth to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param activeserverTlsAuth the activeserverTlsAuth + */ + public SdcReceptionHandlerConfigurationParameterBuilder setActiveserverTlsAuth(final boolean activeserverTlsAuth) { + this.activeserverTlsAuth = activeserverTlsAuth; + return this; + } + + /** + * Set filterinEmptyResources to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param filterinEmptyResources the filterinEmptyResources + */ + public SdcReceptionHandlerConfigurationParameterBuilder setFilterinEmptyResources( + final boolean filterinEmptyResources) { + this.filterinEmptyResources = filterinEmptyResources; + return this; + } + + /** + * Set useHttpsWithDmaap to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param useHttpsWithDmaap the useHttpsWithDmaap + */ + public SdcReceptionHandlerConfigurationParameterBuilder setUseHttpsWithDmaap(final Boolean useHttpsWithDmaap) { + this.useHttpsWithDmaap = useHttpsWithDmaap; + return this; + } + + /** + * Set pollingInterval to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param pollingInterval the pollingInterval + */ + public SdcReceptionHandlerConfigurationParameterBuilder setPollingInterval(final int pollingInterval) { + this.pollingInterval = pollingInterval; + return this; + } + + /** + * Set pollingTimeout to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param pollingTimeout the pollingTimeout + */ + public SdcReceptionHandlerConfigurationParameterBuilder setPollingTimeout(final int pollingTimeout) { + this.pollingTimeout = pollingTimeout; + return this; + } + + /** + * Set asdcAddress to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param asdcAddress the asdcAddress + */ + public SdcReceptionHandlerConfigurationParameterBuilder setAsdcAddress(final String asdcAddress) { + this.asdcAddress = asdcAddress; + return this; + } + + /** + * Set user to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param user the user + */ + public SdcReceptionHandlerConfigurationParameterBuilder setUser(final String user) { + this.user = user; + return this; + } + + /** + * Set password to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param password the password + */ + public SdcReceptionHandlerConfigurationParameterBuilder setPassword(final String password) { + this.password = password; + return this; + } + + /** + * Set consumerId to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param consumerId the consumerId + */ + public SdcReceptionHandlerConfigurationParameterBuilder setConsumerId(final String consumerId) { + this.consumerId = consumerId; + return this; + } + + /** + * Set consumerGroup to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param consumerGroup the consumerGroup + */ + public SdcReceptionHandlerConfigurationParameterBuilder setConsumerGroup(final String consumerGroup) { + this.consumerGroup = consumerGroup; + return this; + } + + /** + * Set environmentName to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param environmentName the environmentName + */ + public SdcReceptionHandlerConfigurationParameterBuilder setEnvironmentName(final String environmentName) { + this.environmentName = environmentName; + return this; + } + + /** + * Set keystorePath to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param keystorePath the keystorePath + */ + public SdcReceptionHandlerConfigurationParameterBuilder setKeystorePath(final String keystorePath) { + this.keystorePath = keystorePath; + return this; + } + + /** + * Set keystorePassword to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param keystorePassword the keystorePassword + */ + public SdcReceptionHandlerConfigurationParameterBuilder setKeystorePassword(final String keystorePassword) { + this.keystorePassword = keystorePassword; + return this; + } + + /** + * Set messageBusAddress to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param messageBusAddress the messageBusAddress + */ + public SdcReceptionHandlerConfigurationParameterBuilder setMessageBusAddress(final List<String> messageBusAddress) { + this.messageBusAddress = messageBusAddress; + return this; + } + + /** + * Set artifactTypes to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param artifactTypes the artifactTypes + */ + public SdcReceptionHandlerConfigurationParameterBuilder setArtifactTypes(final List<String> artifactTypes) { + this.artifactTypes = artifactTypes; + return this; + } + + /** + * Set retryDelay to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @param retryDelay the retryDelay + */ + public SdcReceptionHandlerConfigurationParameterBuilder setRetryDelay(final int retryDelay) { + this.retryDelay = retryDelay; + return this; + } + + /** + * Returns the active server TlsAuth of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @return the activeserverTlsAuth + */ + public boolean isActiveserverTlsAuth() { + return activeserverTlsAuth; + } + + /** + * Returns the isFilterinEmptyResources flag of this {@link SdcReceptionHandlerConfigurationParameterBuilder} + * instance. + * + * @return the isFilterinEmptyResources + */ + public boolean isFilterinEmptyResources() { + return filterinEmptyResources; + } + + /** + * Returns the isUseHttpsWithDmaap flag of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @return the isUseHttpsWithDmaap + */ + public Boolean getIsUseHttpsWithDmaap() { + return useHttpsWithDmaap; + } + + /** + * Returns the polling interval of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @return the pollingInterval + */ + public int getPollingInterval() { + return pollingInterval; + } + + /** + * Returns the polling timeout of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @return the pollingTimeout + */ + public int getPollingTimeout() { + return pollingTimeout; + } + + /** + * Returns the asdc address of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @return the asdcAddress + */ + public String getAsdcAddress() { + return asdcAddress; + } + + /** + * Returns the user of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @return the user + */ + public String getUser() { + return user; + } + + /** + * Returns the password of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @return the password + */ + public String getPassword() { + return password; + } + + /** + * Returns the consumer id of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @return the consumerId + */ + public String getConsumerId() { + return consumerId; + } + + /** + * Returns the consumer group of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @return the consumerGroup + */ + public String getConsumerGroup() { + return consumerGroup; + } + + /** + * Returns the environment name of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @return the environmentName + */ + public String getEnvironmentName() { + return environmentName; + } + + /** + * Returns the keystore path of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @return the keystorePath + */ + public String getKeystorePath() { + return keystorePath; + } + + /** + * Returns the keystore password of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @return the keystorePassword + */ + public String getKeystorePassword() { + return keystorePassword; + } + + /** + * Returns the message bus address of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @return the messageBusAddress + */ + public List<String> getMessageBusAddress() { + return messageBusAddress; + } + + /** + * Returns the artifact types of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @return the artifactTypes + */ + public List<String> getArtifactTypes() { + return artifactTypes; + } + + /** + * Returns the retryDelay of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance. + * + * @return the retryDelay + */ + public int getRetryDelay() { + return retryDelay; + } + +} + + diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterGroup.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterGroup.java new file mode 100644 index 0000000..6746dc3 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterGroup.java @@ -0,0 +1,210 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import java.util.List; + +import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.ValidationStatus; +import org.onap.policy.common.utils.validation.ParameterValidationUtils; +import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup; + +/** + * This class handles reading, parsing and validating of the Policy SDC Service Distribution parameters from Json + * format, which strictly adheres to the interface:IConfiguration, defined by SDC SDK. + */ +public class SdcReceptionHandlerConfigurationParameterGroup extends ReceptionHandlerConfigurationParameterGroup { + + private String asdcAddress; + private List<String> messageBusAddress; + private String user; + private String password; + private int pollingInterval; + private int pollingTimeout; + private int retryDelay; + private String consumerId; + private List<String> artifactTypes; + private String consumerGroup; + private String environmentName; + private String keyStorePath; + private String keyStorePassword; + private boolean activeServerTlsAuth; + private boolean isFilterInEmptyResources; + private boolean isUseHttpsWithDmaap; + + /** + * The constructor for instantiating {@link SdcReceptionHandlerConfigurationParameterGroup} class. + * + * @param builder the SDC configuration builder + */ + public SdcReceptionHandlerConfigurationParameterGroup( + final SdcReceptionHandlerConfigurationParameterBuilder builder) { + asdcAddress = builder.getAsdcAddress(); + messageBusAddress = builder.getMessageBusAddress(); + user = builder.getUser(); + password = builder.getPassword(); + pollingInterval = builder.getPollingInterval(); + pollingTimeout = builder.getPollingTimeout(); + retryDelay = builder.getRetryDelay(); + consumerId = builder.getConsumerId(); + artifactTypes = builder.getArtifactTypes(); + consumerGroup = builder.getConsumerGroup(); + environmentName = builder.getEnvironmentName(); + keyStorePath = builder.getKeystorePath(); + keyStorePassword = builder.getKeystorePassword(); + activeServerTlsAuth = builder.isActiveserverTlsAuth(); + isFilterInEmptyResources = builder.isFilterinEmptyResources(); + isUseHttpsWithDmaap = builder.getIsUseHttpsWithDmaap(); + + } + + public String getAsdcAddress() { + return asdcAddress; + } + + public List<String> getMessageBusAddress() { + return messageBusAddress; + } + + public String getUser() { + return user; + } + + public String getPassword() { + return password; + } + + public int getPollingInterval() { + return pollingInterval; + } + + public int getPollingTimeout() { + return pollingTimeout; + } + + public int getRetryDelay() { + return retryDelay; + } + + public String getConsumerId() { + return consumerId; + } + + public List<String> getArtifactTypes() { + return artifactTypes; + } + + public String getConsumerGroup() { + return consumerGroup; + } + + public String getEnvironmentName() { + return environmentName; + } + + public String getKeyStorePassword() { + return keyStorePassword; + } + + public boolean isActiveServerTlsAuth() { + return activeServerTlsAuth; + } + + public String getKeyStorePath() { + return keyStorePath; + } + + public boolean isFilterInEmptyResources() { + return isFilterInEmptyResources; + } + + public boolean isUseHttpsWithDmaap() { + return isUseHttpsWithDmaap; + } + + /** + * {@inheritDoc}. + */ + @Override + public GroupValidationResult validate() { + final GroupValidationResult validationResult = new GroupValidationResult(this); + validateStringElement(validationResult, asdcAddress, "asdcAddress"); + validateStringElement(validationResult, user, "user"); + validateStringElement(validationResult, consumerId, "consumerId"); + validateStringElement(validationResult, consumerGroup, "consumerGroup"); + validateStringElement(validationResult, keyStorePath, "keyStorePath"); + validateStringElement(validationResult, keyStorePassword, "keyStorePassword"); + validateIntElement(validationResult, pollingInterval, "pollingInterval"); + validateIntElement(validationResult, pollingTimeout, "pollingTimeout"); + validateIntElement(validationResult, retryDelay, "retryDelay"); + validateStringListElement(validationResult, messageBusAddress, "messageBusAddress"); + validateStringListElement(validationResult, artifactTypes, "artifactTypes"); + return validationResult; + } + + /** + * Validate the integer Element. + * + * @param validationResult the result object + * @param element the element to validate + * @param elementName the element name for error message + */ + private void validateIntElement(final GroupValidationResult validationResult, final int element, + final String elementName) { + if (!ParameterValidationUtils.validateIntParameter(element)) { + validationResult.setResult(elementName, ValidationStatus.INVALID, + elementName + " must be a positive integer"); + } + } + + /** + * Validate the String List Element. + * + * @param validationResult the result object + * @param element the element to validate + * @param elementName the element name for error message + */ + private void validateStringListElement(final GroupValidationResult validationResult, final List<String> element, + final String elementName) { + for (final String temp : element) { + if (!ParameterValidationUtils.validateStringParameter(temp)) { + validationResult.setResult(elementName, ValidationStatus.INVALID, + "the string of " + elementName + "must be a non-blank string"); + } + } + } + + /** + * Validate the string element. + * + * @param validationResult the result object + * @param element the element to validate + * @param elementName the element name for error message + */ + private void validateStringElement(final GroupValidationResult validationResult, final String element, + final String elementName) { + if (!ParameterValidationUtils.validateStringParameter(element)) { + validationResult.setResult(elementName, ValidationStatus.INVALID, + elementName + " must be a non-blank string"); + } + } +} + diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerStatus.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerStatus.java new file mode 100644 index 0000000..d0e04c7 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerStatus.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +/** + * Class to hold the possible values for status of {@link SdcReceptionHandler}. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public enum SdcReceptionHandlerStatus { + + /** + * The SdcReceptionHandler is not alive. + */ + STOPPED, + + /** + * The SdcReceptionHandler is initialized but not started yet. + */ + INIT, + + /** + * The SdcReceptionHandler is initialized, started & ready to handle incoming notifications. + */ + IDLE, + + /** + * The SdcReceptionHandler is currently busy in handling notifications. + */ + BUSY +} diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/ArtifactDownloadException.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/ArtifactDownloadException.java new file mode 100644 index 0000000..23409ea --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/ArtifactDownloadException.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc.exceptions; + +/** + * Exception during download from Pssd. + */ +public class ArtifactDownloadException extends Exception { + + /** + * serialization id. + */ + private static final long serialVersionUID = -8507246953751956974L; + + /** + * Constructor for creating PssdDownloadException using message. + * + * @param message The message to dump + */ + public ArtifactDownloadException(final String message) { + super(message); + + } + + /** + * Constructor for creating PssdDownloadException using message and exception. + * + * @param message The message to dump + * @param ex the exception that caused this exception to be thrown + */ + public ArtifactDownloadException(final String message, final Exception ex) { + super(message, ex); + + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/ArtifactInstallerException.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/ArtifactInstallerException.java new file mode 100644 index 0000000..19e711b --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/ArtifactInstallerException.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc.exceptions; + +/** + * Exception during artifact installation. + */ +public class ArtifactInstallerException extends Exception { + + /** + * serialization id. + */ + private static final long serialVersionUID = -8507246953751956974L; + + /** + * Constructor for creating ArtifactInstallerException using message. + * + * @param message The message to dump + */ + public ArtifactInstallerException(final String message) { + super(message); + + } + + /** + * Constructor for creating ArtifactInstallerException using message and exception. + * + * @param message The message to dump + * @param ex the exception that caused this exception to be thrown + */ + public ArtifactInstallerException(final String message, final Exception ex) { + super(message, ex); + + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/PssdControllerException.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/PssdControllerException.java new file mode 100644 index 0000000..0dd16d7 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/PssdControllerException.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc.exceptions; + +/** + * Exception of the Pssd controller. + */ +public class PssdControllerException extends Exception { + + /** + * serialization id. + */ + private static final long serialVersionUID = -8507246953751956974L; + + /** + * Constructor for creating PssdControllerException using message. + * + * @param message The message to dump + */ + public PssdControllerException(final String message) { + super(message); + + } + + /** + * Constructor for creating PssdControllerException using message and exception. + * + * @param message The message to dump + * @param ex the exception that caused this exception to be thrown + */ + public PssdControllerException(final String message, final Exception ex) { + super(message, ex); + + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/PssdParametersException.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/PssdParametersException.java new file mode 100644 index 0000000..e1cdf70 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/PssdParametersException.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc.exceptions; + +/** + * Exception of the Pssd controller. + */ +public class PssdParametersException extends Exception { + + /** + * serialization id. + */ + private static final long serialVersionUID = -8507246953751956974L; + + /** + * Constructor for creating PssdParametersException using message. + * + * @param message The message to dump + */ + public PssdParametersException(final String message) { + super(message); + + } + + /** + * Constructor for creating PssdParametersException using message and exception. + * + * @param message The message to dump + * @param ex the exception that caused this exception to be thrown + */ + public PssdParametersException(final String message, final Exception ex) { + super(message, ex); + + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/DummyArtifactForwarder.java b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/DummyArtifactForwarder.java new file mode 100644 index 0000000..445d47c --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/DummyArtifactForwarder.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import java.util.ArrayList; +import java.util.Collection; + +import org.onap.policy.distribution.forwarding.ArtifactForwarder; +import org.onap.policy.distribution.forwarding.ArtifactForwardingException; +import org.onap.sdc.api.notification.IArtifactInfo; + +/** + * Class to create a dummy forwarder for test cases. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public class DummyArtifactForwarder implements ArtifactForwarder { + private int numberOfPoliciesReceived = 0; + private Collection<IArtifactInfo> policiesReceived = new ArrayList<>(); + + /** + * {@inheritDoc}. + */ + @Override + public void forward(final Collection<IArtifactInfo> policies) throws ArtifactForwardingException { + numberOfPoliciesReceived += policies.size(); + policiesReceived.addAll(policies); + } + + /** + * Returns the number of policies received by this forwarder. + * + * @return the integer value + */ + public int getNumberOfPoliciesReceived() { + return numberOfPoliciesReceived; + } + + /** + * Checks if the forwarder has received a policy with given policy type. + * + * @param policyType the policy type + * @return the boolean result + */ + public boolean receivedPolicyWithGivenType(final String policyType) { + return true; + } + + /** + * {@inheritDoc}. + */ + @Override + public void configure(final String parameterGroupName) {} +} diff --git a/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/DummyPolicy.java b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/DummyPolicy.java new file mode 100644 index 0000000..f4c56ab --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/DummyPolicy.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import org.onap.policy.distribution.model.Policy; + +/** + * Class to create a dummy policy for test cases. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public class DummyPolicy implements Policy { + + private String policyName; + private String policyType; + + /** + * Constructor for instantiating {@link DummyPolicy} class. + * + * @param policyName the policy name + * @param policyType the policy type + */ + public DummyPolicy(final String policyName, final String policyType) { + super(); + this.policyName = policyName; + this.policyType = policyType; + } + + /** + * {@inheritDoc}. + */ + @Override + public String getPolicyName() { + return policyName; + } + + /** + * {@inheritDoc}. + */ + @Override + public String getPolicyType() { + return policyType; + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestComponentDoneStatusMessage.java b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestComponentDoneStatusMessage.java new file mode 100644 index 0000000..75e3224 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestComponentDoneStatusMessage.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.sdc.utils.DistributionStatusEnum; + +public class TestComponentDoneStatusMessage { + + @Test + public void testComponentDoneStatusMessage_Success() { + final String consumerId = "dummyId"; + final String distributionId = "dummyDistribution"; + final long timestamp = System.currentTimeMillis(); + final ComponentDoneStatusMessageBuilder messageBuilder = + new ComponentDoneStatusMessageBuilder().setConsumerId(consumerId).setDistributionId(distributionId) + .setDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK).setTimestamp(timestamp); + final ComponentDoneStatusMessage message = new ComponentDoneStatusMessage(messageBuilder); + assertEquals("POLICY", message.getComponentName()); + assertEquals(consumerId, message.getConsumerID()); + assertEquals(distributionId, message.getDistributionID()); + assertEquals(DistributionStatusEnum.COMPONENT_DONE_OK, message.getStatus()); + assertEquals(timestamp, message.getTimestamp()); + } + + @Test + public void testComponentDoneStatusMessage_Failure() { + final String consumerId = "dummyId"; + final String distributionId = "dummyDistribution"; + final long timestamp = System.currentTimeMillis(); + final ComponentDoneStatusMessageBuilder messageBuilder = + new ComponentDoneStatusMessageBuilder().setConsumerId(consumerId).setDistributionId(distributionId) + .setDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR).setTimestamp(timestamp); + final ComponentDoneStatusMessage message = new ComponentDoneStatusMessage(messageBuilder); + assertEquals("POLICY", message.getComponentName()); + assertEquals(consumerId, message.getConsumerID()); + assertEquals(distributionId, message.getDistributionID()); + assertEquals(DistributionStatusEnum.COMPONENT_DONE_ERROR, message.getStatus()); + assertEquals(timestamp, message.getTimestamp()); + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestDistributionStatusMessage.java b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestDistributionStatusMessage.java new file mode 100644 index 0000000..be12777 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestDistributionStatusMessage.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.sdc.utils.DistributionStatusEnum; + +public class TestDistributionStatusMessage { + + @Test + public void testDistributionStatusMessage_Download() { + final String artifactUrl = "http://dummyurl"; + final String consumerId = "dummyId"; + final String distributionId = "dummyDistribution"; + final long timestamp = System.currentTimeMillis(); + + final DistributionStatusMessageBuilder messageBuilder = new DistributionStatusMessageBuilder() + .setArtifactUrl(artifactUrl).setConsumerId(consumerId).setDistributionId(distributionId) + .setDistributionStatus(DistributionStatusEnum.DOWNLOAD_OK).setTimestamp(timestamp); + final DistributionStatusMessage message = new DistributionStatusMessage(messageBuilder); + assertEquals(artifactUrl, message.getArtifactURL()); + assertEquals(consumerId, message.getConsumerID()); + assertEquals(distributionId, message.getDistributionID()); + assertEquals(DistributionStatusEnum.DOWNLOAD_OK, message.getStatus()); + assertEquals(timestamp, message.getTimestamp()); + } + + @Test + public void testDistributionStatusMessage_Deploy() { + final String artifactUrl = "http://dummyurl"; + final String consumerId = "dummyId"; + final String distributionId = "dummyDistribution"; + final long timestamp = System.currentTimeMillis(); + + final DistributionStatusMessageBuilder messageBuilder = new DistributionStatusMessageBuilder() + .setArtifactUrl(artifactUrl).setConsumerId(consumerId).setDistributionId(distributionId) + .setDistributionStatus(DistributionStatusEnum.DEPLOY_OK).setTimestamp(timestamp); + final DistributionStatusMessage message = new DistributionStatusMessage(messageBuilder); + assertEquals(artifactUrl, message.getArtifactURL()); + assertEquals(consumerId, message.getConsumerID()); + assertEquals(distributionId, message.getDistributionID()); + assertEquals(DistributionStatusEnum.DEPLOY_OK, message.getStatus()); + assertEquals(timestamp, message.getTimestamp()); + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java new file mode 100644 index 0000000..f9a65c5 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java @@ -0,0 +1,160 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import java.io.FileReader; +import java.io.IOException; +import java.util.Arrays; + +import org.junit.Test; +import org.onap.policy.common.parameters.GroupValidationResult; + +/** + * Class to perform unit test of {@link SdcConfiguration}. + * + */ +public class TestSdcReceptionHandlerConfigurationParameterGroup { + + @Test + public void testSdcConfiguration() throws IOException { + SdcReceptionHandlerConfigurationParameterGroup configParameters = null; + try { + final Gson gson = new GsonBuilder().create(); + configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc.json"), + SdcReceptionHandlerConfigurationParameterGroup.class); + } catch (final Exception e) { + fail("test should not thrown an exception here: " + e.getMessage()); + } + final GroupValidationResult validationResult = configParameters.validate(); + assertTrue(validationResult.isValid()); + final SdcConfiguration config = new SdcConfiguration(configParameters); + assertEquals(Arrays.asList("a.com", "b.com", "c.com"), config.getMsgBusAddress()); + assertEquals(Arrays.asList("TOSCA_CSAR", "HEAT"), config.getRelevantArtifactTypes()); + assertEquals("localhost", config.getAsdcAddress()); + assertEquals("policy", config.getUser()); + assertEquals("policy", config.getPassword()); + assertEquals(20, config.getPollingInterval()); + assertEquals(30, config.getPollingTimeout()); + assertEquals("policy-id", config.getConsumerID()); + assertEquals("policy-group", config.getConsumerGroup()); + assertEquals("TEST", config.getEnvironmentName()); + assertEquals("null", config.getKeyStorePath()); + assertEquals("null", config.getKeyStorePassword()); + assertEquals(false, config.activateServerTLSAuth()); + assertEquals(true, config.isFilterInEmptyResources()); + assertEquals(false, config.isUseHttpsWithDmaap()); + } + + @Test + public void testInvalidSdcConfiguration() throws IOException { + SdcReceptionHandlerConfigurationParameterGroup configParameters = null; + try { + final Gson gson = new GsonBuilder().create(); + configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"), + SdcReceptionHandlerConfigurationParameterGroup.class); + } catch (final Exception e) { + fail("test should not thrown an exception here: " + e.getMessage()); + } + final GroupValidationResult validationResult = configParameters.validate(); + assertFalse(validationResult.isValid()); + } + + @Test + public void testSdcConfigurationBuilder() { + + final SdcReceptionHandlerConfigurationParameterBuilder builder = + new SdcReceptionHandlerConfigurationParameterBuilder().setAsdcAddress("localhost") + .setConsumerGroup("policy-group").setConsumerId("policy-id").setEnvironmentName("TEST") + .setKeystorePassword("password").setKeystorePath("dummyPath").setPassword("policy") + .setPollingInterval(10).setPollingTimeout(20).setRetryDelay(30).setUser("policy") + .setUseHttpsWithDmaap(false).setActiveserverTlsAuth(false).setFilterinEmptyResources(true) + .setArtifactTypes(Arrays.asList("TOSCA_CSAR")).setMessageBusAddress(Arrays.asList("localhost")); + final SdcReceptionHandlerConfigurationParameterGroup configParameters = + new SdcReceptionHandlerConfigurationParameterGroup(builder); + configParameters.setName("SDCConfiguration"); + + assertEquals(Arrays.asList("localhost"), configParameters.getMessageBusAddress()); + assertEquals(Arrays.asList("TOSCA_CSAR"), configParameters.getArtifactTypes()); + assertEquals("localhost", configParameters.getAsdcAddress()); + assertEquals("policy", configParameters.getUser()); + assertEquals("policy", configParameters.getPassword()); + assertEquals(10, configParameters.getPollingInterval()); + assertEquals(20, configParameters.getPollingTimeout()); + assertEquals(30, configParameters.getRetryDelay()); + assertEquals("policy-id", configParameters.getConsumerId()); + assertEquals("policy-group", configParameters.getConsumerGroup()); + assertEquals("TEST", configParameters.getEnvironmentName()); + assertEquals("dummyPath", configParameters.getKeyStorePath()); + assertEquals("password", configParameters.getKeyStorePassword()); + assertEquals(false, configParameters.isActiveServerTlsAuth()); + assertEquals(true, configParameters.isFilterInEmptyResources()); + assertEquals(false, configParameters.isUseHttpsWithDmaap()); + } + + @Test + public void testSdcConfigurationWithNullList() { + + final SdcReceptionHandlerConfigurationParameterBuilder builder = + new SdcReceptionHandlerConfigurationParameterBuilder().setAsdcAddress("localhost") + .setConsumerGroup("policy-group").setConsumerId("policy-id").setEnvironmentName("TEST") + .setKeystorePassword("password").setKeystorePath("dummyPath").setPassword("policy") + .setPollingInterval(10).setPollingTimeout(20).setUser("policy").setUseHttpsWithDmaap(false) + .setActiveserverTlsAuth(false).setFilterinEmptyResources(true) + .setArtifactTypes(Arrays.asList("TOSCA_CSAR")).setMessageBusAddress(null); + final SdcReceptionHandlerConfigurationParameterGroup configParameters = + new SdcReceptionHandlerConfigurationParameterGroup(builder); + configParameters.setName("SDCConfiguration"); + + try { + configParameters.validate(); + fail("Test must throw an exception"); + } catch (final Exception exp) { + assertTrue(exp.getMessage().contains("collection parameter \"messageBusAddress\" is null")); + } + } + + @Test + public void testSdcConfigurationWithEmptyStringList() { + + final SdcReceptionHandlerConfigurationParameterBuilder builder = + new SdcReceptionHandlerConfigurationParameterBuilder().setAsdcAddress("localhost") + .setConsumerGroup("policy-group").setConsumerId("policy-id").setEnvironmentName("TEST") + .setKeystorePassword("password").setKeystorePath("dummyPath").setPassword("policy") + .setPollingInterval(10).setPollingTimeout(20).setUser("policy").setUseHttpsWithDmaap(false) + .setActiveserverTlsAuth(false).setFilterinEmptyResources(true) + .setArtifactTypes(Arrays.asList("")).setMessageBusAddress(Arrays.asList("localhost")); + final SdcReceptionHandlerConfigurationParameterGroup configParameters = + new SdcReceptionHandlerConfigurationParameterGroup(builder); + configParameters.setName("SDCConfiguration"); + + final GroupValidationResult validationResult = configParameters.validate(); + assertFalse(validationResult.isValid()); + assertTrue(validationResult.getResult().contains("must be a non-blank string")); + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/ArtifactDownloadExceptionTest.java b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/ArtifactDownloadExceptionTest.java new file mode 100644 index 0000000..6d275f7 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/ArtifactDownloadExceptionTest.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc.exceptions; + +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + +import org.junit.Test; + +public class ArtifactDownloadExceptionTest { + + @Test + public void test() { + assertNotNull(new ArtifactDownloadException("Message")); + assertNotNull(new ArtifactDownloadException("Message", new IOException())); + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/ArtifactInstallerExceptionTest.java b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/ArtifactInstallerExceptionTest.java new file mode 100644 index 0000000..6c524ff --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/ArtifactInstallerExceptionTest.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc.exceptions; + +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + +import org.junit.Test; + +public class ArtifactInstallerExceptionTest { + + @Test + public void test() { + assertNotNull(new ArtifactInstallerException("Message")); + assertNotNull(new ArtifactInstallerException("Message", new IOException())); + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/PssdControllerExceptionTest.java b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/PssdControllerExceptionTest.java new file mode 100644 index 0000000..5f8e507 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/PssdControllerExceptionTest.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc.exceptions; + +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + +import org.junit.Test; + +public class PssdControllerExceptionTest { + + @Test + public void test() { + assertNotNull(new PssdControllerException("Message")); + assertNotNull(new PssdControllerException("Message", new IOException())); + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/PssdParametersExceptionTest.java b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/PssdParametersExceptionTest.java new file mode 100644 index 0000000..7a1f551 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/exceptions/PssdParametersExceptionTest.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc.exceptions; + +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + +import org.junit.Test; + +public class PssdParametersExceptionTest { + + @Test + public void test() { + assertNotNull(new PssdParametersException("Message")); + assertNotNull(new PssdParametersException("Message", new IOException())); + } +} diff --git a/artifactbroker/plugins/reception-plugins/src/test/resources/handling-sdc.json b/artifactbroker/plugins/reception-plugins/src/test/resources/handling-sdc.json new file mode 100644 index 0000000..0bb936b --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/test/resources/handling-sdc.json @@ -0,0 +1,27 @@ +{ + "name" : "parameterConfig1", + "asdcAddress": "localhost", + "messageBusAddress": [ + "a.com", + "b.com", + "c.com" + ], + "user": "policy", + "password": "policy", + "pollingInterval":20, + "pollingTimeout":30, + "retryDelay":30, + "consumerId": "policy-id", + "artifactTypes": [ + "TOSCA_CSAR", + "HEAT" + ], + "consumerGroup": "policy-group", + "environmentName": "TEST", + "keyStorePath": "null", + "keyStorePassword": "null", + "activeServerTlsAuth": false, + "isFilterInEmptyResources": true, + "isUseHttpsWithDmaap": false +} + diff --git a/artifactbroker/plugins/reception-plugins/src/test/resources/handling-sdcInvalid.json b/artifactbroker/plugins/reception-plugins/src/test/resources/handling-sdcInvalid.json new file mode 100644 index 0000000..803fc41 --- /dev/null +++ b/artifactbroker/plugins/reception-plugins/src/test/resources/handling-sdcInvalid.json @@ -0,0 +1,26 @@ +{ + "name" : "parameterConfig1", + "asdcAddress": "", + "messageBusAddress": [ + "a.com", + "b.com", + "c.com" + ], + "user": "tbdsdc-1480", + "password": "tbdsdc-1480", + "pollingInterval":-1, + "pollingTimeout":-2, + "consumerId": "policy-id", + "artifactTypes": [ + "TOSCA_CSAR", + "HEAT" + ], + "consumerGroup": "policy-group", + "environmentName": "environmentName", + "keyStorePath": "null", + "keyStorePassword": "null", + "activeserverTlsAuth": false, + "isFilterInEmptyResources": true, + "isUseHttpsWithDmaap": false +} + |