aboutsummaryrefslogtreecommitdiffstats
path: root/tosca-controlloop/runtime/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'tosca-controlloop/runtime/src/main/java')
-rw-r--r--tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationHandler.java109
-rw-r--r--tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationController.java416
-rw-r--r--tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/ControlLoopAafFilter.java38
-rw-r--r--tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/RestController.java115
-rw-r--r--tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/startstop/ClRuntimeActivator.java42
5 files changed, 720 insertions, 0 deletions
diff --git a/tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationHandler.java b/tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationHandler.java
new file mode 100644
index 000000000..c4b0955f9
--- /dev/null
+++ b/tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationHandler.java
@@ -0,0 +1,109 @@
+/*-
+ * ============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.controlloop.runtime.instantiation;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import javax.ws.rs.core.Response;
+import lombok.Getter;
+import org.onap.policy.clamp.controlloop.common.handler.ControlLoopHandler;
+import org.onap.policy.clamp.controlloop.runtime.instantiation.rest.InstantiationController;
+import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
+import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher;
+import org.onap.policy.common.utils.services.Registry;
+import org.onap.policy.models.base.PfModelRuntimeException;
+
+/**
+ * This class handles instantiation of control loop instances,
+ * so only one object of this type should be built at a time.
+ *
+ * </p>
+ * It is effectively a singleton that is started at system start
+ */
+public final class InstantiationHandler extends ControlLoopHandler {
+
+ @Getter
+ private ControlLoopInstantiationProvider controlLoopInstantiationProvider;
+
+ /**
+ * Gets the InstantiationHandler.
+ *
+ * @return InstantiationHandler
+ */
+ public static InstantiationHandler getInstance() {
+ return Registry.get(InstantiationHandler.class.getName());
+ }
+
+ /**
+ * Create a handler.
+ *
+ * @param controlLoopParameters the parameters for access to the database
+ */
+ public InstantiationHandler(ClRuntimeParameterGroup controlLoopParameters) {
+ super(controlLoopParameters.getDatabaseProviderParameters());
+ }
+
+ @Override
+ public Set<Class<?>> getProviderClasses() {
+ Set<Class<?>> providerClasses = new HashSet<>();
+
+ providerClasses.add(InstantiationController.class);
+
+ return providerClasses;
+ }
+
+ @Override
+ public void startAndRegisterListeners(MessageTypeDispatcher msgDispatcher) {
+ // No topic communication on this handler
+ }
+
+ @Override
+ public void startAndRegisterPublishers(List<TopicSink> topicSinks) {
+ // No topic communication on this handler
+ }
+
+ @Override
+ public void stopAndUnregisterPublishers() {
+ // No topic communication on this handler
+ }
+
+ @Override
+ public void stopAndUnregisterListeners(MessageTypeDispatcher msgDispatcher) {
+ // No topic communication on this handler
+ }
+
+ @Override
+ public void startProviders() {
+ controlLoopInstantiationProvider = new ControlLoopInstantiationProvider(getDatabaseProviderParameters());
+ }
+
+ @Override
+ public void stopProviders() {
+ try {
+ controlLoopInstantiationProvider.close();
+ } catch (IOException e) {
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
+ }
+ }
+}
diff --git a/tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationController.java b/tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationController.java
new file mode 100644
index 000000000..807da5d68
--- /dev/null
+++ b/tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationController.java
@@ -0,0 +1,416 @@
+/*-
+ * ============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.controlloop.runtime.instantiation.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.UUID;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
+import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationCommand;
+import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationResponse;
+import org.onap.policy.clamp.controlloop.runtime.instantiation.ControlLoopInstantiationProvider;
+import org.onap.policy.clamp.controlloop.runtime.instantiation.InstantiationHandler;
+import org.onap.policy.clamp.controlloop.runtime.main.rest.RestController;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.errors.concepts.ErrorResponseInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class to provide REST end points for creating, deleting, query and commanding a control loop definition.
+ */
+public class InstantiationController extends RestController {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(InstantiationController.class);
+
+ // The CL provider for instantiation requests
+ private final ControlLoopInstantiationProvider provider;
+
+ /**
+ * create Instantiation Controller.
+ */
+ public InstantiationController() {
+ this.provider = InstantiationHandler.getInstance().getControlLoopInstantiationProvider();
+ }
+
+ /**
+ * Creates a control loop.
+ *
+ * @param requestId request ID used in ONAP logging
+ * @param controlLoops the control loops
+ * @return a response
+ */
+ // @formatter:off
+ @POST
+ @Path("/instantiation")
+ @ApiOperation(
+ value = "Commissions control loop definitions",
+ notes = "Commissions control loop definitions, returning the control loop IDs",
+ response = InstantiationResponse.class,
+ tags = {
+ "Control Loop Instantiation 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 Response create(
+ @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "Entity Body of Control Loop", required = true) ControlLoops controlLoops) {
+
+ try {
+ InstantiationResponse response = provider.createControlLoops(controlLoops);
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Status.OK)), requestId).entity(response)
+ .build();
+
+ } catch (PfModelRuntimeException | PfModelException e) {
+ LOGGER.warn("creation of control loop failed", e);
+ return createInstantiationErrorResponse(e, requestId);
+ }
+ }
+
+ /**
+ * Queries details of all control loops.
+ *
+ * @param requestId request ID used in ONAP logging
+ * @param name the name of the control loop to get, null for all control loops
+ * @param version the version of the control loop to get, null for all control loops
+ * @return the control loops
+ */
+ // @formatter:off
+ @GET
+ @Path("/instantiation")
+ @ApiOperation(value = "Query details of the requested control loops",
+ notes = "Queries details of the requested control loops, returning all control loop details",
+ response = ControlLoops.class,
+ tags = {
+ "Clamp control loop Instantiation 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 Response query(
+ @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "Control Loop definition name", required = true) @QueryParam("name") String name,
+ @ApiParam(value = "Control Loop definition version",
+ required = true) @QueryParam("version") String version) {
+
+ try {
+ ControlLoops response = provider.getControlLoops(name, version);
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Status.OK)), requestId).entity(response)
+ .build();
+
+ } catch (PfModelRuntimeException | PfModelException e) {
+ LOGGER.warn("commisssioning of control loop failed", e);
+ return createInstantiationErrorResponse(e, requestId);
+ }
+
+ }
+
+ /**
+ * Updates a control loop.
+ *
+ * @param requestId request ID used in ONAP logging
+ * @param controlLoops the control loops
+ * @return a response
+ */
+ // @formatter:off
+ @PUT
+ @Path("/instantiation")
+ @ApiOperation(
+ value = "Updates control loop definitions",
+ notes = "Updates control loop definitions, returning the updated control loop definition IDs",
+ response = InstantiationResponse.class,
+ tags = {
+ "Control Loop Instantiation 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 Response update(
+ @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "Entity Body of Control Loop", required = true) ControlLoops controlLoops) {
+
+ try {
+ InstantiationResponse response = provider.updateControlLoops(controlLoops);
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Status.OK)), requestId).entity(response)
+ .build();
+
+ } catch (PfModelRuntimeException | PfModelException e) {
+ LOGGER.warn("update of control loops failed", e);
+ return createInstantiationErrorResponse(e, requestId);
+ }
+ }
+
+ /**
+ * Deletes a control loop definition.
+ *
+ * @param requestId request ID used in ONAP logging
+ * @param name the name of the control loop to delete
+ * @param version the version of the control loop to delete
+ * @return a response
+ */
+ // @formatter:off
+ @DELETE
+ @Path("/instantiation")
+ @ApiOperation(value = "Delete a control loop",
+ notes = "Deletes a control loop, returning optional error details",
+ response = InstantiationResponse.class,
+ tags = {
+ "Clamp Control Loop Instantiation 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 Response delete(
+ @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "Control Loop definition name", required = true) @QueryParam("name") String name,
+ @ApiParam(value = "Control Loop definition version", required = true)
+ @QueryParam("version") String version) {
+
+ try {
+ InstantiationResponse response = provider.deleteControlLoop(name, version);
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Status.OK)), requestId).entity(response)
+ .build();
+
+ } catch (PfModelRuntimeException | PfModelException e) {
+ LOGGER.warn("delete of control loop failed", e);
+ return createInstantiationErrorResponse(e, requestId);
+ }
+ }
+
+ /**
+ * Issues control loop commands to control loops.
+ *
+ * @param requestId request ID used in ONAP logging
+ * @param command the command to issue to control loops
+ * @return the control loop definitions
+ */
+ // @formatter:off
+ @PUT
+ @Path("/instantiation/command")
+ @ApiOperation(value = "Issue a command to the requested control loops",
+ notes = "Issues a command to a control loop, ordering a state change on the control loop",
+ response = InstantiationResponse.class,
+ tags = {
+ "Clamp Control Loop Instantiation 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 Response issueControlLoopCommand(
+ @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "Entity Body of control loop command", required = true) InstantiationCommand command) {
+
+ try {
+ InstantiationResponse response = provider.issueControlLoopCommand(command);
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Status.ACCEPTED)), requestId)
+ .entity(response).build();
+
+ } catch (PfModelRuntimeException | PfModelException | ControlLoopException e) {
+ LOGGER.warn("creation of control loop failed", e);
+ return createInstantiationErrorResponse(e, requestId);
+ }
+ }
+
+ /**
+ * create a Instantiation Response from an exception.
+ * @param e the error
+ * @param requestId request ID used in ONAP logging
+ * @return the Instantiation Response
+ */
+ private Response createInstantiationErrorResponse(ErrorResponseInfo e, UUID requestId) {
+ InstantiationResponse resp = new InstantiationResponse();
+ resp.setErrorDetails(e.getErrorResponse().getErrorMessage());
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(e.getErrorResponse().getResponseCode())),
+ requestId).entity(resp).build();
+ }
+
+}
diff --git a/tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/ControlLoopAafFilter.java b/tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/ControlLoopAafFilter.java
new file mode 100644
index 000000000..f166de5d6
--- /dev/null
+++ b/tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/ControlLoopAafFilter.java
@@ -0,0 +1,38 @@
+/*-
+ * ============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.controlloop.runtime.main.rest;
+
+import org.onap.policy.common.endpoints.http.server.aaf.AafGranularAuthFilter;
+import org.onap.policy.common.utils.resources.MessageConstants;
+
+/**
+ * Class to manage AAF filters for the control loop runtime component.
+ */
+public class ControlLoopAafFilter extends AafGranularAuthFilter {
+
+ public static final String AAF_NODETYPE = MessageConstants.POLICY_CLAMP;
+ public static final String AAF_ROOT_PERMISSION = DEFAULT_NAMESPACE + "." + AAF_NODETYPE;
+
+ @Override
+ public String getPermissionTypeRoot() {
+ return AAF_ROOT_PERMISSION;
+ }
+}
diff --git a/tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/RestController.java b/tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/RestController.java
new file mode 100644
index 000000000..dd3fa30fc
--- /dev/null
+++ b/tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/RestController.java
@@ -0,0 +1,115 @@
+/*-
+ * ============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.controlloop.runtime.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.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+/**
+ * Common superclass to provide REST endpoints for the control loop service.
+ */
+// @formatter:off
+@Path("/onap/controlloop/v2")
+@Api(value = "Control Loop API")
+@Produces({MediaType.APPLICATION_JSON, RestController.APPLICATION_YAML})
+@SwaggerDefinition(
+ info = @Info(description =
+ "Control Loop Service", version = "v1.0",
+ title = "Control Loop"),
+ consumes = {MediaType.APPLICATION_JSON, RestController.APPLICATION_YAML},
+ produces = {MediaType.APPLICATION_JSON, RestController.APPLICATION_YAML},
+ schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
+ tags = {@Tag(name = "controlloop", description = "Control Loop Service")},
+ securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
+// @formatter:on
+public class RestController {
+ 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";
+
+ /**
+ * Adds version headers to the response.
+ *
+ * @param respBuilder response builder
+ * @return the response builder, with version headers
+ */
+ public ResponseBuilder addVersionControlHeaders(ResponseBuilder respBuilder) {
+ return respBuilder.header(VERSION_MINOR_NAME, "0").header(VERSION_PATCH_NAME, "0").header(VERSION_LATEST_NAME,
+ API_VERSION);
+ }
+
+ /**
+ * Adds logging headers to the response.
+ *
+ * @param respBuilder response builder
+ * @return the response builder, with version logging
+ */
+ public ResponseBuilder addLoggingHeaders(ResponseBuilder respBuilder, UUID requestId) {
+ if (requestId == null) {
+ // Generate a random uuid if client does not embed requestId in rest request
+ return respBuilder.header(REQUEST_ID_NAME, UUID.randomUUID());
+ }
+
+ return respBuilder.header(REQUEST_ID_NAME, requestId);
+ }
+}
diff --git a/tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/startstop/ClRuntimeActivator.java b/tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/startstop/ClRuntimeActivator.java
index 8ac4d684d..d3a5c5810 100644
--- a/tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/startstop/ClRuntimeActivator.java
+++ b/tosca-controlloop/runtime/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/startstop/ClRuntimeActivator.java
@@ -21,11 +21,17 @@
package org.onap.policy.clamp.controlloop.runtime.main.startstop;
import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
import javax.ws.rs.core.Response.Status;
import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
+import org.onap.policy.clamp.controlloop.runtime.instantiation.InstantiationHandler;
import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
+import org.onap.policy.clamp.controlloop.runtime.main.rest.ControlLoopAafFilter;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
+import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
+import org.onap.policy.common.endpoints.http.server.RestServer;
import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.utils.services.ServiceManagerContainer;
@@ -41,6 +47,7 @@ public class ClRuntimeActivator extends ServiceManagerContainer {
private final ClRuntimeParameterGroup clRuntimeParameterGroup;
// Topics from which the application receives and to which the application sends messages
+ private List<TopicSink> topicSinks;
private List<TopicSource> topicSources;
/**
@@ -61,6 +68,9 @@ public class ClRuntimeActivator extends ServiceManagerContainer {
this.clRuntimeParameterGroup = clRuntimeParameterGroup;
+ topicSinks = TopicEndpointManager.getManager()
+ .addTopicSinks(clRuntimeParameterGroup.getTopicParameterGroup().getTopicSinks());
+
topicSources = TopicEndpointManager.getManager()
.addTopicSources(clRuntimeParameterGroup.getTopicParameterGroup().getTopicSources());
@@ -71,6 +81,9 @@ public class ClRuntimeActivator extends ServiceManagerContainer {
"topic message dispatcher failed to start", e);
}
+ final AtomicReference<InstantiationHandler> instantiationHandler = new AtomicReference<>();
+ final AtomicReference<RestServer> restServer = new AtomicReference<>();
+
// @formatter:off
addAction("Control loop runtime parameters",
() -> ParameterService.register(clRuntimeParameterGroup),
@@ -80,9 +93,38 @@ public class ClRuntimeActivator extends ServiceManagerContainer {
() -> TopicEndpointManager.getManager().start(),
() -> TopicEndpointManager.getManager().shutdown());
+ addAction("Instantiation Handler",
+ () -> instantiationHandler.set(new InstantiationHandler(clRuntimeParameterGroup)),
+ () -> instantiationHandler.get().close());
+
+ addAction("Providers",
+ () -> instantiationHandler.get().startProviders(),
+ () -> instantiationHandler.get().stopProviders());
+
+ addAction("Listeners",
+ () -> instantiationHandler.get().startAndRegisterListeners(msgDispatcher),
+ () -> instantiationHandler.get().stopAndUnregisterListeners(msgDispatcher));
+
+ addAction("Publishers",
+ () -> instantiationHandler.get().startAndRegisterPublishers(topicSinks),
+ () -> instantiationHandler.get().stopAndUnregisterPublishers());
+
addAction("Topic Message Dispatcher", this::registerMsgDispatcher, this::unregisterMsgDispatcher);
clRuntimeParameterGroup.getRestServerParameters().setName(clRuntimeParameterGroup.getName());
+
+ addAction("REST server",
+ () -> {
+ Set<Class<?>> providerClasses = instantiationHandler.get().getProviderClasses();
+
+ RestServer server = new RestServer(clRuntimeParameterGroup.getRestServerParameters(),
+ ControlLoopAafFilter.class,
+ providerClasses.toArray(new Class<?>[providerClasses.size()]));
+
+ restServer.set(server);
+ restServer.get().start();
+ },
+ () -> restServer.get().stop());
// @formatter:on
}