aboutsummaryrefslogtreecommitdiffstats
path: root/so-monitoring/so-monitoring-service/src/main/java
diff options
context:
space:
mode:
authorwaqas.ikram <waqas.ikram@ericsson.com>2018-08-23 13:26:09 +0100
committerSeshu Kumar M <seshu.kumar.m@huawei.com>2018-09-08 04:42:09 +0000
commit3e9ee0977d0c8643f81e720bbf23e5a40864a0d8 (patch)
treec020d47d525165c0db3ff3c4376e30b772efb1c3 /so-monitoring/so-monitoring-service/src/main/java
parent1fa4f35a1525cdb36513cd43c171240699077f3b (diff)
Adding rest service for so monitoring
Change-Id: I9dac918998901d54b3cbc5477cc9c057c3019cb3 Issue-ID: SO-724 Signed-off-by: waqas.ikram <waqas.ikram@ericsson.com>
Diffstat (limited to 'so-monitoring/so-monitoring-service/src/main/java')
-rw-r--r--so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/JerseyConfiguration.java40
-rw-r--r--so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringApplication.java37
-rw-r--r--so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringController.java236
-rw-r--r--so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/WebApplicationConfig.java36
4 files changed, 349 insertions, 0 deletions
diff --git a/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/JerseyConfiguration.java b/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/JerseyConfiguration.java
new file mode 100644
index 0000000000..0f03f23898
--- /dev/null
+++ b/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/JerseyConfiguration.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.monitoring.rest.api;
+
+import javax.annotation.PostConstruct;
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author waqas.ikram@ericsson.com
+ */
+@Configuration
+@ApplicationPath("/so/monitoring")
+public class JerseyConfiguration extends ResourceConfig {
+
+ @PostConstruct
+ public void setUp() {
+ register(SoMonitoringController.class);
+ }
+
+}
diff --git a/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringApplication.java b/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringApplication.java
new file mode 100644
index 0000000000..7c5a8965b7
--- /dev/null
+++ b/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringApplication.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 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.so.monitoring.rest.api;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * @author waqas.ikram@ericsson.com
+ */
+@SpringBootApplication(scanBasePackages = {"org.onap"})
+public class SoMonitoringApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SoMonitoringApplication.class, args);
+
+ }
+
+}
diff --git a/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringController.java b/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringController.java
new file mode 100644
index 0000000000..913fb3f934
--- /dev/null
+++ b/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringController.java
@@ -0,0 +1,236 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.monitoring.rest.api;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.onap.so.montoring.db.service.DatabaseServiceProvider;
+import org.onap.so.montoring.exception.InvalidRestRequestException;
+import org.onap.so.montoring.exception.RestProcessingException;
+import org.onap.so.montoring.model.ActivityInstanceDetail;
+import org.onap.so.montoring.model.ProcessDefinitionDetail;
+import org.onap.so.montoring.model.ProcessInstanceDetail;
+import org.onap.so.montoring.model.ProcessInstanceIdDetail;
+import org.onap.so.montoring.model.ProcessInstanceVariableDetail;
+import org.onap.so.montoring.model.SoInfraRequest;
+import org.onap.so.montoring.rest.service.CamundaProcessDataServiceProvider;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.google.common.base.Optional;
+
+/**
+ * @author waqas.ikram@ericsson.com
+ */
+@Component
+@Path("/")
+public class SoMonitoringController {
+
+ private static final String INVALID_PROCESS_INSTANCE_ERROR_MESSAGE = "Invalid process instance id: ";
+
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(SoMonitoringController.class);
+
+ private final DatabaseServiceProvider databaseServiceProvider;
+
+ private final CamundaProcessDataServiceProvider camundaProcessDataServiceProvider;
+
+ @Autowired
+ public SoMonitoringController(final DatabaseServiceProvider databaseServiceProvider,
+ final CamundaProcessDataServiceProvider camundaProcessDataServiceProvider) {
+ this.databaseServiceProvider = databaseServiceProvider;
+ this.camundaProcessDataServiceProvider = camundaProcessDataServiceProvider;
+ }
+
+ @GET
+ @Path("/process-instance-id/{requestId}")
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public Response getProcessInstanceId(final @PathParam("requestId") String requestId) {
+ if (requestId == null || requestId.isEmpty()) {
+ return Response.status(Status.BAD_REQUEST).entity("Invalid Request id: " + requestId).build();
+ }
+ try {
+ final Optional<ProcessInstanceIdDetail> processInstanceId =
+ camundaProcessDataServiceProvider.getProcessInstanceIdDetail(requestId);
+ if (processInstanceId.isPresent()) {
+ return Response.status(Status.OK).entity(processInstanceId.get()).build();
+ }
+
+ LOGGER.error("Unable to find process instance id for : {}", requestId);
+ return Response.status(Status.NO_CONTENT).build();
+
+ } catch (final InvalidRestRequestException extensions) {
+ final String message = "Unable to find process instance id for : " + requestId;
+ LOGGER.error(message);
+ return Response.status(Status.BAD_REQUEST).entity(message).build();
+ } catch (final RestProcessingException restProcessingException) {
+ final String message = "Unable to process request for id: " + requestId;
+ LOGGER.error(message);
+ return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).build();
+ }
+ }
+
+ @GET
+ @Path("/process-instance/{processInstanceId}")
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public Response getSingleProcessInstance(final @PathParam("processInstanceId") String processInstanceId) {
+ if (processInstanceId == null || processInstanceId.isEmpty()) {
+ return Response.status(Status.BAD_REQUEST)
+ .entity(INVALID_PROCESS_INSTANCE_ERROR_MESSAGE + processInstanceId).build();
+ }
+ try {
+ final Optional<ProcessInstanceDetail> processInstanceDetail =
+ camundaProcessDataServiceProvider.getSingleProcessInstanceDetail(processInstanceId);
+ if (processInstanceDetail.isPresent()) {
+ return Response.status(Status.OK).entity(processInstanceDetail.get()).build();
+ }
+
+ LOGGER.error("Unable to find process instance id for : {}", processInstanceId);
+ return Response.status(Status.NO_CONTENT).build();
+
+ } catch (final InvalidRestRequestException extensions) {
+ final String message = "Unable to find process instance id for : " + processInstanceId;
+ LOGGER.error(message);
+ return Response.status(Status.BAD_REQUEST).entity(message).build();
+ } catch (final RestProcessingException restProcessingException) {
+ final String message = "Unable to process request for id: " + processInstanceId;
+ LOGGER.error(message);
+ return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).build();
+ }
+ }
+
+ @GET
+ @Path("/process-definition/{processDefinitionId}")
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public Response getProcessDefinitionXml(final @PathParam("processDefinitionId") String processDefinitionId) {
+ if (processDefinitionId == null || processDefinitionId.isEmpty()) {
+ return Response.status(Status.BAD_REQUEST).entity("Invalid process definition id: " + processDefinitionId)
+ .build();
+ }
+ try {
+ final Optional<ProcessDefinitionDetail> response =
+ camundaProcessDataServiceProvider.getProcessDefinition(processDefinitionId);
+ if (response.isPresent()) {
+ final ProcessDefinitionDetail definitionDetail = response.get();
+ return Response.status(Status.OK).entity(definitionDetail).build();
+ }
+ LOGGER.error("Unable to find process definition xml for processDefinitionId: {}", processDefinitionId);
+ return Response.status(Status.NO_CONTENT).build();
+
+ } catch (final InvalidRestRequestException extensions) {
+ final String message =
+ "Unable to find process definition xml for processDefinitionId: {}" + processDefinitionId;
+ return Response.status(Status.BAD_REQUEST).entity(message).build();
+ } catch (final RestProcessingException restProcessingException) {
+ final String message = "Unable to get process definition xml for id: " + processDefinitionId;
+ LOGGER.error(message);
+ return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).build();
+ }
+ }
+
+ @GET
+ @Path("/activity-instance/{processInstanceId}")
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public Response getActivityInstanceDetail(final @PathParam("processInstanceId") String processInstanceId) {
+ if (processInstanceId == null || processInstanceId.isEmpty()) {
+ return Response.status(Status.BAD_REQUEST)
+ .entity(INVALID_PROCESS_INSTANCE_ERROR_MESSAGE + processInstanceId).build();
+ }
+ try {
+ final List<ActivityInstanceDetail> activityInstanceDetails =
+ camundaProcessDataServiceProvider.getActivityInstance(processInstanceId);
+ return Response.status(Status.OK).entity(activityInstanceDetails).build();
+ } catch (final InvalidRestRequestException extensions) {
+ final String message = "Unable to find activity instance for processInstanceId: " + processInstanceId;
+ LOGGER.error(message);
+ return Response.status(Status.BAD_REQUEST).entity(message).build();
+ } catch (final RestProcessingException restProcessingException) {
+ final String message = "Unable to get activity instance detail for id: " + processInstanceId;
+ LOGGER.error(message);
+ return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).build();
+ }
+ }
+
+ @GET
+ @Path("/variable-instance/{processInstanceId}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getProcessInstanceVariables(final @PathParam("processInstanceId") String processInstanceId) {
+ if (processInstanceId == null || processInstanceId.isEmpty()) {
+ return Response.status(Status.BAD_REQUEST)
+ .entity(INVALID_PROCESS_INSTANCE_ERROR_MESSAGE + processInstanceId).build();
+ }
+ try {
+ final List<ProcessInstanceVariableDetail> processInstanceVariable =
+ camundaProcessDataServiceProvider.getProcessInstanceVariable(processInstanceId);
+ return Response.status(Status.OK).entity(processInstanceVariable).build();
+ } catch (final InvalidRestRequestException extensions) {
+ final String message =
+ "Unable to find process instance variables for processInstanceId: " + processInstanceId;
+ LOGGER.error(message);
+ return Response.status(Status.BAD_REQUEST).entity(message).build();
+ } catch (final RestProcessingException restProcessingException) {
+ final String message = "Unable to get process instance variables for id: " + processInstanceId;
+ LOGGER.error(message);
+ return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).build();
+ }
+ }
+
+ @POST
+ @Path("/v1/search")
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public Response getInfraActiveRequests(final Map<String, String[]> filters,
+ @QueryParam("from") final long startTime, @QueryParam("to") final long endTime,
+ @QueryParam("maxResult") final Integer maxResult) {
+
+ if (filters == null) {
+ return Response.status(Status.BAD_REQUEST).entity("Invalid filters: " + filters).build();
+ }
+ try {
+ final List<SoInfraRequest> requests =
+ databaseServiceProvider.getSoInfraRequest(filters, startTime, endTime, maxResult);
+ LOGGER.info("result size: {}", requests.size());
+ return Response.status(Status.OK).entity(requests).build();
+
+ } catch (final InvalidRestRequestException extensions) {
+ final String message = "Unable to search request for filters: " + filters + ", from: " + startTime
+ + ", to: " + endTime + ", maxResult: " + maxResult;
+ LOGGER.error(message);
+ return Response.status(Status.BAD_REQUEST).entity(message).build();
+ } catch (final RestProcessingException restProcessingException) {
+ final String message = "Unable to search request for filters: " + filters + ", from: " + startTime
+ + ", to: " + endTime + ", maxResult: " + maxResult;
+ LOGGER.error(message);
+ return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).build();
+ }
+ }
+
+}
diff --git a/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/WebApplicationConfig.java b/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/WebApplicationConfig.java
new file mode 100644
index 0000000000..cadd60b0d9
--- /dev/null
+++ b/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/WebApplicationConfig.java
@@ -0,0 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.monitoring.rest.api;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+/**
+ * @author waqas.ikram@ericsson.com
+ */
+@Configuration
+public class WebApplicationConfig extends WebMvcConfigurerAdapter {
+ @Override
+ public void addViewControllers(final ViewControllerRegistry registry) {
+ super.addViewControllers(registry);
+ registry.addViewController("/details/**").setViewName("forward:/");
+ }
+}