diff options
author | rameshiyer27 <ramesh.murugan.iyer@est.tech> | 2022-07-28 11:58:19 +0100 |
---|---|---|
committer | rameshiyer27 <ramesh.murugan.iyer@est.tech> | 2022-07-29 08:47:55 +0100 |
commit | fda6280b8d38e24d15fc0710cc7d0c213f90779b (patch) | |
tree | 667846be886ff6f8d443de1973b90439f72b5bc3 | |
parent | c1c9b09f1b7200f814110bd7dab7f45630b3e184 (diff) |
Add module for AC Element implementation
Refactored unused participant simulator module to implement AC element
microservice for ACM testing purposes. Empty spring project added.
Business logics will be added as a separate review on top of this structure.
Issue-ID: POLICY-4312
Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech>
Change-Id: I8fc280083ce4b759ed9ab23b223cf1555176ef62
28 files changed, 121 insertions, 1756 deletions
diff --git a/participant/participant-impl/participant-impl-simulator/pom.xml b/participant/participant-impl/participant-impl-acelement/pom.xml index 989e47e92..0a3087ae0 100644 --- a/participant/participant-impl/participant-impl-simulator/pom.xml +++ b/participant/participant-impl/participant-impl-acelement/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2021 Nordix Foundation. + Copyright (C) 2021-2022 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -29,9 +29,9 @@ <version>6.3.0-SNAPSHOT</version> </parent> - <artifactId>policy-clamp-participant-impl-simulator</artifactId> + <artifactId>policy-clamp-acm-element-impl</artifactId> <name>${project.artifactId}</name> - <description>Participant simulator, used to test automation compositions</description> + <description>AC element implementation, used to test automation compositions</description> <build> <plugins> diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/ParticipantSimulatorApplication.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/AcElementApplication.java index ea94795fb..9991c4cee 100644 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/ParticipantSimulatorApplication.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/AcElementApplication.java @@ -1,46 +1,36 @@ -/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.acm.participant.simulator;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
-import org.springframework.context.annotation.ComponentScan;
-
-/**
- * Starter.
- *
- */
-// @formatter:off
-@SpringBootApplication
-@ConfigurationPropertiesScan("org.onap.policy.clamp.acm.participant.simulator.main.parameters")
-@ComponentScan({
- "org.onap.policy.clamp.acm.participant.simulator",
- "org.onap.policy.clamp.acm.participant.intermediary",
- "org.onap.policy.clamp.acm.common.rest"
-})
-//@formatter:on
-public class ParticipantSimulatorApplication {
-
- public static void main(String[] args) {
- SpringApplication.run(ParticipantSimulatorApplication.class, args);
- }
-}
+/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2022 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.acm.element; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Starter. + * + */ +@SpringBootApplication +public class AcElementApplication { + + public static void main(String[] args) { + SpringApplication.run(AcElementApplication.class, args); + } +} diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/config/SecurityConfig.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/config/SecurityConfig.java index c41c6e1b3..b2609d358 100644 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/config/SecurityConfig.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/config/SecurityConfig.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.clamp.acm.participant.simulator.config; +package org.onap.policy.clamp.acm.element.config; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/config/SpringFoxConfig.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/config/SpringFoxConfig.java index d9909818f..4e88e364a 100644 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/config/SpringFoxConfig.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/config/SpringFoxConfig.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,9 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.clamp.acm.participant.simulator.config; +package org.onap.policy.clamp.acm.element.config; -import org.onap.policy.clamp.acm.participant.simulator.simulation.rest.SimulationElementController; +import org.onap.policy.clamp.acm.element.main.rest.AcElementController; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.PathSelectors; @@ -39,7 +39,8 @@ public class SpringFoxConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2).select() - .apis(RequestHandlerSelectors.basePackage(SimulationElementController.class.getPackageName())) + .apis(RequestHandlerSelectors.basePackage(AcElementController.class.getPackageName())) .paths(PathSelectors.any()).build(); } } + diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/main/parameters/ParticipantSimulatorParameters.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/parameters/AcElement.java index 8549e4c7b..bb80cc638 100644 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/main/parameters/ParticipantSimulatorParameters.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/parameters/AcElement.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,28 +18,25 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.clamp.acm.participant.simulator.main.parameters; +package org.onap.policy.clamp.acm.element.main.parameters; + import javax.validation.Valid; import javax.validation.constraints.NotNull; -import lombok.Getter; -import lombok.Setter; -import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantIntermediaryParameters; -import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.validation.annotation.Validated; +import org.springframework.stereotype.Component; -/** - * Class to hold all parameters needed for the participant simulator. - * - */ -@Validated -@Getter -@Setter -@ConfigurationProperties(prefix = "participant") -public class ParticipantSimulatorParameters implements ParticipantParameters { +@Data +@NoArgsConstructor +@Component +@ConfigurationProperties(prefix = "element") +public class AcElement { - @Valid + // The name and version of this AC element @NotNull - private ParticipantIntermediaryParameters intermediaryParameters; + @Valid + private ToscaConceptIdentifier elementId; } diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/main/rest/ParticipantSimulatorAafFilter.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementController.java index 3008d2d17..833819a13 100644 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/main/rest/ParticipantSimulatorAafFilter.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementController.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,21 +18,12 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.clamp.acm.participant.simulator.main.rest; +package org.onap.policy.clamp.acm.element.main.rest; -import org.onap.policy.common.endpoints.http.server.aaf.AafGranularAuthFilter; -import org.onap.policy.common.utils.resources.MessageConstants; +import org.springframework.web.bind.annotation.RestController; -/** - * Class to manage AAF filters for the participant simulator component. - */ -public class ParticipantSimulatorAafFilter extends AafGranularAuthFilter { - - public static final String AAF_NODETYPE = MessageConstants.POLICY_CLAMP + "-participant-simulator"; - public static final String AAF_ROOT_PERMISSION = DEFAULT_NAMESPACE + "." + AAF_NODETYPE; +@RestController +public class AcElementController { - @Override - public String getPermissionTypeRoot() { - return AAF_ROOT_PERMISSION; - } + //TODO : Implement REST methods for configuring Dmaap topic } diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/main/rest/ParticipantErrorController.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementErrorController.java index e32c57254..717390088 100644 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/main/rest/ParticipantErrorController.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementErrorController.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * ================================================================================ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -20,7 +20,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.clamp.acm.participant.simulator.main.rest; +package org.onap.policy.clamp.acm.element.main.rest; import java.util.Map; import javax.servlet.RequestDispatcher; @@ -39,7 +39,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.context.request.ServletWebRequest; @Controller -public class ParticipantErrorController implements ErrorController { +public class AcElementErrorController implements ErrorController { private final ErrorAttributes errorAttributes; @@ -51,7 +51,7 @@ public class ParticipantErrorController implements ErrorController { * * @param errorAttributes ErrorAttributes */ - public ParticipantErrorController(ErrorAttributes errorAttributes) { + public AcElementErrorController(ErrorAttributes errorAttributes) { this.errorAttributes = errorAttributes; } @@ -92,6 +92,5 @@ public class ParticipantErrorController implements ErrorController { resp.setErrorDetails(sb.toString()); return ResponseEntity.status(getStatus(request)).body(resp); - } } diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/main/rest/GlobalControllerExceptionHandler.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/GlobalControllerExceptionHandler.java index 69714137f..bb56bf993 100644 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/main/rest/GlobalControllerExceptionHandler.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/GlobalControllerExceptionHandler.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * ================================================================================ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -20,7 +20,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.clamp.acm.participant.simulator.main.rest; +package org.onap.policy.clamp.acm.element.main.rest; import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException; import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse; diff --git a/participant/participant-impl/participant-impl-acelement/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-acelement/src/main/resources/config/application.yaml new file mode 100644 index 000000000..4a0f0d301 --- /dev/null +++ b/participant/participant-impl/participant-impl-acelement/src/main/resources/config/application.yaml @@ -0,0 +1,22 @@ +spring: + security: + user: + name: acmUser + password: zb!XztG34 + +server: + port: 8084 + servlet: + context-path: /onap/policy/clamp/acelement/ + error: + path: /error + +element: + elementId: + name: onap.policy.clamp.ac.element1 + version: 1.0.0 +management: + endpoints: + web: + exposure: + include: health, metrics, prometheus
\ No newline at end of file diff --git a/participant/participant-impl/participant-impl-acelement/src/test/resources/application-test.yaml b/participant/participant-impl/participant-impl-acelement/src/test/resources/application-test.yaml new file mode 100644 index 000000000..76dbeaa2a --- /dev/null +++ b/participant/participant-impl/participant-impl-acelement/src/test/resources/application-test.yaml @@ -0,0 +1,22 @@ +spring: + security: + user: + name: acmUser + password: zb!XztG34 + +server: + port: 8084 + servlet: + context-path: /onap/policy/clamp/acelement/ + error: + path: /error + +element: + elementId: + name: onap.policy.clamp.ac.element1 + version: 1.0.0 +management: + endpoints: + web: + exposure: + include: health, metrics, prometheus diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/config/AafConfiguration.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/config/AafConfiguration.java deleted file mode 100644 index 101e7fac2..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/config/AafConfiguration.java +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.policy.clamp.acm.participant.simulator.config; - -import javax.servlet.Filter; -import org.onap.policy.clamp.acm.participant.simulator.main.rest.ParticipantSimulatorAafFilter; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; - -@Configuration -@Profile("clamp-aaf-authentication") -public class AafConfiguration { - - /** - * Method to return Aaf filter. - * - * @return Filter - */ - @Bean - public Filter aafFilter() { - return new ParticipantSimulatorAafFilter(); - } - -} diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/config/ParticipantConfig.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/config/ParticipantConfig.java deleted file mode 100644 index 92ced99d7..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/config/ParticipantConfig.java +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.acm.participant.simulator.config; - -import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; -import org.onap.policy.clamp.acm.participant.simulator.main.handler.AutomationCompositionElementHandler; -import org.onap.policy.clamp.common.acm.rest.RequestResponseLoggingFilter; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class ParticipantConfig { - - /** - * logging Filter configuration. - * - * @return FilterRegistrationBean - */ - @Bean - public FilterRegistrationBean<RequestResponseLoggingFilter> loggingFilter() { - FilterRegistrationBean<RequestResponseLoggingFilter> registrationBean = new FilterRegistrationBean<>(); - - registrationBean.setFilter(new RequestResponseLoggingFilter()); - registrationBean.addUrlPatterns("/onap/participantsim/v2/*"); - - return registrationBean; - } - - /** - * Register AutomationCompositionElementListener. - * - * @param intermediaryApi the ParticipantIntermediaryApi - * @param acElementHandler the AutomationComposition Element Handler - */ - @Autowired - public void registerAutomationCompositionElementListener(ParticipantIntermediaryApi intermediaryApi, - AutomationCompositionElementHandler acElementHandler) { - intermediaryApi.registerAutomationCompositionElementListener(acElementHandler); - acElementHandler.setIntermediaryApi(intermediaryApi); - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/config/YamlConfiguration.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/config/YamlConfiguration.java deleted file mode 100644 index 718697786..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/config/YamlConfiguration.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.acm.participant.simulator.config; - -import java.util.List; -import org.onap.policy.clamp.common.acm.rest.CoderHttpMesageConverter; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.MediaType; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.StringHttpMessageConverter; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@Configuration -public class YamlConfiguration implements WebMvcConfigurer { - - @Override - public void extendMessageConverters(List<HttpMessageConverter<?>> converters) { - converters.add(new CoderHttpMesageConverter<>("yaml")); - converters.add(new CoderHttpMesageConverter<>("json")); - - StringHttpMessageConverter converter = new StringHttpMessageConverter(); - converter.setSupportedMediaTypes(List.of(MediaType.TEXT_PLAIN)); - converters.add(converter); - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/main/handler/AutomationCompositionElementHandler.java deleted file mode 100644 index 9e30c8809..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/main/handler/AutomationCompositionElementHandler.java +++ /dev/null @@ -1,112 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.acm.participant.simulator.main.handler; - -import java.time.Instant; -import java.util.UUID; -import lombok.Setter; -import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; -import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; -import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; -import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -/** - * This class handles implementation of automationCompositionElement updates. - */ -@Component -public class AutomationCompositionElementHandler implements AutomationCompositionElementListener { - - private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionElementHandler.class); - - @Setter - private ParticipantIntermediaryApi intermediaryApi; - - /** - * Callback method to handle a automation composition element state change. - * - * @param automationCompositionElementId the ID of the automation composition element - * @param currentState the current state of the automation composition element - * @param newState the state to which the automation composition element is changing to - * @throws PfModelException in case of an exception - */ - @Override - public void automationCompositionElementStateChange(ToscaConceptIdentifier automationCompositionId, - UUID automationCompositionElementId, AutomationCompositionState currentState, - AutomationCompositionOrderedState newState) throws PfModelException { - switch (newState) { - case UNINITIALISED: - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, newState, AutomationCompositionState.UNINITIALISED, - ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE); - break; - case PASSIVE: - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, newState, AutomationCompositionState.PASSIVE, - ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE); - break; - case RUNNING: - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, newState, AutomationCompositionState.RUNNING, - ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE); - break; - default: - LOGGER.debug("Unknown orderedstate {}", newState); - break; - } - } - - /** - * Callback method to handle an update on a automation composition element. - * - * @param element the information on the automation composition element - * @param acElementDefinition toscaNodeTemplate - * @throws PfModelException in case of an exception - */ - @Override - public void automationCompositionElementUpdate(ToscaConceptIdentifier automationCompositionId, - AutomationCompositionElement element, ToscaNodeTemplate acElementDefinition) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - element.getOrderedState(), AutomationCompositionState.PASSIVE, - ParticipantMessageType.AUTOMATION_COMPOSITION_UPDATE); - } - - @Override - public void handleStatistics(UUID automationCompositionElementId) throws PfModelException { - var acElement = intermediaryApi.getAutomationCompositionElement(automationCompositionElementId); - if (acElement != null) { - var acElementStatistics = new AcElementStatistics(); - acElementStatistics.setState(acElement.getState()); - acElementStatistics.setTimeStamp(Instant.now()); - intermediaryApi.updateAutomationCompositionElementStatistics(automationCompositionElementId, - acElementStatistics); - } - } - -} diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/main/rest/AbstractRestController.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/main/rest/AbstractRestController.java deleted file mode 100644 index 4db07c953..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/main/rest/AbstractRestController.java +++ /dev/null @@ -1,130 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.acm.participant.simulator.main.rest; - -import io.swagger.annotations.Api; -import io.swagger.annotations.BasicAuthDefinition; -import io.swagger.annotations.Info; -import io.swagger.annotations.SecurityDefinition; -import io.swagger.annotations.SwaggerDefinition; -import io.swagger.annotations.Tag; -import java.net.HttpURLConnection; -import java.util.UUID; -import javax.ws.rs.core.MediaType; -import lombok.AccessLevel; -import lombok.Getter; -import org.onap.policy.clamp.acm.participant.simulator.simulation.SimulationProvider; -import org.springframework.http.HttpHeaders; -import org.springframework.web.bind.annotation.RequestMapping; - -/** - * Common superclass to provide REST endpoints for the participant simulator. - */ -// @formatter:off -@RequestMapping( - value = "/v2", - produces = { - MediaType.APPLICATION_JSON, - AbstractRestController.APPLICATION_YAML - } -) -@Api(value = "Participant Simulator API") -@SwaggerDefinition( - info = @Info( - description = "Participant Simulator", - version = "v1.0", - title = "Participant Simulator" - ), - consumes = {MediaType.APPLICATION_JSON, AbstractRestController.APPLICATION_YAML}, - produces = {MediaType.APPLICATION_JSON, AbstractRestController.APPLICATION_YAML}, - schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS}, - tags = { - @Tag(name = "participantsim", description = "Participant Simulator") - }, - securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")})) -// @formatter:on -public abstract class AbstractRestController { - public static final String APPLICATION_YAML = "application/yaml"; - - public static final String EXTENSION_NAME = "interface info"; - - public static final String API_VERSION_NAME = "api-version"; - public static final String API_VERSION = "1.0.0"; - - public static final String LAST_MOD_NAME = "last-mod-release"; - public static final String LAST_MOD_RELEASE = "Dublin"; - - public static final String VERSION_MINOR_NAME = "X-MinorVersion"; - public static final String VERSION_MINOR_DESCRIPTION = - "Used to request or communicate a MINOR version back from the client" - + " to the server, and from the server back to the client"; - - public static final String VERSION_PATCH_NAME = "X-PatchVersion"; - public static final String VERSION_PATCH_DESCRIPTION = "Used only to communicate a PATCH version in a response for" - + " troubleshooting purposes only, and will not be provided by" + " the client on request"; - - public static final String VERSION_LATEST_NAME = "X-LatestVersion"; - public static final String VERSION_LATEST_DESCRIPTION = "Used only to communicate an API's latest version"; - - public static final String REQUEST_ID_NAME = "X-ONAP-RequestID"; - public static final String REQUEST_ID_HDR_DESCRIPTION = "Used to track REST transactions for logging purpose"; - public static final String REQUEST_ID_PARAM_DESCRIPTION = "RequestID for http transaction"; - - public static final String AUTHORIZATION_TYPE = "basicAuth"; - - public static final int AUTHENTICATION_ERROR_CODE = HttpURLConnection.HTTP_UNAUTHORIZED; - public static final int AUTHORIZATION_ERROR_CODE = HttpURLConnection.HTTP_FORBIDDEN; - public static final int SERVER_ERROR_CODE = HttpURLConnection.HTTP_INTERNAL_ERROR; - - public static final String AUTHENTICATION_ERROR_MESSAGE = "Authentication Error"; - public static final String AUTHORIZATION_ERROR_MESSAGE = "Authorization Error"; - public static final String SERVER_ERROR_MESSAGE = "Internal Server Error"; - - // The provider for simulation requests - @Getter(AccessLevel.PROTECTED) - private SimulationProvider simulationProvider; - - /** - * create a Rest Controller. - * - * @param simulationProvider the provider for the simulation participant - */ - protected AbstractRestController(SimulationProvider simulationProvider) { - this.simulationProvider = simulationProvider; - } - - /** - * Get the common headers for responses. - * - * @param requestId the request ID - * - * @return the headers - */ - protected HttpHeaders getCommonHeaders(UUID requestId) { - HttpHeaders commonHeaders = new HttpHeaders(); - commonHeaders.add(VERSION_MINOR_NAME, API_VERSION.split("\\.")[1]); - commonHeaders.add(VERSION_PATCH_NAME, API_VERSION.split("\\.")[2]); - commonHeaders.add(VERSION_LATEST_NAME, API_VERSION); - commonHeaders.add(REQUEST_ID_NAME, (requestId != null ? requestId.toString() : null)); - - return commonHeaders; - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/simulation/SimulationProvider.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/simulation/SimulationProvider.java deleted file mode 100644 index 73ae80e29..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/simulation/SimulationProvider.java +++ /dev/null @@ -1,113 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.acm.participant.simulator.simulation; - -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; -import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; -import org.onap.policy.clamp.models.acm.concepts.Participant; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; -import org.onap.policy.clamp.models.acm.messages.rest.TypedSimpleResponse; -import org.springframework.stereotype.Service; - -/** - * This provider class simulation of participants and automation composition elements. - */ -@Service -public class SimulationProvider { - - private final ParticipantIntermediaryApi intermediaryApi; - - /** - * Create a participant simulation provider. - * - * @param intermediaryApi the intermediary to use for talking to the CLAMP runtime - */ - public SimulationProvider(ParticipantIntermediaryApi intermediaryApi) { - this.intermediaryApi = intermediaryApi; - } - - /** - * Get the automation compositions. - * - * @param name the automationComposition, null to get all - * @param version the automationComposition, null to get all - * @return the automation compositions - * @throws AutomationCompositionException on errors getting the automation compositions - */ - public AutomationCompositions getAutomationCompositions(String name, String version) - throws AutomationCompositionException { - return intermediaryApi.getAutomationCompositions(name, version); - } - - /** - * Get the simulated automation composition elements. - * - * @param name the automationCompositionElement, null to get all - * @param version the automationCompositionElement, null to get all - * @return the automation composition elements - */ - public Map<UUID, AutomationCompositionElement> getAutomationCompositionElements(String name, String version) { - return intermediaryApi.getAutomationCompositionElements(name, version); - } - - /** - * Update the given automation composition element in the simulator. - * - * @param element the automation composition element to update - * @return response simple response returned - */ - public TypedSimpleResponse<AutomationCompositionElement> updateAutomationCompositionElement( - AutomationCompositionElement element) { - TypedSimpleResponse<AutomationCompositionElement> response = new TypedSimpleResponse<>(); - response.setResponse(intermediaryApi.updateAutomationCompositionElementState(null, element.getId(), - element.getOrderedState(), element.getState(), ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE)); - return response; - } - - /** - * Get the current simulated participants. - * - * @param name the participant, null to get all - * @param version the participant, null to get all - * @return the list of participants - */ - public List<Participant> getParticipants(String name, String version) { - return intermediaryApi.getParticipants(name, version); - } - - /** - * Update a simulated participant. - * - * @param participant the participant to update - * @return TypedSimpleResponse simple response - */ - public TypedSimpleResponse<Participant> updateParticipant(Participant participant) { - TypedSimpleResponse<Participant> response = new TypedSimpleResponse<>(); - response.setResponse( - intermediaryApi.updateParticipantState(participant.getDefinition(), participant.getParticipantState())); - return response; - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/simulation/rest/SimulationElementController.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/simulation/rest/SimulationElementController.java deleted file mode 100644 index 277638220..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/simulation/rest/SimulationElementController.java +++ /dev/null @@ -1,188 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.acm.participant.simulator.simulation.rest; - -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.ResponseHeader; -import java.util.Map; -import java.util.UUID; -import org.onap.policy.clamp.acm.participant.simulator.main.rest.AbstractRestController; -import org.onap.policy.clamp.acm.participant.simulator.simulation.SimulationProvider; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; -import org.onap.policy.clamp.models.acm.messages.rest.TypedSimpleResponse; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RestController; - -/** - * Class to provide REST end points for participant simulator to query/update details of automationCompositionElements. - */ -@RestController -public class SimulationElementController extends AbstractRestController { - - /** - * Constructor. - * - * @param simulationProvider the Simulation Provider - */ - public SimulationElementController(SimulationProvider simulationProvider) { - super(simulationProvider); - } - - /** - * Queries details of all automation composition element within the simulator. - * - * @param requestId request ID used in ONAP logging - * @param name the name of the Automation Composition element to get, null to get all - * @param version the version of the Automation Composition element to get, null to get all - * @return the automation composition elements - */ - // @formatter:off - @GetMapping("/elements/{name}/{version}") - @ApiOperation( - value = "Query details of the requested simulated automation composition elements", - notes = "Queries details of the requested simulated automation composition elements, " - + "returning all automation composition element details", - response = AutomationCompositions.class, - tags = { - "Clamp Automation Composition Participant Simulator API" - }, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader( - name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension - ( - name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - } - ) - } - ) - @ApiResponses( - value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - } - ) - // @formatter:on - public ResponseEntity<Map<UUID, AutomationCompositionElement>> elements( - @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId, - @ApiParam(value = "Automation composition element name", required = true) @PathVariable("name") String name, - @ApiParam( - value = "Automation composition element version", - required = true) @PathVariable("version") String version) { - - return ResponseEntity - .ok() - .headers(super.getCommonHeaders(requestId)) - .body(getSimulationProvider().getAutomationCompositionElements(name, version)); - } - - /** - * Updates a automation composition element in the simulator. - * - * @param requestId request ID used in ONAP logging - * @param body the body of a automation composition element - * @return a response - */ - // @formatter:off - @PutMapping("/elements") - @ApiOperation( - value = "Updates simulated automation composition elements", - notes = "Updates simulated automation composition elements, " - + "returning the updated automation composition definition IDs", - response = TypedSimpleResponse.class, - tags = { - "Clamp Automation Composition Participant Simulator API" - }, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader( - name = VERSION_MINOR_NAME, - description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader( - name = VERSION_PATCH_NAME, - description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader( - name = VERSION_LATEST_NAME, - description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader( - name = REQUEST_ID_NAME, - description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class) - }, - extensions = { - @Extension - ( - name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - } - ) - } - ) - @ApiResponses( - value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - } - ) - // @formatter:on - public ResponseEntity<TypedSimpleResponse<AutomationCompositionElement>> update( - @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId, - @ApiParam( - value = "Body of a automation composition element", - required = true) @RequestBody AutomationCompositionElement body) { - - return ResponseEntity - .ok() - .headers(super.getCommonHeaders(requestId)) - .body(getSimulationProvider().updateAutomationCompositionElement(body)); - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/simulation/rest/SimulationParticipantController.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/simulation/rest/SimulationParticipantController.java deleted file mode 100644 index 02e56aa6e..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/simulator/simulation/rest/SimulationParticipantController.java +++ /dev/null @@ -1,181 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.acm.participant.simulator.simulation.rest; - -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.ResponseHeader; -import java.util.List; -import java.util.UUID; -import org.onap.policy.clamp.acm.participant.simulator.main.rest.AbstractRestController; -import org.onap.policy.clamp.acm.participant.simulator.simulation.SimulationProvider; -import org.onap.policy.clamp.models.acm.concepts.Participant; -import org.onap.policy.clamp.models.acm.messages.rest.TypedSimpleResponse; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RestController; - -/** - * Class to provide REST end points for participant simulator to query/update details of all participants. - */ -@RestController -public class SimulationParticipantController extends AbstractRestController { - - /** - * Constructor. - * - * @param simulationProvider the Simulation Provider - */ - public SimulationParticipantController(SimulationProvider simulationProvider) { - super(simulationProvider); - } - - /** - * Queries details of all participants within the simulator. - * - * @param requestId request ID used in ONAP logging - * @param name the name of the participant to get, null to get all - * @param version the version of the participant to get, null to get all - * @return the participants - */ - // @formatter:off - @GetMapping("/participants/{name}/{version}") - @ApiOperation(value = "Query details of the requested simulated participants", - notes = "Queries details of the requested simulated participants, " - + "returning all participant details", - response = List.class, - tags = { - "Clamp Automation Composition Participant Simulator API" - }, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader( - name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension - ( - name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - } - ) - } - ) - @ApiResponses( - value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - } - ) - // @formatter:on - public ResponseEntity<List<Participant>> participants( - @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId, - @ApiParam(value = "Participant name", required = true) @PathVariable("name") String name, - @ApiParam(value = "Participant version", required = true) @PathVariable("version") String version) { - - return ResponseEntity - .ok() - .headers(super.getCommonHeaders(requestId)) - .body(getSimulationProvider().getParticipants(name, version)); - } - - /** - * Updates a participant in the simulator. - * - * @param requestId request ID used in ONAP logging - * @param body the body of a participant - * @return a response - */ - // @formatter:off - @PutMapping("/participants") - @ApiOperation( - value = "Updates simulated participants", - notes = "Updates simulated participants, returning the updated automation composition definition IDs", - response = TypedSimpleResponse.class, - tags = { - "Clamp Automation Composition Participant Simulator API" - }, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader( - name = VERSION_MINOR_NAME, - description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader( - name = VERSION_PATCH_NAME, - description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader( - name = VERSION_LATEST_NAME, - description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader( - name = REQUEST_ID_NAME, - description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class) - }, - extensions = { - @Extension - ( - name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - } - ) - } - ) - @ApiResponses( - value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - } - ) - // @formatter:on - public ResponseEntity<TypedSimpleResponse<Participant>> update( - @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId, - @ApiParam(value = "Body of a participant", required = true) @RequestBody Participant body) { - - return ResponseEntity - .ok() - .headers(super.getCommonHeaders(requestId)) - .body(getSimulationProvider().updateParticipant(body)); - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml deleted file mode 100644 index e20f0ebf5..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml +++ /dev/null @@ -1,37 +0,0 @@ -spring: - security: - user: - name: runtimeUser - password: zb!XztG34 - -server: - port: 8084 - servlet: - context-path: /onap/participantsim - error: - path: /error - -participant: - intermediaryParameters: - reportingTimeIntervalMs: 60000 - description: Participant Description - participantId: - name: org.onap.PM_CDS_Blueprint - version: 1.0.0 - participantType: - name: org.onap.PM_CDS_Blueprint - version: 1.0.0 - clampAutomationCompositionTopics: - topicSources: - - - topic: POLICY-ACRUNTIME-PARTICIPANT - servers: - - ${topicServer:localhost} - topicCommInfrastructure: dmaap - fetchTimeout: 15000 - topicSinks: - - - topic: POLICY-ACRUNTIME-PARTICIPANT - servers: - - ${topicServer:localhost} - topicCommInfrastructure: dmaap diff --git a/participant/participant-impl/participant-impl-simulator/src/main/resources/version.txt b/participant/participant-impl/participant-impl-simulator/src/main/resources/version.txt deleted file mode 100644 index 5fcdcab5a..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/resources/version.txt +++ /dev/null @@ -1,4 +0,0 @@ -ONAP Tosca defined automation composition Participant -Version: ${project.version} -Built (UTC): ${maven.build.timestamp} -ONAP https://wiki.onap.org diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/endtoend/ParticipantSimulatorTest.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/endtoend/ParticipantSimulatorTest.java deleted file mode 100644 index 4cf9f1e3c..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/endtoend/ParticipantSimulatorTest.java +++ /dev/null @@ -1,287 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.acm.participant.simulator.endtoend; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.List; -import java.util.Map; -import java.util.UUID; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.GenericType; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; -import org.glassfish.jersey.client.ClientProperties; -import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; -import org.onap.policy.clamp.acm.participant.intermediary.comm.AutomationCompositionUpdateListener; -import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHandler; -import org.onap.policy.clamp.acm.participant.simulator.main.parameters.CommonTestData; -import org.onap.policy.clamp.acm.participant.simulator.main.rest.AbstractRestController; -import org.onap.policy.clamp.acm.participant.simulator.utils.TestListenerUtils; -import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.Participant; -import org.onap.policy.clamp.models.acm.concepts.ParticipantState; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionUpdate; -import org.onap.policy.clamp.models.acm.messages.rest.TypedSimpleResponse; -import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; -import org.onap.policy.common.gson.GsonMessageBodyHandler; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith(SpringExtension.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@ActiveProfiles("test") -class ParticipantSimulatorTest { - - private static final String PARTICIPANTS_ENDPOINT = "participants"; - private static final String ELEMENTS_ENDPOINT = "elements"; - private static final CommInfrastructure INFRA = CommInfrastructure.NOOP; - private static final String TOPIC = "my-topic"; - - @Value("${spring.security.user.name}") - private String user; - - @Value("${spring.security.user.password}") - private String password; - - @LocalServerPort - private int randomServerPort; - - @Autowired - private ParticipantIntermediaryApi participantIntermediaryApi; - - @Autowired - private ParticipantHandler participantHandler; - - private static final Object lockit = new Object(); - private boolean check = false; - - private void setUp() { - synchronized (lockit) { - if (!check) { - check = true; - AutomationCompositionUpdateListener acUpdateListener = - new AutomationCompositionUpdateListener(participantHandler); - - AutomationCompositionUpdate automationCompositionUpdateMsg = - TestListenerUtils.createAutomationCompositionUpdateMsg(); - acUpdateListener.onTopicEvent(INFRA, TOPIC, null, automationCompositionUpdateMsg); - } - } - } - - @Test - void testEndParticipantsSwagger() { - testSwagger(PARTICIPANTS_ENDPOINT); - } - - @Test - void testElementsSwagger() { - testSwagger(ELEMENTS_ENDPOINT); - } - - @Test - void testProducerYaml() { - final Client client = ClientBuilder.newBuilder().build(); - - client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true"); - client.register(GsonMessageBodyHandler.class); - client.register(HttpAuthenticationFeature.basic(user, password)); - - String path = getPath(PARTICIPANTS_ENDPOINT + "/org.onap.PM_CDS_Blueprint/1"); - final WebTarget webTarget = client.target(path); - - Response response = webTarget.request("application/yaml").get(); - - assertThat(response.getStatus()).isEqualTo(200); - } - - @Test - void testQuery_Unauthorized() { - String path = PARTICIPANTS_ENDPOINT + "/org.onap.PM_CDS_Blueprint/1"; - - Response response = performRequest(path, true, null).get(); - assertThat(response.getStatus()).isEqualTo(200); - - // unauthorized call - response = performRequest(path, false, null).get(); - assertThat(response.getStatus()).isEqualTo(401); - } - - @Test - void testQueryParticipants() { - Participant participant = new Participant(); - ToscaConceptIdentifier participantId = CommonTestData.getParticipantId(); - participant.setDefinition(participantId); - participant.setName(participantId.getName()); - participant.setVersion(participantId.getVersion()); - UUID uuid = UUID.randomUUID(); - - // GET REST call for querying the participants - Response response = performGet( - PARTICIPANTS_ENDPOINT + "/" + participant.getKey().getName() + "/" + participant.getKey().getVersion(), - uuid); - checkResponseEntity(response, uuid); - - Participant[] returnValue = response.readEntity(Participant[].class); - assertThat(returnValue).hasSize(1); - // Verify the result of GET participants with what is stored - assertEquals(participant.getDefinition(), returnValue[0].getDefinition()); - } - - @Test - void testQueryAutomationCompositionElements() { - setUp(); - UUID uuid = UUID.randomUUID(); - ToscaConceptIdentifier participantId = CommonTestData.getParticipantId(); - - // GET REST call for querying the automationComposition elements - Response response = - performGet(ELEMENTS_ENDPOINT + "/" + participantId.getName() + "/" + participantId.getVersion(), uuid); - checkResponseEntity(response, uuid); - - Map<?, ?> returnValue = response.readEntity(Map.class); - // Verify the result of GET automation composition elements with what is stored - assertThat(returnValue).isEmpty(); - } - - @Test - void testUpdateParticipant() { - setUp(); - List<Participant> participants = participantIntermediaryApi.getParticipants( - CommonTestData.getParticipantId().getName(), CommonTestData.getParticipantId().getVersion()); - assertEquals(ParticipantState.UNKNOWN, participants.get(0).getParticipantState()); - // Change the state of the participant to PASSIVE from UNKNOWN - participants.get(0).setParticipantState(ParticipantState.PASSIVE); - UUID uuid = UUID.randomUUID(); - - // PUT REST call for updating Participant - Response response = performPut(PARTICIPANTS_ENDPOINT, Entity.json(participants.get(0)), uuid); - checkResponseEntity(response, uuid); - - TypedSimpleResponse<Participant> resp = response.readEntity(new GenericType<>() { - }); - assertNotNull(resp.getResponse()); - // Verify the response and state returned by PUT REST call for updating participants - assertEquals(participants.get(0).getDefinition(), resp.getResponse().getDefinition()); - assertEquals(ParticipantState.PASSIVE, resp.getResponse().getParticipantState()); - } - - @Test - void testUpdateAutomationCompositionElement() { - setUp(); - AutomationComposition automationComposition = TestListenerUtils.createAutomationComposition(); - Map<UUID, AutomationCompositionElement> automationCompositionElements = - participantIntermediaryApi.getAutomationCompositionElements(automationComposition.getDefinition().getName(), - automationComposition.getDefinition().getVersion()); - - UUID uuid = automationCompositionElements.keySet().iterator().next(); - AutomationCompositionElement automationCompositionElement = automationCompositionElements.get(uuid); - - automationCompositionElement.setOrderedState(AutomationCompositionOrderedState.PASSIVE); - // PUT REST call for updating AutomationCompositionElement - Response response = performPut(ELEMENTS_ENDPOINT, Entity.json(automationCompositionElement), uuid); - checkResponseEntity(response, uuid); - - TypedSimpleResponse<AutomationCompositionElement> resp = response.readEntity(new GenericType<>() { - }); - assertNotNull(resp.getResponse()); - // Verify the response and state returned by PUT REST call for updating participants - assertEquals(automationCompositionElement.getDefinition(), resp.getResponse().getDefinition()); - assertEquals(AutomationCompositionOrderedState.PASSIVE, resp.getResponse().getOrderedState()); - } - - private String getPath(String path) { - return "http://localhost:" + randomServerPort + "/onap/participantsim/v2/" + path; - } - - void testSwagger(String endPoint) { - final Client client = ClientBuilder.newBuilder().build(); - - client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true"); - client.register(GsonMessageBodyHandler.class); - client.register(HttpAuthenticationFeature.basic(user, password)); - - final WebTarget webTarget = client.target(getPath("api-docs")); - - Response response = webTarget.request(MediaType.APPLICATION_JSON).get(); - - assertThat(response.getStatus()).isEqualTo(200); - assertTrue(response.readEntity(String.class).contains("/onap/participantsim/v2/" + endPoint)); - } - - private Invocation.Builder performRequest(String endpoint, boolean includeAuth, UUID uuid) { - final Client client = ClientBuilder.newBuilder().build(); - - client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true"); - client.register(GsonMessageBodyHandler.class); - if (includeAuth) { - client.register(HttpAuthenticationFeature.basic(user, password)); - } - Invocation.Builder builder = client.target(getPath(endpoint)).request(MediaType.APPLICATION_JSON); - if (uuid != null) { - builder = builder.header(AbstractRestController.REQUEST_ID_NAME, uuid.toString()); - } - return builder; - } - - private Response performGet(String endpoint, UUID uuid) { - return performRequest(endpoint, true, uuid).get(); - } - - private void checkResponseEntity(Response response, UUID uuid) { - assertThat(response.getStatus()).isEqualTo(200); - assertThat(getHeader(response.getHeaders(), AbstractRestController.VERSION_MINOR_NAME)).isEqualTo("0"); - assertThat(getHeader(response.getHeaders(), AbstractRestController.VERSION_PATCH_NAME)).isEqualTo("0"); - assertThat(getHeader(response.getHeaders(), AbstractRestController.VERSION_LATEST_NAME)).isEqualTo("1.0.0"); - assertThat(getHeader(response.getHeaders(), AbstractRestController.REQUEST_ID_NAME)).isEqualTo(uuid.toString()); - } - - private String getHeader(MultivaluedMap<String, Object> httpHeaders, String param) { - List<Object> list = httpHeaders.get(param); - assertThat(list).hasSize(1); - assertThat(list.get(0)).isNotNull(); - return (String) list.get(0); - } - - private Response performPut(String endpoint, final Entity<?> entity, UUID uuid) { - return performRequest(endpoint, true, uuid).put(entity); - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/handler/AutomationCompositionElementHandlerTest.java deleted file mode 100644 index 87be88658..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/handler/AutomationCompositionElementHandlerTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.acm.participant.simulator.main.handler; - -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.mockito.Mockito.when; - -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; -import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; - -class AutomationCompositionElementHandlerTest { - - private static final String ID_NAME = "org.onap.PM_CDS_Blueprint"; - private static final String ID_VERSION = "1.0.1"; - private static final UUID automationCompositionElementId = UUID.randomUUID(); - private static final ToscaConceptIdentifier automationCompositionId = - new ToscaConceptIdentifier(ID_NAME, ID_VERSION); - - @Test - void testSimulatorHandlerExceptions() { - AutomationCompositionElementHandler handler = getTestingHandler(); - - assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(automationCompositionId, - automationCompositionElementId, AutomationCompositionState.UNINITIALISED, - AutomationCompositionOrderedState.PASSIVE)); - - assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(automationCompositionId, - automationCompositionElementId, AutomationCompositionState.RUNNING, - AutomationCompositionOrderedState.UNINITIALISED)); - - assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(automationCompositionId, - automationCompositionElementId, AutomationCompositionState.PASSIVE, - AutomationCompositionOrderedState.RUNNING)); - var element = getTestingAcElement(); - var acElementDefinition = Mockito.mock(ToscaNodeTemplate.class); - - assertDoesNotThrow( - () -> handler.automationCompositionElementUpdate(automationCompositionId, element, acElementDefinition)); - - assertDoesNotThrow(() -> handler.handleStatistics(automationCompositionElementId)); - } - - AutomationCompositionElementHandler getTestingHandler() { - var handler = new AutomationCompositionElementHandler(); - var intermediaryApi = Mockito.mock(ParticipantIntermediaryApi.class); - var element = getTestingAcElement(); - when(intermediaryApi.getAutomationCompositionElement(automationCompositionElementId)).thenReturn(element); - handler.setIntermediaryApi(intermediaryApi); - return handler; - } - - AutomationCompositionElement getTestingAcElement() { - var element = new AutomationCompositionElement(); - element.setDefinition(automationCompositionId); - element.setDescription("Description"); - element.setId(automationCompositionElementId); - element.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); - element.setParticipantId(automationCompositionId); - element.setState(AutomationCompositionState.UNINITIALISED); - var template = Mockito.mock(ToscaServiceTemplate.class); - element.setToscaServiceTemplateFragment(template); - return element; - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/parameters/CommonTestData.java deleted file mode 100644 index fbedbe633..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/parameters/CommonTestData.java +++ /dev/null @@ -1,124 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.acm.participant.simulator.main.parameters; - -import java.util.List; -import java.util.Map; -import java.util.TreeMap; -import org.onap.policy.common.endpoints.parameters.TopicParameters; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Class to hold/create all parameters for test cases. - */ -public class CommonTestData { - public static final String DESCRIPTION = "Participant description"; - public static final long TIME_INTERVAL = 2000; - public static final List<TopicParameters> TOPIC_PARAMS = List.of(getTopicParams()); - - public static final Coder CODER = new StandardCoder(); - - /** - * Get ParticipantSimulatorParameters. - * - * @return ParticipantSimulatorParameters - */ - public ParticipantSimulatorParameters getParticipantSimulatorParameters() { - try { - return CODER.convert(getParticipantParameterGroupMap(), - ParticipantSimulatorParameters.class); - } catch (final CoderException e) { - throw new RuntimeException("cannot create ParticipantSimulatorParameters from map", e); - } - } - - /** - * Returns a property map for a ApexStarterParameterGroup map for test cases. - * - * @return a property map suitable for constructing an object - */ - public Map<String, Object> getParticipantParameterGroupMap() { - final Map<String, Object> map = new TreeMap<>(); - - map.put("intermediaryParameters", getIntermediaryParametersMap(false)); - return map; - } - - /** - * Returns a property map for a intermediaryParameters map for test cases. - * - * @param isEmpty boolean value to represent that object created should be empty or not - * @return a property map suitable for constructing an object - */ - public Map<String, Object> getIntermediaryParametersMap(final boolean isEmpty) { - final Map<String, Object> map = new TreeMap<>(); - if (!isEmpty) { - map.put("name", "Participant parameters"); - map.put("reportingTimeIntervalMs", TIME_INTERVAL); - map.put("description", DESCRIPTION); - map.put("participantId", getParticipantId()); - map.put("participantType", getParticipantId()); - map.put("clampAutomationCompositionTopics", getTopicParametersMap(false)); - } - - return map; - } - - /** - * Returns a property map for a TopicParameters map for test cases. - * - * @param isEmpty boolean value to represent that object created should be empty or not - * @return a property map suitable for constructing an object - */ - public Map<String, Object> getTopicParametersMap(final boolean isEmpty) { - final Map<String, Object> map = new TreeMap<>(); - if (!isEmpty) { - map.put("topicSources", TOPIC_PARAMS); - map.put("topicSinks", TOPIC_PARAMS); - } - return map; - } - - /** - * Returns topic parameters for test cases. - * - * @return topic parameters - */ - public static TopicParameters getTopicParams() { - final TopicParameters topicParams = new TopicParameters(); - topicParams.setTopic("POLICY-ACRUNTIME-PARTICIPANT"); - topicParams.setTopicCommInfrastructure("dmaap"); - topicParams.setServers(List.of("localhost")); - return topicParams; - } - - /** - * Returns participantId for test cases. - * - * @return participant Id - */ - public static ToscaConceptIdentifier getParticipantId() { - return new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.0"); - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java deleted file mode 100644 index 4e8aa5f46..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.acm.participant.simulator.main.parameters; - -import static org.assertj.core.api.Assertions.assertThat; - -import javax.validation.Validation; -import javax.validation.ValidatorFactory; -import org.junit.jupiter.api.Test; - -/** - * Class to perform unit test of - * {@link org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters}. - */ -class TestParticipantSimulatorParameters { - private final CommonTestData commonTestData = new CommonTestData(); - private final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); - - @Test - void testParticipantParameterGroup() { - final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters(); - assertThat(validatorFactory.getValidator().validate(participantParameters)).isEmpty(); - } - - @Test - void testParticipantParameterGroup_EmptyParticipantIntermediaryParameters() { - final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters(); - participantParameters.setIntermediaryParameters(null); - assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); - } - - @Test - void testParticipantPolicyParameters_NullTopicSinks() { - final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters(); - participantParameters.getIntermediaryParameters().getClampAutomationCompositionTopics().setTopicSinks(null); - assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); - } - - @Test - void testParticipantPolicyParameters_NullTopicSources() { - final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters(); - participantParameters.getIntermediaryParameters().getClampAutomationCompositionTopics().setTopicSources(null); - assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/utils/TestListenerUtils.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/utils/TestListenerUtils.java deleted file mode 100644 index 944aaa6b7..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/utils/TestListenerUtils.java +++ /dev/null @@ -1,154 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.acm.participant.simulator.utils; - -import java.io.FileNotFoundException; -import java.time.Instant; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates; -import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionUpdate; -import org.onap.policy.clamp.models.acm.utils.AcmUtils; -import org.onap.policy.common.utils.coder.YamlJsonTranslator; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class TestListenerUtils { - - private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); - private static final Logger LOGGER = LoggerFactory.getLogger(TestListenerUtils.class); - private static final String TOSCA_TEMPLATE = "clamp/acm/test/pm_simple_ac_tosca.yaml"; - - /** - * Method to create a automationComposition from a yaml file. - * - * @return AutomationComposition automation composition - */ - public static AutomationComposition createAutomationComposition() { - AutomationComposition automationComposition = new AutomationComposition(); - Map<UUID, AutomationCompositionElement> elements = new LinkedHashMap<>(); - ToscaServiceTemplate toscaServiceTemplate = testAutomationCompositionYamlSerialization(); - Map<String, ToscaNodeTemplate> nodeTemplatesMap = - toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(); - for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : nodeTemplatesMap.entrySet()) { - AutomationCompositionElement acElement = new AutomationCompositionElement(); - acElement.setId(UUID.randomUUID()); - - ToscaConceptIdentifier acElementParticipantId = new ToscaConceptIdentifier(); - acElementParticipantId.setName(toscaInputEntry.getKey()); - acElementParticipantId.setVersion(toscaInputEntry.getValue().getVersion()); - acElement.setParticipantId(acElementParticipantId); - acElement.setParticipantType(acElementParticipantId); - - acElement.setDefinition(acElementParticipantId); - acElement.setState(AutomationCompositionState.UNINITIALISED); - acElement.setDescription(toscaInputEntry.getValue().getDescription()); - acElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); - elements.put(acElement.getId(), acElement); - } - automationComposition.setElements(elements); - automationComposition.setName("PMSHInstance0"); - automationComposition.setVersion("1.0.0"); - - ToscaConceptIdentifier definition = new ToscaConceptIdentifier(); - definition.setName("PMSHInstance0"); - definition.setVersion("1.0.0"); - automationComposition.setDefinition(definition); - - return automationComposition; - } - - /** - * Method to create AutomationCompositionUpdateMsg. - * - * @return AutomationCompositionUpdate message - */ - public static AutomationCompositionUpdate createAutomationCompositionUpdateMsg() { - final AutomationCompositionUpdate acUpdateMsg = new AutomationCompositionUpdate(); - ToscaConceptIdentifier automationCompositionId = new ToscaConceptIdentifier("PMSHInstance0", "1.0.0"); - ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0"); - - acUpdateMsg.setAutomationCompositionId(automationCompositionId); - acUpdateMsg.setParticipantId(participantId); - acUpdateMsg.setMessageId(UUID.randomUUID()); - acUpdateMsg.setTimestamp(Instant.now()); - - Map<UUID, AutomationCompositionElement> elements = new LinkedHashMap<>(); - ToscaServiceTemplate toscaServiceTemplate = testAutomationCompositionYamlSerialization(); - Map<String, ToscaNodeTemplate> nodeTemplatesMap = - toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(); - for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : nodeTemplatesMap.entrySet()) { - if (ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(toscaInputEntry.getValue(), - toscaServiceTemplate)) { - AutomationCompositionElement acElement = new AutomationCompositionElement(); - acElement.setId(UUID.randomUUID()); - var acParticipantType = - ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties()); - - acElement.setParticipantId(acParticipantType); - acElement.setParticipantType(acParticipantType); - - acElement.setDefinition( - new ToscaConceptIdentifier(toscaInputEntry.getKey(), toscaInputEntry.getValue().getVersion())); - acElement.setState(AutomationCompositionState.UNINITIALISED); - acElement.setDescription(toscaInputEntry.getValue().getDescription()); - acElement.setOrderedState(AutomationCompositionOrderedState.PASSIVE); - elements.put(acElement.getId(), acElement); - } - } - - List<ParticipantUpdates> participantUpdates = new ArrayList<>(); - for (AutomationCompositionElement element : elements.values()) { - AcmUtils.prepareParticipantUpdate(element, participantUpdates); - } - acUpdateMsg.setParticipantUpdatesList(participantUpdates); - return acUpdateMsg; - } - - private static ToscaServiceTemplate testAutomationCompositionYamlSerialization() { - try { - String automationCompositionString = ResourceUtils.getResourceAsString(TestListenerUtils.TOSCA_TEMPLATE); - if (automationCompositionString == null) { - throw new FileNotFoundException(TestListenerUtils.TOSCA_TEMPLATE); - } - - return yamlTranslator.fromYaml(automationCompositionString, ToscaServiceTemplate.class); - } catch (FileNotFoundException e) { - LOGGER.error("cannot find YAML file {}", TestListenerUtils.TOSCA_TEMPLATE); - throw new IllegalArgumentException(e); - } - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/test/resources/application-test.yaml b/participant/participant-impl/participant-impl-simulator/src/test/resources/application-test.yaml deleted file mode 100644 index 3388f01a5..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/test/resources/application-test.yaml +++ /dev/null @@ -1,24 +0,0 @@ -participant: - intermediaryParameters: - reportingTimeInterval: 120000 - description: Participant Description - participantId: - version: 1.0.0 - name: org.onap.PM_CDS_Blueprint - participantType: - version: 1.0.0 - name: org.onap.PM_CDS_Blueprint - clampAutomationCompositionTopics: - topicSources: - - - topic: POLICY-ACRUNTIME-PARTICIPANT - servers: - - localhost - topicCommInfrastructure: dmaap - fetchTimeout: 15000 - topicSinks: - - - topicCommInfrastructure: dmaap - servers: - - localhost - topic: POLICY-ACRUNTIME-PARTICIPANT diff --git a/participant/participant-impl/pom.xml b/participant/participant-impl/pom.xml index b3cbad541..c75c8c7bd 100644 --- a/participant/participant-impl/pom.xml +++ b/participant/participant-impl/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- ============LICENSE_START======================================================= - Copyright (C) 2021 Nordix Foundation. + Copyright (C) 2021-2022 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ <packaging>pom</packaging> <modules> - <module>participant-impl-simulator</module> + <module>participant-impl-acelement</module> <module>participant-impl-policy</module> <module>participant-impl-cds</module> <module>participant-impl-kubernetes</module> @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2021 Nordix Foundation. + Copyright (C) 2021-2022 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ o policy-clamp-participant-impl-cds: A standard participant for interworking with CDS o policy-clamp-participant-impl-kubernetes: A standard participant for Kubernetes microservices o policy-clamp-participant-impl-policy: A standard participant for handling polcies for Policy Framework - o policy-clamp-participant-impl-simulator: A participant simulator for integration testing + o policy-clamp-acm-element-impl: ACM element implementation for integration testing o policy-clamp-participant-impl-http: A standard participant for http configurations </description> |