diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml new file mode 100644 index 0000000000..e28cd015e8 --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml @@ -0,0 +1,338 @@ + + + + + + + org.wso2.carbon.devicemgt + grafana-mgt + 5.0.1-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.analytics.mgt.grafana.proxy.api + war + Entgra - Grafana Proxy API + Entgra - Grafana Proxy API + http://entgra.io + + + + + maven-compiler-plugin + + 1.8 + 1.8 + + + + maven-war-plugin + + WEB-INF/lib/*cxf*.jar + api#grafana-mgt#v1.0 + + + + + + + + deploy + + compile + + + org.apache.maven.plugins + maven-antrun-plugin + 1.7 + + + compile + + run + + + + + + + + + + + + + + + + + + + + + org.testng + testng + test + + + org.springframework + spring-web + provided + + + org.apache.cxf + cxf-bundle + 3.0.0-milestone2 + test + + + org.apache.cxf + cxf-bundle-jaxrs + provided + + + commons-httpclient.wso2 + commons-httpclient + provided + + + org.wso2.carbon + org.wso2.carbon.utils + provided + + + org.wso2.carbon.identity.framework + org.wso2.carbon.user.mgt + provided + + + org.slf4j + slf4j-api + + + org.slf4j + jcl-over-slf4j + + + + + org.wso2.carbon + org.wso2.carbon.logging + provided + + + org.wso2.carbon.identity.inbound.auth.oauth2 + org.wso2.carbon.identity.oauth.stub + provided + + + org.apache.axis2.wso2 + axis2-client + + + + + org.json.wso2 + json + + + commons-codec.wso2 + commons-codec + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.certificate.mgt.core + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + + + + + io.swagger + swagger-annotations + + + io.swagger + swagger-core + + + com.fasterxml.jackson.module + jackson-module-jaxb-annotations + + + org.slf4j + slf4j-api + + + org.wso2.orbit.com.fasterxml.jackson.core + jackson-core + + + + + io.swagger + swagger-jaxrs + + + com.fasterxml.jackson.module + jackson-module-jaxb-annotations + + + org.slf4j + slf4j-api + + + org.wso2.orbit.com.fasterxml.jackson.core + jackson-core + + + + + javax.servlet + javax.servlet-api + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.annotations + provided + + + org.wso2.orbit.com.fasterxml.jackson.core + jackson-annotations + + + org.hibernate + hibernate-validator + + + javax.ws.rs + javax.ws.rs-api + provided + + + javax.ws.rs + jsr311-api + provided + + + org.wso2.carbon.commons + org.wso2.carbon.application.mgt.stub + provided + + + org.wso2.carbon.analytics + org.wso2.carbon.analytics.api + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.identity.jwt.client.extension + provided + + + org.wso2.carbon + org.wso2.carbon.registry.core + provided + + + org.wso2.carbon.registry + org.wso2.carbon.registry.resource + provided + + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.user.store.count + ${carbon.identity.framework.version} + provided + + + + + + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.receiver.stub + provided + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.stream.stub + provided + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.publisher.stub + provided + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.stream.persistence.stub + provided + + + org.powermock + powermock-module-testng + test + + + org.powermock + powermock-api-mockito + test + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.extensions + provided + + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.claim.metadata.mgt + ${carbon.identity.framework.version} + provided + + + org.wso2.carbon.devicemgt + io.entgra.analytics.mgt.grafana.proxy.core + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + provided + + + org.wso2.carbon.devicemgt + io.entgra.analytics.mgt.grafana.proxy.common + provided + + + + diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/GrafanaAPIProxyService.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/GrafanaAPIProxyService.java new file mode 100644 index 0000000000..b4b38e40fd --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/GrafanaAPIProxyService.java @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.entgra.analytics.mgt.grafana.proxy.api.service; + +import com.google.gson.JsonObject; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.Extension; +import io.swagger.annotations.ExtensionProperty; +import io.swagger.annotations.Info; +import io.swagger.annotations.SwaggerDefinition; +import io.swagger.annotations.Tag; +import org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +@SwaggerDefinition( + info = @Info( + version = "1.0.0", + title = "Grafana API Proxy Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "name", value = "GrafanaAPIManagement"), + @ExtensionProperty(name = "context", value = "/api/grafana-mgt/v1.0/api"), + }) + } + ), + tags = { + @Tag(name = "analytics_management", description = "") + } +) +@Scopes( + scopes = { + @Scope( + name = "Using Grafana APIs required for Grafana iframes", + description = "Grafana API proxy to validate requests.", + key = "perm:grafana:api:view", + roles = {"Internal/grafanamgt-user"}, + permissions = {"/analytics-mgt/grafana-mgt/api/view"} + ) + } +) + +@Path("/api") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.MEDIA_TYPE_WILDCARD) +@Api(value = "Grafana API Management", description = "Grafana api related operations can be found here.") +public interface GrafanaAPIProxyService { + + String SCOPE = "scope"; + + @POST + @Path("/ds/query") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Grafana query API proxy", + tags = "Analytics", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:grafana:api:view") + }) + } + ) + Response queryDatasource(JsonObject body, @Context HttpHeaders headers, @Context UriInfo requestUriInfo); + + @POST + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @Path("/frontend-metrics") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Grafana frontend-metric API proxy", + tags = "Analytics", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:grafana:api:view") + }) + } + ) + Response frontendMetrics(JsonObject body, @Context HttpHeaders headers, @Context UriInfo requestUriInfo); + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/dashboards/uid/{uid}") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Grafana dashboard details API proxy", + tags = "Analytics", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:grafana:api:view") + }) + } + ) + Response getDashboard(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) throws ClassNotFoundException; + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @Path("/annotations") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Grafana annotations API proxy", + tags = "Analytics", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:grafana:api:view") + }) + } + ) + Response getAnnotations(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) throws ClassNotFoundException; + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/alerts/states-for-dashboard") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Get Grafana alert states for dashboard details API proxy", + tags = "Analytics", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:grafana::api:view") + }) + } + ) + Response getAlertStateForDashboards(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) throws ClassNotFoundException; +} diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/addons/ApiOriginFilter.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/addons/ApiOriginFilter.java new file mode 100644 index 0000000000..5562c40ad0 --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/addons/ApiOriginFilter.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2021, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.entgra.analytics.mgt.grafana.proxy.api.service.addons; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class ApiOriginFilter implements Filter { + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + HttpServletResponse res = (HttpServletResponse) response; + res.addHeader("Access-Control-Allow-Origin", "*"); + res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); + res.addHeader("Access-Control-Allow-Headers", "Content-Type"); + chain.doFilter(request, response); + } + + public void destroy() { + //do nothing + } + + public void init(FilterConfig filterConfig) throws ServletException { + //do nothing + } +} diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/addons/GsonMessageBodyHandler.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/addons/GsonMessageBodyHandler.java new file mode 100644 index 0000000000..f786cf645e --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/addons/GsonMessageBodyHandler.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.entgra.analytics.mgt.grafana.proxy.api.service.addons; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyReader; +import javax.ws.rs.ext.MessageBodyWriter; +import javax.ws.rs.ext.Provider; +import java.io.*; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import static javax.ws.rs.core.MediaType.APPLICATION_JSON; + +@Provider +@Produces(APPLICATION_JSON) +@Consumes(APPLICATION_JSON) +public class GsonMessageBodyHandler implements MessageBodyWriter, MessageBodyReader { + + public static final String DATE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z"; + private Gson gson; + private static final String UTF_8 = "UTF-8"; + + public boolean isReadable(Class aClass, Type type, Annotation[] annotations, MediaType mediaType) { + return true; + } + + private Gson getGson() { + if (gson == null) { + final GsonBuilder gsonBuilder = new GsonBuilder(); + gson = gsonBuilder.setDateFormat(DATE_FORMAT).create(); + } + return gson; + } + + public Object readFrom(Class objectClass, Type type, Annotation[] annotations, MediaType mediaType, + MultivaluedMap stringStringMultivaluedMap, InputStream entityStream) + throws IOException, WebApplicationException { + + InputStreamReader reader = new InputStreamReader(entityStream, "UTF-8"); + + try { + return getGson().fromJson(reader, type); + } finally { + reader.close(); + } + } + + public boolean isWriteable(Class aClass, Type type, Annotation[] annotations, MediaType mediaType) { + return true; + } + + public long getSize(Object o, Class aClass, Type type, Annotation[] annotations, MediaType mediaType) { + return -1; + } + + public void writeTo(Object object, Class aClass, Type type, Annotation[] annotations, MediaType mediaType, + MultivaluedMap stringObjectMultivaluedMap, OutputStream entityStream) + throws IOException, WebApplicationException { + + OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8); + try { + getGson().toJson(object, type, writer); + } finally { + writer.close(); + } + } +} diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/addons/ValidationInterceptor.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/addons/ValidationInterceptor.java new file mode 100644 index 0000000000..3ff1928ef6 --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/addons/ValidationInterceptor.java @@ -0,0 +1,121 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.entgra.analytics.mgt.grafana.proxy.api.service.addons; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.cxf.interceptor.Fault; +import org.apache.cxf.jaxrs.lifecycle.ResourceProvider; +import org.apache.cxf.jaxrs.model.ClassResourceInfo; +import org.apache.cxf.jaxrs.model.OperationResourceInfo; +import org.apache.cxf.message.Message; +import org.apache.cxf.message.MessageContentsList; +import org.apache.cxf.phase.AbstractPhaseInterceptor; +import org.apache.cxf.phase.Phase; + +import javax.validation.ConstraintViolation; +import javax.validation.ConstraintViolationException; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; +import javax.validation.executable.ExecutableValidator; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Set; + +public class ValidationInterceptor extends AbstractPhaseInterceptor { + private Log log = LogFactory.getLog(getClass()); + private Validator validator = null; //validator interface is thread-safe + + public ValidationInterceptor() { + super(Phase.PRE_INVOKE); + ValidatorFactory defaultFactory = Validation.buildDefaultValidatorFactory(); + validator = defaultFactory.getValidator(); + if (validator == null) { + log.warn("Bean Validation provider could not be found, no validation will be performed"); + } else { + log.debug("Validation In-Interceptor initialized successfully"); + } + } + + @Override + public void handleMessage(Message message) throws Fault { + final OperationResourceInfo operationResource = message.getExchange().get(OperationResourceInfo.class); + if (operationResource == null) { + log.info("OperationResourceInfo is not available, skipping validation"); + return; + } + + final ClassResourceInfo classResource = operationResource.getClassResourceInfo(); + if (classResource == null) { + log.info("ClassResourceInfo is not available, skipping validation"); + return; + } + + final ResourceProvider resourceProvider = classResource.getResourceProvider(); + if (resourceProvider == null) { + log.info("ResourceProvider is not available, skipping validation"); + return; + } + + final List arguments = MessageContentsList.getContentsList(message); + final Method method = operationResource.getAnnotatedMethod(); + final Object instance = resourceProvider.getInstance(message); + if (method != null && arguments != null) { + //validate the parameters(arguments) over the invoked method + validate(method, arguments.toArray(), instance); + + //validate the fields of each argument + for (Object arg : arguments) { + if (arg != null) + validate(arg); + } + } + + } + + public void validate(final Method method, final Object[] arguments, final T instance) { + if (validator == null) { + log.warn("Bean Validation provider could not be found, no validation will be performed"); + return; + } + + ExecutableValidator methodValidator = validator.forExecutables(); + Set> violations = methodValidator.validateParameters(instance, + method, arguments); + + if (!violations.isEmpty()) { + throw new ConstraintViolationException(violations); + } + } + + public void validate(final T object) { + if (validator == null) { + log.warn("Bean Validation provider could be found, no validation will be performed"); + return; + } + + Set> violations = validator.validate(object); + + if (!violations.isEmpty()) { + throw new ConstraintViolationException(violations); + } + } + + public void handleFault(org.apache.cxf.message.Message messageParam) { + } +} diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/bean/ErrorListItem.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/bean/ErrorListItem.java new file mode 100644 index 0000000000..aca4e22b56 --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/bean/ErrorListItem.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package io.entgra.analytics.mgt.grafana.proxy.api.service.bean; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.NotNull; + +@ApiModel(description = "") +public class ErrorListItem { + + @NotNull + private String code = null; + @NotNull + private String message = null; + + @ApiModelProperty(required = true, value = "") + @JsonProperty("code") + public String getCode() { + return code; + } + public void setCode(String code) { + this.code = code; + } + + public ErrorListItem() {} + + public ErrorListItem(String code, String msg) { + this.code = code; + this.message = msg; + } + + + /** + * Description about individual errors occurred + **/ + @ApiModelProperty(required = true, value = "Description about individual errors occurred") + @JsonProperty("message") + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("errorItem {\n"); + + sb.append(" code: ").append(code).append("\n"); + sb.append(" message: ").append(message).append("\n"); + sb.append("}\n"); + return sb.toString(); + } + +} diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/bean/ErrorResponse.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/bean/ErrorResponse.java new file mode 100644 index 0000000000..1287ce5f76 --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/bean/ErrorResponse.java @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package io.entgra.analytics.mgt.grafana.proxy.api.service.bean; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.ArrayList; +import java.util.List; + +@ApiModel(description = "") +public class ErrorResponse { + + private Long code = null; + private String message = null; + private String description = null; + private String moreInfo = null; + private List errorItems = new ArrayList<>(); + + public ErrorResponse() { + } + + @JsonProperty(value = "code") + @ApiModelProperty(required = true, value = "") + public Long getCode() { + return code; + } + + public void setCode(Long code) { + this.code = code; + } + + @JsonProperty(value = "message") + @ApiModelProperty(required = true, value = "ErrorResponse message.") + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @JsonProperty(value = "description") + @ApiModelProperty(value = "A detail description about the error message.") + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @JsonProperty(value = "moreInfo") + @ApiModelProperty(value = "Preferably an url with more details about the error.") + public String getMoreInfo() { + return moreInfo; + } + + public void setMoreInfo(String moreInfo) { + this.moreInfo = moreInfo; + } + + public void addErrorListItem(ErrorListItem item) { + this.errorItems.add(item); + } + + /** + * If there are more than one error list them out. \nFor example, list out validation errors by each field. + */ + @JsonProperty(value = "errorItems") + @ApiModelProperty(value = "If there are more than one error list them out. \n" + + "For example, list out validation errors by each field.") + public List getErrorItems() { + return errorItems; + } + + public void setErrorItems(List error) { + this.errorItems = error; + } + + @Override + public String toString() { + return null; + } + + public static class ErrorResponseBuilder { + + private Long code = null; + private String message = null; + private String description = null; + private String moreInfo = null; + private List error; + + + public ErrorResponseBuilder() { + this.error = new ArrayList<>(); + } + + public ErrorResponseBuilder setCode(long code) { + this.code = code; + return this; + } + + public ErrorResponseBuilder setMessage(String message) { + this.message = message; + return this; + } + + public ErrorResponseBuilder setDescription(String description) { + this.description = description; + return this; + } + + public ErrorResponseBuilder setMoreInfo(String moreInfo) { + this.moreInfo = moreInfo; + return this; + } + + public ErrorResponseBuilder addErrorItem(String code, String msg) { + ErrorListItem item = new ErrorListItem(); + item.setCode(code); + item.setMessage(msg); + this.error.add(item); + return this; + } + + public ErrorResponse build() { + ErrorResponse errorResponse = new ErrorResponse(); + errorResponse.setCode(code); + errorResponse.setMessage(message); + errorResponse.setErrorItems(error); + errorResponse.setDescription(description); + errorResponse.setMoreInfo(moreInfo); + return errorResponse; + } + } + +} + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/RefererNotValid.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/exception/RefererNotValid.java similarity index 63% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/RefererNotValid.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/exception/RefererNotValid.java index 0a36f34b23..2e39f3d62e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/RefererNotValid.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/exception/RefererNotValid.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.mgt.jaxrs.exception; +package io.entgra.analytics.mgt.grafana.proxy.api.service.exception; public class RefererNotValid extends Exception { public RefererNotValid(String msg) { diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/impl/GrafanaAPIProxyServiceImpl.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/impl/GrafanaAPIProxyServiceImpl.java new file mode 100644 index 0000000000..ee227b3f18 --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/impl/GrafanaAPIProxyServiceImpl.java @@ -0,0 +1,116 @@ +package io.entgra.analytics.mgt.grafana.proxy.api.service.impl; + +import com.google.gson.JsonObject; +import io.entgra.analytics.mgt.grafana.proxy.api.service.GrafanaAPIProxyService; +import io.entgra.analytics.mgt.grafana.proxy.api.service.bean.ErrorResponse; +import io.entgra.analytics.mgt.grafana.proxy.api.service.exception.RefererNotValid; +import io.entgra.analytics.mgt.grafana.proxy.api.service.impl.util.GrafanaRequestHandlerUtil; +import io.entgra.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException; +import io.entgra.analytics.mgt.grafana.proxy.core.bean.GrafanaPanelIdentifier; +import io.entgra.analytics.mgt.grafana.proxy.core.exception.MaliciousQueryAttempt; +import io.entgra.analytics.mgt.grafana.proxy.core.internal.GrafanaMgtDataHolder; +import io.entgra.analytics.mgt.grafana.proxy.core.util.GrafanaUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.exceptions.DBConnectionException; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; +import java.io.IOException; +import java.sql.SQLException; + +@Path("/api") +public class GrafanaAPIProxyServiceImpl implements GrafanaAPIProxyService { + + private static final Log log = LogFactory.getLog(GrafanaAPIProxyServiceImpl.class); + + @POST + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @Path("/ds/query") + @Override + public Response queryDatasource(JsonObject body, @Context HttpHeaders headers, @Context UriInfo requestUriInfo) { + try { + GrafanaPanelIdentifier panelIdentifier = GrafanaRequestHandlerUtil.getPanelIdentifier(headers); + GrafanaMgtDataHolder.getInstance().getGrafanaQueryService(). + buildSafeQuery(body, panelIdentifier.getDashboardId(), panelIdentifier.getPanelId(), requestUriInfo.getRequestUri()); + return GrafanaRequestHandlerUtil.proxyPassPostRequest(body, requestUriInfo, panelIdentifier.getOrgId()); + } catch (MaliciousQueryAttempt e) { + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(e.getMessage()).build()).build(); + } catch (GrafanaManagementException e) { + return GrafanaRequestHandlerUtil.constructInternalServerError(e, e.getMessage()); + } catch (RefererNotValid e) { + return GrafanaRequestHandlerUtil.constructInvalidReferer(); + } catch (SQLException | IOException | DBConnectionException | + io.entgra.application.mgt.common.exception.DBConnectionException e) { + log.error(e); + return GrafanaRequestHandlerUtil.constructInternalServerError(e, e.getMessage()); + } + } + + @POST + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @Path("/frontend-metrics") + @Override + public Response frontendMetrics(JsonObject body, @Context HttpHeaders headers, @Context UriInfo requestUriInfo) { + return proxyPassPostRequest(body, headers, requestUriInfo); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/dashboards/uid/{uid}") + @Override + public Response getDashboard(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) { + return proxyPassGetRequest(headers, requestUriInfo); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @Path("/annotations") + @Override + public Response getAnnotations(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) { + return proxyPassGetRequest(headers, requestUriInfo); + } + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/alerts/states-for-dashboard") + @Override + public Response getAlertStateForDashboards(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) { + return proxyPassGetRequest(headers, requestUriInfo); + } + + public Response proxyPassGetRequest(HttpHeaders headers, UriInfo requestUriInfo) { + try { + GrafanaPanelIdentifier panelIdentifier = GrafanaRequestHandlerUtil.getPanelIdentifier(headers); + return GrafanaRequestHandlerUtil.proxyPassGetRequest(requestUriInfo, panelIdentifier.getOrgId()); + } catch (RefererNotValid e) { + return GrafanaRequestHandlerUtil.constructInvalidReferer(); + } catch (GrafanaManagementException e) { + return GrafanaRequestHandlerUtil.constructInternalServerError(e, e.getMessage()); + } + } + + public Response proxyPassPostRequest(JsonObject body, HttpHeaders headers, UriInfo requestUriInfo) { + try { + GrafanaPanelIdentifier panelIdentifier = GrafanaRequestHandlerUtil.getPanelIdentifier(headers); + return GrafanaRequestHandlerUtil.proxyPassPostRequest(body, requestUriInfo, panelIdentifier.getOrgId()); + } catch (RefererNotValid e) { + return GrafanaRequestHandlerUtil.constructInvalidReferer(); + } catch (GrafanaManagementException e) { + return GrafanaRequestHandlerUtil.constructInternalServerError(e, e.getMessage()); + } + } + + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/GrafanaRequestHandlerUtil.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/impl/util/GrafanaRequestHandlerUtil.java similarity index 91% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/GrafanaRequestHandlerUtil.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/impl/util/GrafanaRequestHandlerUtil.java index 9b44e17296..064ea037f4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/GrafanaRequestHandlerUtil.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/impl/util/GrafanaRequestHandlerUtil.java @@ -16,9 +16,16 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.jaxrs.service.impl.util; +package io.entgra.analytics.mgt.grafana.proxy.api.service.impl.util; import com.google.gson.JsonObject; +import io.entgra.analytics.mgt.grafana.proxy.api.service.bean.ErrorResponse; +import io.entgra.analytics.mgt.grafana.proxy.api.service.exception.RefererNotValid; +import io.entgra.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException; +import io.entgra.analytics.mgt.grafana.proxy.core.bean.GrafanaPanelIdentifier; +import io.entgra.analytics.mgt.grafana.proxy.core.exception.GrafanaEnvVariablesNotDefined; +import io.entgra.analytics.mgt.grafana.proxy.core.util.GrafanaConstants; +import io.entgra.analytics.mgt.grafana.proxy.core.util.GrafanaUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.HttpResponse; @@ -29,15 +36,8 @@ import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -import org.wso2.carbon.device.mgt.common.exceptions.GrafanaManagementException; import org.wso2.carbon.device.mgt.core.common.util.HttpUtil; -import org.wso2.carbon.device.mgt.core.grafana.mgt.bean.GrafanaPanelIdentifier; -import org.wso2.carbon.device.mgt.core.grafana.mgt.exception.GrafanaEnvVariablesNotDefined; -import org.wso2.carbon.device.mgt.core.grafana.mgt.util.GrafanaConstants; -import org.wso2.carbon.device.mgt.core.grafana.mgt.util.GrafanaUtil; import org.wso2.carbon.device.mgt.core.report.mgt.Constants; -import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; -import org.wso2.carbon.device.mgt.jaxrs.exception.RefererNotValid; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; @@ -112,8 +112,7 @@ public class GrafanaRequestHandlerUtil { } public static String getGrafanaRequestPathWQuery(UriInfo requestUriInfo) { - String contextPath = "/reports/grafana"; - String path = requestUriInfo.getPath().substring(contextPath.length()); + String path = requestUriInfo.getPath(); String queryParam = requestUriInfo.getRequestUri().getRawQuery(); if (queryParam != null) { path += Constants.URI_QUERY_SEPARATOR + queryParam; diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/webapp/META-INF/permissions.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/webapp/META-INF/permissions.xml new file mode 100644 index 0000000000..190a634a12 --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/webapp/META-INF/permissions.xml @@ -0,0 +1,32 @@ + + + + + + + diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/webapp/META-INF/webapp-classloading.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/webapp/META-INF/webapp-classloading.xml new file mode 100644 index 0000000000..9f50930c4f --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/webapp/META-INF/webapp-classloading.xml @@ -0,0 +1,35 @@ + + + + + + + + + false + + + CXF3,Carbon + diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/webapp/WEB-INF/cxf-servlet.xml new file mode 100644 index 0000000000..0f6ec36cf0 --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/webapp/WEB-INF/web.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..6ef280f763 --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,113 @@ + + + + Grafana-API-Proxy-Webapp + + JAX-WS/JAX-RS Grafana API Management Endpoint + JAX-WS/JAX-RS Servlet + CXFServlet + + org.apache.cxf.transport.servlet.CXFServlet + + + + swagger.security.filter + ApiAuthorizationFilterImpl + + 1 + + + CXFServlet + /* + + + 60 + + + + doAuthentication + true + + + + nonSecuredEndPoints + + + + + + managed-api-enabled + true + + + managed-api-owner + admin + + + isSharedWithAllTenants + true + + + + ApiOriginFilter + io.entgra.analytics.mgt.grafana.proxy.api.service.addons.ApiOriginFilter + + + + ApiOriginFilter + /* + + + + HttpHeaderSecurityFilter + org.apache.catalina.filters.HttpHeaderSecurityFilter + + hstsEnabled + false + + + + + ContentTypeBasedCachePreventionFilter + org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter + + patterns + text/html" ,application/json" ,text/plain + + + filterAction + enforce + + + httpHeaders + Cache-Control: no-store, no-cache, must-revalidate, private + + + + + HttpHeaderSecurityFilter + /* + + + + ContentTypeBasedCachePreventionFilter + /* + + + diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml new file mode 100644 index 0000000000..ac29a22a76 --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml @@ -0,0 +1,107 @@ + + + + + + + org.wso2.carbon.devicemgt + grafana-mgt + 5.0.1-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.analytics.mgt.grafana.proxy.common + bundle + Entgra - Grafana API Handler Common + Entgra - Grafana API Handler Common + http://entgra.io + + + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + Grafana Management Common Bundle + + io.entgra.analytics.mgt.grafana.proxy.common.* + + + javax.xml.bind.annotation; version="${javax.xml.bind.imp.pkg.version}", + com.fasterxml.jackson.annotation;version="${jackson-annotations.version}", + io.swagger.annotations; version="${swagger.annotations.version}"; resolution:=optional, + com.google.gson + + + + + + org.jacoco + jacoco-maven-plugin + + ${basedir}/target/coverage-reports/jacoco-unit.exec + + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + ${basedir}/target/coverage-reports/jacoco-unit.exec + ${basedir}/target/coverage-reports/site + + + + + + + + + + + io.swagger + swagger-annotations + provided + + + org.wso2.orbit.com.fasterxml.jackson.core + jackson-annotations + + + com.google.code.gson + gson + + + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/GrafanaManagementException.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/src/main/java/io/entgra/analytics/mgt/grafana/proxy/common/exception/GrafanaManagementException.java similarity index 88% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/GrafanaManagementException.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/src/main/java/io/entgra/analytics/mgt/grafana/proxy/common/exception/GrafanaManagementException.java index 331f52a209..64ec9b2731 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/GrafanaManagementException.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/src/main/java/io/entgra/analytics/mgt/grafana/proxy/common/exception/GrafanaManagementException.java @@ -16,11 +16,11 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.common.exceptions; +package io.entgra.analytics.mgt.grafana.proxy.common.exception; public class GrafanaManagementException extends Exception{ - private static final long serialVersionUID = -3951279311829079297L; + private static final long serialVersionUID = -3922279312829079297L; public GrafanaManagementException(String msg, Exception nestedEx) { super(msg, nestedEx); diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml new file mode 100644 index 0000000000..86a93f0a27 --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml @@ -0,0 +1,329 @@ + + + + + + + org.wso2.carbon.devicemgt + grafana-mgt + 5.0.1-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.analytics.mgt.grafana.proxy.core + bundle + Entgra - Grafana API Handler Core + Entgra - Grafana API Handler Core + http://entgra.io + + + + + org.apache.felix + maven-scr-plugin + + + org.jacoco + jacoco-maven-plugin + + ${basedir}/target/coverage-reports/jacoco-unit.exec + + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + ${basedir}/target/coverage-reports/jacoco-unit.exec + ${basedir}/target/coverage-reports/site + + + + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + Grafana API Management Core Bundle + io.entgra.analytics.mgt.grafana.proxy.core.internal + + io.entgra.analytics.mgt.grafana.proxy.common.*, + javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}";resolution:=optional, + javax.xml.bind.annotation, + javax.xml.bind, + org.apache.commons.lang, + org.wso2.carbon, + org.wso2.carbon.device.mgt.common.*, + org.wso2.carbon.device.mgt.core.* + io.entgra.application.mgt.core.* + + + !org.wso2.carbon.email.sender.core.internal, + io.entgra.analytics.mgt.grafana.proxy.core.* + + + scribe;scope=compile|runtime;inline=false, + + * + + + + + + + + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.osgi + org.eclipse.osgi.services + + + org.wso2.orbit.org.scannotation + scannotation + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + + + org.wso2.carbon + org.wso2.carbon.utils + + + org.wso2.carbon + org.wso2.carbon.logging + provided + + + org.wso2.carbon + org.wso2.carbon.core + provided + + + org.wso2.carbon.devicemgt + io.entgra.analytics.mgt.grafana.proxy.common + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + + + org.wso2.carbon.devicemgt + io.entgra.application.mgt.core + + + org.apache.httpcomponents.wso2 + httpclient + 4.1.1.wso2v1 + compile + + + org.apache.httpcomponents + httpclient + + + org.wso2.carbon.devicemgt + org.wso2.carbon.identity.jwt.client.extension + provided + + + javax.ws.rs + javax.ws.rs-api + + + javax.ws.rs + jsr311-api + + + org.javassist + javassist + + + org.powermock + powermock-api-mockito + + + org.wso2.carbon + org.wso2.carbon.ndatasource.core + + + commons-lang + commons-lang + + + + + commons-codec.wso2 + commons-codec + provided + + + com.h2database.wso2 + h2-database-engine + test + + + org.testng + testng + + + org.powermock + powermock-module-testng + test + + + org.wso2.carbon + org.wso2.carbon.user.core + + + org.wso2.carbon + org.wso2.carbon.user.api + + + org.wso2.carbon + org.wso2.carbon.registry.api + + + org.wso2.carbon + org.wso2.carbon.registry.core + + + org.apache.tomcat.wso2 + jdbc-pool + + + org.wso2.carbon + org.wso2.carbon.base + + + org.wso2.carbon.governance + org.wso2.carbon.governance.api + + + org.apache.axis2.transport + axis2-transport-mail + + + org.apache.ws.commons.axiom.wso2 + axiom + + + + org.apache.axis2.wso2 + axis2 + + + org.wso2.carbon.identity.inbound.auth.oauth2 + org.wso2.carbon.identity.oauth.stub + + + org.wso2.tomcat + tomcat + + + org.wso2.tomcat + tomcat-servlet-api + + + + + org.wso2.carbon.commons + org.wso2.carbon.ntask.core + + + + + commons-collections.wso2 + commons-collections + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.email.sender.core + + + + mysql + mysql-connector-java + test + + + + com.google.code.gson + gson + + + + io.swagger + swagger-annotations + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.annotations + + + org.wso2.carbon.event-processing + org.wso2.carbon.event.processor.stub + + + org.wso2.carbon.multitenancy + org.wso2.carbon.tenant.mgt + + + commons-validator + commons-validator + + + org.wso2.carbon.devicemgt + io.entgra.server.bootup.heartbeat.beacon + + + com.google.guava + guava + + + + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/bean/GrafanaPanelIdentifier.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/bean/GrafanaPanelIdentifier.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/bean/GrafanaPanelIdentifier.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/bean/GrafanaPanelIdentifier.java index 950edfa1cb..4ff90e25b0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/bean/GrafanaPanelIdentifier.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/bean/GrafanaPanelIdentifier.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.bean; +package io.entgra.analytics.mgt.grafana.proxy.core.bean; public class GrafanaPanelIdentifier { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/config/GrafanaConfiguration.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/config/GrafanaConfiguration.java similarity index 88% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/config/GrafanaConfiguration.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/config/GrafanaConfiguration.java index 25a1302728..72ab1545fe 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/config/GrafanaConfiguration.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/config/GrafanaConfiguration.java @@ -16,10 +16,11 @@ * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.config; +package io.entgra.analytics.mgt.grafana.proxy.core.config; + +import io.entgra.analytics.mgt.grafana.proxy.core.config.xml.bean.CacheConfiguration; +import io.entgra.analytics.mgt.grafana.proxy.core.config.xml.bean.User; -import org.wso2.carbon.device.mgt.core.grafana.mgt.config.xml.bean.CacheConfiguration; -import org.wso2.carbon.device.mgt.core.grafana.mgt.config.xml.bean.User; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/config/GrafanaConfigurationManager.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/config/GrafanaConfigurationManager.java similarity index 95% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/config/GrafanaConfigurationManager.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/config/GrafanaConfigurationManager.java index d4f51315c9..a8ce50fb5f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/config/GrafanaConfigurationManager.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/config/GrafanaConfigurationManager.java @@ -15,13 +15,13 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.config; +package io.entgra.analytics.mgt.grafana.proxy.core.config; +import io.entgra.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException; +import io.entgra.analytics.mgt.grafana.proxy.core.util.GrafanaConstants; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; -import org.wso2.carbon.device.mgt.common.exceptions.GrafanaManagementException; -import org.wso2.carbon.device.mgt.core.grafana.mgt.util.GrafanaConstants; import org.wso2.carbon.utils.CarbonUtils; import javax.xml.XMLConstants; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/config/xml/bean/CacheConfiguration.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/config/xml/bean/CacheConfiguration.java similarity index 94% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/config/xml/bean/CacheConfiguration.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/config/xml/bean/CacheConfiguration.java index 9ab509b7bb..def5fb3476 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/config/xml/bean/CacheConfiguration.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/config/xml/bean/CacheConfiguration.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.config.xml.bean; +package io.entgra.analytics.mgt.grafana.proxy.core.config.xml.bean; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/config/xml/bean/User.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/config/xml/bean/User.java similarity index 94% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/config/xml/bean/User.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/config/xml/bean/User.java index 8fd868fd86..3e8b662175 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/config/xml/bean/User.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/config/xml/bean/User.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.config.xml.bean; +package io.entgra.analytics.mgt.grafana.proxy.core.config.xml.bean; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/DashboardNotFound.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/DashboardNotFound.java similarity index 92% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/DashboardNotFound.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/DashboardNotFound.java index 597b44d346..c052d107d1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/DashboardNotFound.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/DashboardNotFound.java @@ -15,11 +15,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.exception; +package io.entgra.analytics.mgt.grafana.proxy.core.exception; public class DashboardNotFound extends GrafanaAPIException { - private static final long serialVersionUID = -2111271331930070297L; + private static final long serialVersionUID = -2111271331930066297L; public DashboardNotFound(String errMsg) { super(errMsg); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/DatasourceNotFound.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/DatasourceNotFound.java similarity index 85% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/DatasourceNotFound.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/DatasourceNotFound.java index 6e7a187f06..3d750bff35 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/DatasourceNotFound.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/DatasourceNotFound.java @@ -15,11 +15,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.exception; +package io.entgra.analytics.mgt.grafana.proxy.core.exception; public class DatasourceNotFound extends GrafanaAPIException { - private static final long serialVersionUID = -3171279332930270227L; + private static final long serialVersionUID = -3171333332936220227L; public DatasourceNotFound(String errMsg) { super(errMsg); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/GrafanaAPIException.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/GrafanaAPIException.java similarity index 78% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/GrafanaAPIException.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/GrafanaAPIException.java index 2a6b85c31e..df926061f0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/GrafanaAPIException.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/GrafanaAPIException.java @@ -15,13 +15,13 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.exception; +package io.entgra.analytics.mgt.grafana.proxy.core.exception; -import org.wso2.carbon.device.mgt.common.exceptions.GrafanaManagementException; +import io.entgra.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException; public class GrafanaAPIException extends GrafanaManagementException { - private static final long serialVersionUID = -3921249462930270227L; + private static final long serialVersionUID = -3121249462130274227L; public GrafanaAPIException(String errMsg) { super(errMsg); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/GrafanaEnvVariablesNotDefined.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/GrafanaEnvVariablesNotDefined.java similarity index 79% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/GrafanaEnvVariablesNotDefined.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/GrafanaEnvVariablesNotDefined.java index 5bccbcf3b7..acb836680c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/GrafanaEnvVariablesNotDefined.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/GrafanaEnvVariablesNotDefined.java @@ -15,13 +15,14 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.exception; +package io.entgra.analytics.mgt.grafana.proxy.core.exception; -import org.wso2.carbon.device.mgt.common.exceptions.GrafanaManagementException; + +import io.entgra.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException; public class GrafanaEnvVariablesNotDefined extends GrafanaManagementException { - private static final long serialVersionUID = -3444449462330270237L; + private static final long serialVersionUID = -3424429462350570237L; public GrafanaEnvVariablesNotDefined(String errMsg) { super(errMsg); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/MaliciousQueryAttempt.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/MaliciousQueryAttempt.java similarity index 80% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/MaliciousQueryAttempt.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/MaliciousQueryAttempt.java index 133a4037e9..ff91dd6a6e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/MaliciousQueryAttempt.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/MaliciousQueryAttempt.java @@ -15,13 +15,14 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.exception; +package io.entgra.analytics.mgt.grafana.proxy.core.exception; -import org.wso2.carbon.device.mgt.common.exceptions.GrafanaManagementException; + +import io.entgra.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException; public class MaliciousQueryAttempt extends GrafanaManagementException { - private static final long serialVersionUID = -3171279331930070297L; + private static final long serialVersionUID = -3171279331530570257L; public MaliciousQueryAttempt(String msg) { super(msg); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/PanelNotFound.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/PanelNotFound.java similarity index 85% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/PanelNotFound.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/PanelNotFound.java index e3d191be30..f8cead9df8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/PanelNotFound.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/PanelNotFound.java @@ -15,11 +15,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.exception; +package io.entgra.analytics.mgt.grafana.proxy.core.exception; public class PanelNotFound extends GrafanaAPIException { - private static final long serialVersionUID = -3471479441930070297L; + private static final long serialVersionUID = -3471379441938070287L; public PanelNotFound(String errMsg) { super(errMsg); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/QueryMisMatch.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/QueryMisMatch.java similarity index 86% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/QueryMisMatch.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/QueryMisMatch.java index b2a6244bf0..0d011ddd14 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/QueryMisMatch.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/QueryMisMatch.java @@ -15,11 +15,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.exception; +package io.entgra.analytics.mgt.grafana.proxy.core.exception; public class QueryMisMatch extends MaliciousQueryAttempt { - private static final long serialVersionUID = -3171279334939076294L; + private static final long serialVersionUID = -3171277334737076294L; public QueryMisMatch(String msg) { super(msg); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/QueryNotFound.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/QueryNotFound.java similarity index 86% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/QueryNotFound.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/QueryNotFound.java index 22379e43a5..1bff687b14 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/QueryNotFound.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/QueryNotFound.java @@ -15,11 +15,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.exception; +package io.entgra.analytics.mgt.grafana.proxy.core.exception; public class QueryNotFound extends GrafanaAPIException { - private static final long serialVersionUID = -3151259335930070297L; + private static final long serialVersionUID = -3151259311910070297L; public QueryNotFound(String errMsg) { super(errMsg); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/TemplateNotFound.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/TemplateNotFound.java similarity index 85% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/TemplateNotFound.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/TemplateNotFound.java index 69b167a9c2..e5347eee10 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/exception/TemplateNotFound.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/exception/TemplateNotFound.java @@ -15,11 +15,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.exception; +package io.entgra.analytics.mgt.grafana.proxy.core.exception; public class TemplateNotFound extends GrafanaAPIException { - private static final long serialVersionUID = -3481878481830070297L; + private static final long serialVersionUID = -3481878481835562209L; public TemplateNotFound(String errMsg) { super(errMsg); } diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/internal/GrafanaManagementServiceComponent.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/internal/GrafanaManagementServiceComponent.java new file mode 100644 index 0000000000..f976e2ef51 --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/internal/GrafanaManagementServiceComponent.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.entgra.analytics.mgt.grafana.proxy.core.internal; + +import io.entgra.analytics.mgt.grafana.proxy.core.service.GrafanaAPIService; +import io.entgra.analytics.mgt.grafana.proxy.core.service.GrafanaQueryService; +import io.entgra.analytics.mgt.grafana.proxy.core.service.impl.GrafanaAPIServiceImpl; +import io.entgra.analytics.mgt.grafana.proxy.core.service.impl.GrafanaQueryServiceImpl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.context.PrivilegedCarbonContext; + +/** + * @scr.component name="io.entgra.analytics.mgt.grafana.proxy.grafanamanagementservicecomponent" immediate="true" + */ +public class GrafanaManagementServiceComponent { + + private static Log log = LogFactory.getLog(GrafanaManagementServiceComponent.class); + + @SuppressWarnings("unused") + protected void activate(ComponentContext componentContext) { + try { + if (log.isDebugEnabled()) { + log.debug("Initializing grafana proxy management core bundle"); + } + + BundleContext bundleContext = componentContext.getBundleContext(); + + GrafanaAPIService grafanaAPIService = new GrafanaAPIServiceImpl(); + GrafanaQueryService grafanaQueryService = new GrafanaQueryServiceImpl(grafanaAPIService); + bundleContext.registerService(GrafanaAPIService.class.getName(), grafanaAPIService, null); + GrafanaMgtDataHolder.getInstance().setGrafanaAPIService(grafanaAPIService); + bundleContext.registerService(GrafanaQueryService.class.getName(), grafanaQueryService, null); + GrafanaMgtDataHolder.getInstance().setGrafanaQueryService(grafanaQueryService); + + if (log.isDebugEnabled()) { + log.debug("Grafana management core bundle has been successfully initialized"); + } + } catch (Throwable e) { + log.error("Error occurred while initializing grafana management core bundle", e); + } + } + + @SuppressWarnings("unused") + protected void deactivate(ComponentContext componentContext) { + if (log.isDebugEnabled()) { + log.debug("De-activating Grafana Management Service Component"); + } + } +} diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/internal/GrafanaMgtDataHolder.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/internal/GrafanaMgtDataHolder.java new file mode 100644 index 0000000000..10d43d7a23 --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/internal/GrafanaMgtDataHolder.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.entgra.analytics.mgt.grafana.proxy.core.internal; + +import io.entgra.analytics.mgt.grafana.proxy.core.service.GrafanaAPIService; +import io.entgra.analytics.mgt.grafana.proxy.core.service.GrafanaQueryService; + +public class GrafanaMgtDataHolder { + + private GrafanaAPIService grafanaAPIService; + private GrafanaQueryService grafanaQueryService; + + private GrafanaMgtDataHolder() { + + } + + public GrafanaAPIService getGrafanaAPIService() { + return grafanaAPIService; + } + + public void setGrafanaAPIService(GrafanaAPIService grafanaAPIService) { + this.grafanaAPIService = grafanaAPIService; + } + + public GrafanaQueryService getGrafanaQueryService() { + return grafanaQueryService; + } + + public void setGrafanaQueryService(GrafanaQueryService grafanaQueryService) { + this.grafanaQueryService = grafanaQueryService; + } + + public static class InstanceHolder { + public static GrafanaMgtDataHolder instance = new GrafanaMgtDataHolder(); + } + + public static GrafanaMgtDataHolder getInstance() { + return InstanceHolder.instance; + } + + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/GrafanaAPIService.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/GrafanaAPIService.java similarity index 53% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/GrafanaAPIService.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/GrafanaAPIService.java index e83bfe4c51..91776c50b9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/GrafanaAPIService.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/GrafanaAPIService.java @@ -15,24 +15,60 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.service; +package io.entgra.analytics.mgt.grafana.proxy.core.service; import com.google.gson.JsonObject; -import org.wso2.carbon.device.mgt.common.exceptions.GrafanaManagementException; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.bean.Datasource; +import io.entgra.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException; +import io.entgra.analytics.mgt.grafana.proxy.core.service.bean.Datasource; + import java.io.IOException; public interface GrafanaAPIService { + /** + * Get predefined query template from grafana for given panel/variable + * @param dashboardUID + * @param panelId + * @param refId + * @param requestScheme + * @return query of the given panel/variable + * @throws IOException + * @throws GrafanaManagementException + */ String getQueryTemplate(String dashboardUID, String panelId, String refId, String requestScheme) throws IOException, GrafanaManagementException; + /** + * Get panel details by dashboard uid and panel Id + * @param dashboardUID + * @param panelId + * @param requestScheme + * @return Panel details + * @throws IOException + * @throws GrafanaManagementException + */ JsonObject getPanelDetails(String dashboardUID, String panelId, String requestScheme) throws IOException, GrafanaManagementException; + /** + * Get dashboard details by uid + * @param dashboardUID + * @param requestScheme + * @return Dashboard details + * @throws IOException + * @throws GrafanaManagementException + */ JsonObject getDashboardDetails(String dashboardUID, String requestScheme) throws IOException, GrafanaManagementException; + /** + * Get datasource details by id + * @param datasourceId + * @param requestScheme + * @return Datasource details + * @throws IOException + * @throws GrafanaManagementException + */ Datasource getDatasource(int datasourceId, String requestScheme) throws IOException, GrafanaManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/GrafanaQueryService.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/GrafanaQueryService.java similarity index 78% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/GrafanaQueryService.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/GrafanaQueryService.java index ba2c8cbc97..a1c43baf52 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/GrafanaQueryService.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/GrafanaQueryService.java @@ -15,11 +15,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.service; +package io.entgra.analytics.mgt.grafana.proxy.core.service; import com.google.gson.JsonObject; +import io.entgra.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException; import org.wso2.carbon.device.mgt.common.exceptions.DBConnectionException; -import org.wso2.carbon.device.mgt.common.exceptions.GrafanaManagementException; import java.io.IOException; import java.net.URI; @@ -28,6 +28,7 @@ import java.sql.SQLException; public interface GrafanaQueryService { void buildSafeQuery(JsonObject queryRequestBody, String dashboardUID, String panelId, - URI requestUri) throws IOException, SQLException, GrafanaManagementException, DBConnectionException; + URI requestUri) throws IOException, SQLException, GrafanaManagementException, + DBConnectionException, io.entgra.application.mgt.common.exception.DBConnectionException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/bean/Datasource.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/bean/Datasource.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/bean/Datasource.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/bean/Datasource.java index 4dc84938e4..43a11fdda4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/bean/Datasource.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/bean/Datasource.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.service.bean; +package io.entgra.analytics.mgt.grafana.proxy.core.service.bean; public class Datasource { private int id; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/cache/CacheManager.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/cache/CacheManager.java similarity index 85% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/cache/CacheManager.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/cache/CacheManager.java index 9bcd02d2ed..b56a1041bd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/cache/CacheManager.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/cache/CacheManager.java @@ -16,18 +16,18 @@ * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.service.cache; +package io.entgra.analytics.mgt.grafana.proxy.core.service.cache; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; +import io.entgra.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException; +import io.entgra.analytics.mgt.grafana.proxy.core.config.GrafanaConfiguration; +import io.entgra.analytics.mgt.grafana.proxy.core.config.GrafanaConfigurationManager; +import io.entgra.analytics.mgt.grafana.proxy.core.config.xml.bean.CacheConfiguration; +import io.entgra.analytics.mgt.grafana.proxy.core.service.bean.Datasource; +import io.entgra.analytics.mgt.grafana.proxy.core.util.GrafanaConstants; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.exceptions.GrafanaManagementException; -import org.wso2.carbon.device.mgt.core.grafana.mgt.config.GrafanaConfiguration; -import org.wso2.carbon.device.mgt.core.grafana.mgt.config.GrafanaConfigurationManager; -import org.wso2.carbon.device.mgt.core.grafana.mgt.config.xml.bean.CacheConfiguration; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.bean.Datasource; -import org.wso2.carbon.device.mgt.core.grafana.mgt.util.GrafanaConstants; public class CacheManager { private static final Log log = LogFactory.getLog(CacheManager.class); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/cache/QueryTemplateCacheKey.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/cache/QueryTemplateCacheKey.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/cache/QueryTemplateCacheKey.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/cache/QueryTemplateCacheKey.java index 262be1ead9..175fe3ae28 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/cache/QueryTemplateCacheKey.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/cache/QueryTemplateCacheKey.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.service.cache; +package io.entgra.analytics.mgt.grafana.proxy.core.service.cache; import java.util.Objects; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/impl/GrafanaAPIServiceImpl.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/impl/GrafanaAPIServiceImpl.java similarity index 81% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/impl/GrafanaAPIServiceImpl.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/impl/GrafanaAPIServiceImpl.java index 36e900d003..ae3e91a0c7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/impl/GrafanaAPIServiceImpl.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/impl/GrafanaAPIServiceImpl.java @@ -15,11 +15,24 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.service.impl; +package io.entgra.analytics.mgt.grafana.proxy.core.service.impl; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import io.entgra.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException; +import io.entgra.analytics.mgt.grafana.proxy.core.exception.DashboardNotFound; +import io.entgra.analytics.mgt.grafana.proxy.core.exception.DatasourceNotFound; +import io.entgra.analytics.mgt.grafana.proxy.core.exception.GrafanaEnvVariablesNotDefined; +import io.entgra.analytics.mgt.grafana.proxy.core.exception.PanelNotFound; +import io.entgra.analytics.mgt.grafana.proxy.core.exception.QueryNotFound; +import io.entgra.analytics.mgt.grafana.proxy.core.exception.TemplateNotFound; +import io.entgra.analytics.mgt.grafana.proxy.core.service.GrafanaAPIService; +import io.entgra.analytics.mgt.grafana.proxy.core.service.bean.Datasource; +import io.entgra.analytics.mgt.grafana.proxy.core.service.cache.CacheManager; +import io.entgra.analytics.mgt.grafana.proxy.core.service.cache.QueryTemplateCacheKey; +import io.entgra.analytics.mgt.grafana.proxy.core.util.GrafanaConstants; +import io.entgra.analytics.mgt.grafana.proxy.core.util.GrafanaUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.HttpResponse; @@ -28,21 +41,9 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -import org.wso2.carbon.device.mgt.common.exceptions.GrafanaManagementException; import org.wso2.carbon.device.mgt.core.common.util.HttpUtil; -import org.wso2.carbon.device.mgt.core.grafana.mgt.exception.DashboardNotFound; -import org.wso2.carbon.device.mgt.core.grafana.mgt.exception.DatasourceNotFound; -import org.wso2.carbon.device.mgt.core.grafana.mgt.exception.GrafanaEnvVariablesNotDefined; -import org.wso2.carbon.device.mgt.core.grafana.mgt.exception.PanelNotFound; -import org.wso2.carbon.device.mgt.core.grafana.mgt.exception.QueryNotFound; -import org.wso2.carbon.device.mgt.core.grafana.mgt.exception.TemplateNotFound; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.GrafanaAPIService; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.bean.Datasource; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.cache.CacheManager; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.cache.QueryTemplateCacheKey; -import org.wso2.carbon.device.mgt.core.grafana.mgt.util.GrafanaConstants; -import org.wso2.carbon.device.mgt.core.grafana.mgt.util.GrafanaUtil; import org.wso2.carbon.device.mgt.core.report.mgt.Constants; + import javax.ws.rs.core.HttpHeaders; import java.io.IOException; @@ -59,6 +60,16 @@ public class GrafanaAPIServiceImpl implements GrafanaAPIService { } } + /** + * Get predefined query template from grafana for given panel + * @param dashboardUID + * @param panelId + * @param refId + * @param requestScheme + * @return query of the given panel + * @throws IOException + * @throws GrafanaManagementException + */ public String getPanelQuery(String dashboardUID, String panelId, String refId, String requestScheme) throws IOException, GrafanaManagementException { JsonObject panel = getPanelDetails(dashboardUID, panelId, requestScheme); @@ -74,6 +85,16 @@ public class GrafanaAPIServiceImpl implements GrafanaAPIService { return queryTemplate; } + /** + * Get predefined query template from grafana for given variable (template variable) + * Note: Here template query means the grafana template variable queries + * @param dashboardUID + * @param refId + * @param requestScheme + * @return query of grafana template variable + * @throws IOException + * @throws GrafanaManagementException + */ // Here template query means the grafana template variable queries public String getTemplateQuery(String dashboardUID, String refId, String requestScheme) throws IOException, GrafanaManagementException { @@ -89,6 +110,15 @@ public class GrafanaAPIServiceImpl implements GrafanaAPIService { return query; } + /** + * Get grafana template variable details of given dashboard uid + * @param dashboardUID + * @param refId + * @param requestScheme + * @return Template variable details of given dashboard uid + * @throws IOException + * @throws GrafanaManagementException + */ public JsonObject getTemplatingDetails(String dashboardUID, String refId, String requestScheme) throws IOException, GrafanaManagementException { JsonObject dashboard = getDashboardDetails(dashboardUID, requestScheme); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/impl/GrafanaQueryServiceImpl.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/impl/GrafanaQueryServiceImpl.java similarity index 79% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/impl/GrafanaQueryServiceImpl.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/impl/GrafanaQueryServiceImpl.java index 915f84eca4..b15ebed76a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/service/impl/GrafanaQueryServiceImpl.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/impl/GrafanaQueryServiceImpl.java @@ -15,27 +15,28 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.service.impl; +package io.entgra.analytics.mgt.grafana.proxy.core.service.impl; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import io.entgra.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException; +import io.entgra.analytics.mgt.grafana.proxy.core.exception.MaliciousQueryAttempt; +import io.entgra.analytics.mgt.grafana.proxy.core.exception.QueryMisMatch; +import io.entgra.analytics.mgt.grafana.proxy.core.exception.QueryNotFound; +import io.entgra.analytics.mgt.grafana.proxy.core.service.GrafanaAPIService; +import io.entgra.analytics.mgt.grafana.proxy.core.service.GrafanaQueryService; +import io.entgra.analytics.mgt.grafana.proxy.core.service.bean.Datasource; +import io.entgra.analytics.mgt.grafana.proxy.core.service.cache.CacheManager; +import io.entgra.analytics.mgt.grafana.proxy.core.service.cache.QueryTemplateCacheKey; +import io.entgra.analytics.mgt.grafana.proxy.core.sql.query.GrafanaPreparedQueryBuilder; +import io.entgra.analytics.mgt.grafana.proxy.core.sql.query.PreparedQuery; +import io.entgra.analytics.mgt.grafana.proxy.core.sql.query.encoder.QueryEncoderFactory; +import io.entgra.analytics.mgt.grafana.proxy.core.util.GrafanaConstants; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.exceptions.DBConnectionException; -import org.wso2.carbon.device.mgt.common.exceptions.GrafanaManagementException; -import org.wso2.carbon.device.mgt.core.grafana.mgt.exception.MaliciousQueryAttempt; -import org.wso2.carbon.device.mgt.core.grafana.mgt.exception.QueryMisMatch; -import org.wso2.carbon.device.mgt.core.grafana.mgt.exception.QueryNotFound; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.GrafanaAPIService; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.GrafanaQueryService; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.bean.Datasource; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.cache.CacheManager; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.cache.QueryTemplateCacheKey; -import org.wso2.carbon.device.mgt.core.grafana.mgt.sql.query.GrafanaPreparedQueryBuilder; -import org.wso2.carbon.device.mgt.core.grafana.mgt.sql.query.PreparedQuery; -import org.wso2.carbon.device.mgt.core.grafana.mgt.sql.query.encoder.QueryEncoderFactory; -import org.wso2.carbon.device.mgt.core.grafana.mgt.util.GrafanaConstants; + import java.io.IOException; import java.net.URI; import java.sql.SQLException; @@ -50,7 +51,7 @@ public class GrafanaQueryServiceImpl implements GrafanaQueryService { } public void buildSafeQuery(JsonObject queryRequestBody, String dashboardUID, String panelId, URI requestUri) - throws IOException, SQLException, GrafanaManagementException, DBConnectionException { + throws IOException, SQLException, GrafanaManagementException, DBConnectionException, io.entgra.application.mgt.common.exception.DBConnectionException { JsonArray queries = queryRequestBody.getAsJsonArray(GrafanaConstants.QUERY_BODY_QUERIES_KEY); for (int i = 0; i < queries.size(); i++) { JsonObject queryObj = queries.get(i).getAsJsonObject(); @@ -101,7 +102,8 @@ public class GrafanaQueryServiceImpl implements GrafanaQueryService { } private void encodeQuery(JsonObject queryObj, Datasource datasource, String queryTemplate, String rawSql) - throws SQLException, GrafanaManagementException, DBConnectionException { + throws SQLException, GrafanaManagementException, DBConnectionException, + io.entgra.application.mgt.common.exception.DBConnectionException { PreparedQuery pq = GrafanaPreparedQueryBuilder.build(queryTemplate, rawSql); String encodedQuery = QueryEncoderFactory.createEncoder(datasource.getType(), datasource.getName()).encode(pq); CacheManager.getInstance().getEncodedQueryCache().put(rawSql, encodedQuery); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/connection/GrafanaDatasourceConnectionFactory.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/connection/GrafanaDatasourceConnectionFactory.java similarity index 69% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/connection/GrafanaDatasourceConnectionFactory.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/connection/GrafanaDatasourceConnectionFactory.java index b9ffbd39ce..808b859038 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/connection/GrafanaDatasourceConnectionFactory.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/connection/GrafanaDatasourceConnectionFactory.java @@ -1,19 +1,18 @@ -package org.wso2.carbon.device.mgt.core.grafana.mgt.sql.connection; +package io.entgra.analytics.mgt.grafana.proxy.core.sql.connection; +import io.entgra.application.mgt.core.config.Configuration; +import io.entgra.application.mgt.core.config.ConfigurationManager; +import io.entgra.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.mgt.common.exceptions.DBConnectionException; -import org.wso2.carbon.device.mgt.common.exceptions.GrafanaManagementException; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.core.grafana.mgt.config.GrafanaConfiguration; -import org.wso2.carbon.device.mgt.core.grafana.mgt.config.GrafanaConfigurationManager; import org.wso2.carbon.device.mgt.core.report.mgt.config.ReportMgtConfiguration; import org.wso2.carbon.device.mgt.core.report.mgt.config.ReportMgtConfigurationManager; import org.wso2.carbon.device.mgt.core.report.mgt.dao.common.ReportMgtConnectionManager; import java.sql.Connection; import java.sql.SQLException; -import java.util.Map; public class GrafanaDatasourceConnectionFactory { @@ -22,22 +21,30 @@ public class GrafanaDatasourceConnectionFactory { private static final DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance(). getDeviceManagementConfig(); - public static Connection getConnection(String databaseName) throws SQLException, DBConnectionException { + private static final Configuration applicationMgtConfig = ConfigurationManager.getInstance().getConfiguration(); + + public static Connection getConnection(String databaseName) throws SQLException, DBConnectionException, + io.entgra.application.mgt.common.exception.DBConnectionException { if(databaseName.equals(getReportManagementDatasourceName())) { ReportMgtConnectionManager.openDBConnection(); return ReportMgtConnectionManager.getDBConnection(); } else if (databaseName.equals(getDeviceManagementDatasourceName())) { DeviceManagementDAOFactory.openConnection(); return DeviceManagementDAOFactory.getConnection(); + } else if (databaseName.equals(getApplicationManagementDatasourceName())) { + ConnectionManagerUtil.openDBConnection(); + return ConnectionManagerUtil.getDBConnection(); } else { throw new RuntimeException("No such datasource with the name: " + databaseName); } } - public static void closeConnection(String databaseName) throws SQLException, DBConnectionException { + public static void closeConnection(String databaseName) { if(databaseName.equals(getReportManagementDatasourceName())) { ReportMgtConnectionManager.closeDBConnection(); } else if (databaseName.equals(getDeviceManagementDatasourceName())) { DeviceManagementDAOFactory.closeConnection(); + } else if (databaseName.equals(getApplicationManagementDatasourceName())) { + ConnectionManagerUtil.closeDBConnection(); } else { throw new RuntimeException("No such datasource with the name: " + databaseName); } @@ -52,4 +59,8 @@ public class GrafanaDatasourceConnectionFactory { getJndiLookupDefinition().getJndiName(); } + private static String getApplicationManagementDatasourceName() { + return applicationMgtConfig.getDatasourceName(); + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/GrafanaPreparedQueryBuilder.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/GrafanaPreparedQueryBuilder.java similarity index 97% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/GrafanaPreparedQueryBuilder.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/GrafanaPreparedQueryBuilder.java index d938a2b320..8b8606dacb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/GrafanaPreparedQueryBuilder.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/GrafanaPreparedQueryBuilder.java @@ -15,14 +15,14 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.sql.query; +package io.entgra.analytics.mgt.grafana.proxy.core.sql.query; +import io.entgra.analytics.mgt.grafana.proxy.core.exception.QueryMisMatch; +import io.entgra.analytics.mgt.grafana.proxy.core.util.GrafanaConstants; +import io.entgra.analytics.mgt.grafana.proxy.core.util.GrafanaUtil; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.core.grafana.mgt.exception.QueryMisMatch; -import org.wso2.carbon.device.mgt.core.grafana.mgt.util.GrafanaConstants; -import org.wso2.carbon.device.mgt.core.grafana.mgt.util.GrafanaUtil; import java.util.ArrayList; import java.util.List; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/PreparedQuery.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/PreparedQuery.java similarity index 95% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/PreparedQuery.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/PreparedQuery.java index 11f240b1af..9540841061 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/PreparedQuery.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/PreparedQuery.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.sql.query; +package io.entgra.analytics.mgt.grafana.proxy.core.sql.query; import java.util.List; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/encoder/GenericQueryEncoder.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/encoder/GenericQueryEncoder.java similarity index 91% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/encoder/GenericQueryEncoder.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/encoder/GenericQueryEncoder.java index 031b8bd123..7b6693689f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/encoder/GenericQueryEncoder.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/encoder/GenericQueryEncoder.java @@ -15,10 +15,10 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.sql.query.encoder; +package io.entgra.analytics.mgt.grafana.proxy.core.sql.query.encoder; +import io.entgra.analytics.mgt.grafana.proxy.core.sql.query.PreparedQuery; import org.apache.commons.lang.StringEscapeUtils; -import org.wso2.carbon.device.mgt.core.grafana.mgt.sql.query.PreparedQuery; import java.sql.SQLException; import java.util.ArrayList; @@ -26,7 +26,7 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class GenericQueryEncoder implements QueryEncoder{ +public class GenericQueryEncoder implements QueryEncoder { public GenericQueryEncoder() { } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/encoder/MySQLQueryEncoder.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/encoder/MySQLQueryEncoder.java similarity index 78% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/encoder/MySQLQueryEncoder.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/encoder/MySQLQueryEncoder.java index 0c1220217e..faa6977b78 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/encoder/MySQLQueryEncoder.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/encoder/MySQLQueryEncoder.java @@ -15,13 +15,13 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.sql.query.encoder; +package io.entgra.analytics.mgt.grafana.proxy.core.sql.query.encoder; +import io.entgra.analytics.mgt.grafana.proxy.core.sql.connection.GrafanaDatasourceConnectionFactory; +import io.entgra.analytics.mgt.grafana.proxy.core.sql.query.PreparedQuery; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.exceptions.DBConnectionException; -import org.wso2.carbon.device.mgt.core.grafana.mgt.sql.connection.GrafanaDatasourceConnectionFactory; -import org.wso2.carbon.device.mgt.core.grafana.mgt.sql.query.PreparedQuery; import java.sql.Connection; import java.sql.PreparedStatement; @@ -40,7 +40,8 @@ public class MySQLQueryEncoder implements QueryEncoder { } @Override - public String encode(PreparedQuery preparedQuery) throws SQLException, DBConnectionException { + public String encode(PreparedQuery preparedQuery) throws SQLException, DBConnectionException, + io.entgra.application.mgt.common.exception.DBConnectionException { try { Connection con = GrafanaDatasourceConnectionFactory.getConnection(databaseName); PreparedStatement stmt = con.prepareStatement(preparedQuery.getPreparedSQL()); @@ -62,7 +63,9 @@ public class MySQLQueryEncoder implements QueryEncoder { private String generateQueryFromPreparedStatement(PreparedStatement stmt) { String query = stmt.toString().substring(stmt.toString().indexOf(PREPARED_STATEMENT_STRING_OBJECT_ID_SEPARATOR) + PREPARED_STATEMENT_STRING_OBJECT_ID_SEPARATOR.length()); - // remove unnecessary "]" char at the end + // Below is how generated string of prepared statement may look like + // org.apache.tomcat.jdbc.pool.StatementFacade$StatementProxy[Proxy=1138452482; Query=; Delegate=com.mysql.cj.jdbc.ClientPreparedStatement: ] + // This removes unnecessary "]" char at the end that may remain after extracting the query if (query.charAt(query.length() - 1) == ']') { query = query.substring(0, query.length() - 1); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/encoder/QueryEncoder.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/encoder/QueryEncoder.java similarity index 77% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/encoder/QueryEncoder.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/encoder/QueryEncoder.java index 724557d434..81d7735a81 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/encoder/QueryEncoder.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/encoder/QueryEncoder.java @@ -15,16 +15,15 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.sql.query.encoder; +package io.entgra.analytics.mgt.grafana.proxy.core.sql.query.encoder; +import io.entgra.analytics.mgt.grafana.proxy.core.sql.query.PreparedQuery; import org.wso2.carbon.device.mgt.common.exceptions.DBConnectionException; -import org.wso2.carbon.device.mgt.common.exceptions.GrafanaManagementException; -import org.wso2.carbon.device.mgt.core.grafana.mgt.sql.query.PreparedQuery; import java.sql.SQLException; public interface QueryEncoder { - String encode(PreparedQuery preparedQuery) throws SQLException, DBConnectionException; + String encode(PreparedQuery preparedQuery) throws SQLException, DBConnectionException, io.entgra.application.mgt.common.exception.DBConnectionException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/encoder/QueryEncoderFactory.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/encoder/QueryEncoderFactory.java similarity index 87% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/encoder/QueryEncoderFactory.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/encoder/QueryEncoderFactory.java index 383f9a61b2..fe426f1f20 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/sql/query/encoder/QueryEncoderFactory.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/encoder/QueryEncoderFactory.java @@ -15,9 +15,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.sql.query.encoder; +package io.entgra.analytics.mgt.grafana.proxy.core.sql.query.encoder; -import org.wso2.carbon.device.mgt.core.grafana.mgt.util.GrafanaConstants; +import io.entgra.analytics.mgt.grafana.proxy.core.util.GrafanaConstants; public class QueryEncoderFactory { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/util/GrafanaConstants.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/util/GrafanaConstants.java similarity index 98% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/util/GrafanaConstants.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/util/GrafanaConstants.java index 0dfe683c2a..65865ad619 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/util/GrafanaConstants.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/util/GrafanaConstants.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.util; +package io.entgra.analytics.mgt.grafana.proxy.core.util; public class GrafanaConstants { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/util/GrafanaUtil.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/util/GrafanaUtil.java similarity index 70% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/util/GrafanaUtil.java rename to components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/util/GrafanaUtil.java index d78cc23ff1..40117cee60 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/grafana/mgt/util/GrafanaUtil.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/util/GrafanaUtil.java @@ -15,22 +15,25 @@ * under the License. */ -package org.wso2.carbon.device.mgt.core.grafana.mgt.util; +package io.entgra.analytics.mgt.grafana.proxy.core.util; import com.google.gson.Gson; import com.google.gson.JsonObject; +import io.entgra.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException; +import io.entgra.analytics.mgt.grafana.proxy.core.bean.GrafanaPanelIdentifier; +import io.entgra.analytics.mgt.grafana.proxy.core.config.GrafanaConfiguration; +import io.entgra.analytics.mgt.grafana.proxy.core.config.GrafanaConfigurationManager; +import io.entgra.analytics.mgt.grafana.proxy.core.exception.GrafanaEnvVariablesNotDefined; +import io.entgra.analytics.mgt.grafana.proxy.core.service.GrafanaAPIService; +import io.entgra.analytics.mgt.grafana.proxy.core.service.GrafanaQueryService; +import io.entgra.analytics.mgt.grafana.proxy.core.service.impl.GrafanaAPIServiceImpl; +import io.entgra.analytics.mgt.grafana.proxy.core.service.impl.GrafanaQueryServiceImpl; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.exceptions.GrafanaManagementException; import org.wso2.carbon.device.mgt.core.common.util.HttpUtil; -import org.wso2.carbon.device.mgt.core.grafana.mgt.bean.GrafanaPanelIdentifier; -import org.wso2.carbon.device.mgt.core.grafana.mgt.config.GrafanaConfiguration; -import org.wso2.carbon.device.mgt.core.grafana.mgt.config.GrafanaConfigurationManager; -import org.wso2.carbon.device.mgt.core.grafana.mgt.exception.GrafanaEnvVariablesNotDefined; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.GrafanaAPIService; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.GrafanaQueryService; import org.wso2.carbon.device.mgt.core.report.mgt.Constants; import java.net.URI; @@ -60,11 +63,11 @@ public class GrafanaUtil { throws GrafanaEnvVariablesNotDefined { String grafanaHost = System.getProperty(GrafanaConstants.HTTPS_HOST_ENV_VAR); String scheme = httpsProtocol; - if (Constants.HTTP_PROTOCOL.equals(requestScheme) || grafanaHost == null){ + if (Constants.HTTP_PROTOCOL.equals(requestScheme) || StringUtils.isEmpty(grafanaHost)){ grafanaHost = System.getProperty(GrafanaConstants.HTTP_HOST_ENV_VAR); scheme = httpProtocol; } - if(grafanaHost == null) { + if(StringUtils.isEmpty(grafanaHost)) { String errMsg = "Grafana host is not defined in the iot-server.sh properly."; log.error(errMsg); throw new GrafanaEnvVariablesNotDefined(errMsg); @@ -111,31 +114,4 @@ public class GrafanaUtil { public static int getTenantId() { return PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); } - - public static GrafanaAPIService getGrafanaAPIService() { - GrafanaAPIService grafanaAPIService; - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - grafanaAPIService = (GrafanaAPIService) ctx.getOSGiService( - GrafanaAPIService.class, null); - if (grafanaAPIService == null) { - String msg = "Report Management service not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - return grafanaAPIService; - } - - public static GrafanaQueryService getGrafanaQueryService() { - GrafanaQueryService grafanaQueryService; - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - grafanaQueryService = (GrafanaQueryService) ctx.getOSGiService( - GrafanaQueryService.class, null); - if (grafanaQueryService == null) { - String msg = "Report Management service not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - return grafanaQueryService; - } - } diff --git a/components/analytics-mgt/grafana-mgt/pom.xml b/components/analytics-mgt/grafana-mgt/pom.xml new file mode 100644 index 0000000000..b2a02f90ad --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/pom.xml @@ -0,0 +1,42 @@ + + + + + + + org.wso2.carbon.devicemgt + analytics-mgt + 5.0.1-SNAPSHOT + ../pom.xml + + + 4.0.0 + grafana-mgt + pom + Entgra - Grafana API Handler Component + http://entgra.io + + + + io.entgra.analytics.mgt.grafana.proxy.core + io.entgra.analytics.mgt.grafana.proxy.common + io.entgra.analytics.mgt.grafana.proxy.api + + + diff --git a/components/analytics-mgt/pom.xml b/components/analytics-mgt/pom.xml new file mode 100644 index 0000000000..120d440a44 --- /dev/null +++ b/components/analytics-mgt/pom.xml @@ -0,0 +1,20 @@ + + + + carbon-devicemgt + org.wso2.carbon.devicemgt + 5.0.1-SNAPSHOT + ../../pom.xml + + + 4.0.0 + analytics-mgt + pom + Entgra - Analytics Management Component + http://entgra.io + + + grafana-mgt + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ReportManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ReportManagementService.java index c5eeccab2c..cbec6b47c9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ReportManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ReportManagementService.java @@ -83,89 +83,6 @@ import java.util.List; @Consumes(MediaType.APPLICATION_JSON) public interface ReportManagementService { - @POST - @Path("/grafana/api/ds/query") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Grafana query API proxy", - tags = "Analytics", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") - }) - } - ) - Response queryDatasource(JsonObject body, @Context HttpHeaders headers, @Context UriInfo requestUriInfo); - - @POST - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @Path("/grafana/api/frontend-metrics") - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Grafana frontend-metric API proxy", - tags = "Analytics", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") - }) - } - ) - Response frontendMetrics(JsonObject body, @Context HttpHeaders headers, @Context UriInfo requestUriInfo); - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("/grafana/api/dashboards/uid/{uid}") - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Grafana dashboard details API proxy", - tags = "Analytics", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") - }) - } - ) - Response getDashboard(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) throws ClassNotFoundException; - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @Path("/grafana/api/annotations") - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Grafana annotations API proxy", - tags = "Analytics", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") - }) - } - ) - Response getAnnotations(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) throws ClassNotFoundException; - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("/grafana/api/alerts/states-for-dashboard") - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Get Grafana alert states for dashboard details API proxy", - tags = "Analytics", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") - }) - } - ) - Response getAlertStateForDashboards(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) throws ClassNotFoundException; - @GET @Path("/devices") @ApiOperation( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ReportManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ReportManagementServiceImpl.java index 1342bc1801..eb95311868 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ReportManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ReportManagementServiceImpl.java @@ -26,38 +26,25 @@ import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.exceptions.BadRequestException; -import org.wso2.carbon.device.mgt.common.exceptions.DBConnectionException; import org.wso2.carbon.device.mgt.common.exceptions.DeviceTypeNotFoundException; -import org.wso2.carbon.device.mgt.common.exceptions.GrafanaManagementException; import org.wso2.carbon.device.mgt.common.exceptions.ReportManagementException; -import org.wso2.carbon.device.mgt.core.grafana.mgt.bean.GrafanaPanelIdentifier; -import org.wso2.carbon.device.mgt.core.grafana.mgt.exception.MaliciousQueryAttempt; -import org.wso2.carbon.device.mgt.core.grafana.mgt.util.GrafanaUtil; import org.wso2.carbon.device.mgt.core.report.mgt.Constants; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.common.ReportFiltersList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; -import org.wso2.carbon.device.mgt.jaxrs.exception.RefererNotValid; import org.wso2.carbon.device.mgt.jaxrs.service.api.ReportManagementService; -import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.GrafanaRequestHandlerUtil; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; 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.Context; -import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import java.io.IOException; -import java.sql.SQLException; import java.util.List; /** @@ -70,85 +57,6 @@ public class ReportManagementServiceImpl implements ReportManagementService { private static final Log log = LogFactory.getLog(ReportManagementServiceImpl.class); - @POST - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @Path("/grafana/api/ds/query") - @Override - public Response queryDatasource(JsonObject body, @Context HttpHeaders headers, @Context UriInfo requestUriInfo) { - try { - GrafanaPanelIdentifier panelIdentifier = GrafanaRequestHandlerUtil.getPanelIdentifier(headers); - GrafanaUtil.getGrafanaQueryService().buildSafeQuery(body, panelIdentifier.getDashboardId(), panelIdentifier.getPanelId(), requestUriInfo.getRequestUri()); - return GrafanaRequestHandlerUtil.proxyPassPostRequest(body, requestUriInfo, panelIdentifier.getOrgId()); - } catch (MaliciousQueryAttempt e) { - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(e.getMessage()).build()).build(); - } catch (GrafanaManagementException e) { - return GrafanaRequestHandlerUtil.constructInternalServerError(e, e.getMessage()); - } catch (RefererNotValid e) { - return GrafanaRequestHandlerUtil.constructInvalidReferer(); - } catch (SQLException | IOException | DBConnectionException e) { - log.error(e); - return GrafanaRequestHandlerUtil.constructInternalServerError(e, e.getMessage()); - } - } - - @POST - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @Path("/grafana/api/frontend-metrics") - @Override - public Response frontendMetrics(JsonObject body, @Context HttpHeaders headers, @Context UriInfo requestUriInfo) { - return proxyPassPostRequest(body, headers, requestUriInfo); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("/grafana/api/dashboards/uid/{uid}") - @Override - public Response getDashboard(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) { - return proxyPassGetRequest(headers, requestUriInfo); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @Path("/grafana/api/annotations") - @Override - public Response getAnnotations(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) { - return proxyPassGetRequest(headers, requestUriInfo); - } - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("/grafana/api/alerts/states-for-dashboard") - @Override - public Response getAlertStateForDashboards(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) { - return proxyPassGetRequest(headers, requestUriInfo); - } - - public Response proxyPassGetRequest(HttpHeaders headers, UriInfo requestUriInfo) { - try { - GrafanaPanelIdentifier panelIdentifier = GrafanaRequestHandlerUtil.getPanelIdentifier(headers); - return GrafanaRequestHandlerUtil.proxyPassGetRequest(requestUriInfo, panelIdentifier.getOrgId()); - } catch (RefererNotValid e) { - return GrafanaRequestHandlerUtil.constructInvalidReferer(); - } catch (GrafanaManagementException e) { - return GrafanaRequestHandlerUtil.constructInternalServerError(e, e.getMessage()); - } - } - - public Response proxyPassPostRequest(JsonObject body, HttpHeaders headers, UriInfo requestUriInfo) { - try { - GrafanaPanelIdentifier panelIdentifier = GrafanaRequestHandlerUtil.getPanelIdentifier(headers); - return GrafanaRequestHandlerUtil.proxyPassPostRequest(body, requestUriInfo, panelIdentifier.getOrgId()); - } catch (RefererNotValid e) { - return GrafanaRequestHandlerUtil.constructInvalidReferer(); - } catch (GrafanaManagementException e) { - return GrafanaRequestHandlerUtil.constructInternalServerError(e, e.getMessage()); - } - } - - @GET @Path("/devices") @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index bfaf80a284..859659bdf5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -56,10 +56,6 @@ import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManag import org.wso2.carbon.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl; import org.wso2.carbon.device.mgt.core.event.config.EventConfigurationProviderServiceImpl; import org.wso2.carbon.device.mgt.core.geo.service.GeoLocationProviderServiceImpl; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.GrafanaAPIService; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.GrafanaQueryService; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.impl.GrafanaAPIServiceImpl; -import org.wso2.carbon.device.mgt.core.grafana.mgt.service.impl.GrafanaQueryServiceImpl; import org.wso2.carbon.device.mgt.core.metadata.mgt.MetadataManagementServiceImpl; import org.wso2.carbon.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOFactory; import org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImpl; @@ -334,13 +330,6 @@ public class DeviceManagementServiceComponent { = new NotificationManagementServiceImpl(); bundleContext.registerService(NotificationManagementService.class.getName(), notificationManagementService, null); - /* Registering Grafana Services */ - GrafanaAPIService grafanaAPIService = new GrafanaAPIServiceImpl(); - GrafanaQueryService grafanaQueryService = new GrafanaQueryServiceImpl(grafanaAPIService); - bundleContext.registerService(GrafanaAPIService.class.getName(), grafanaAPIService, null); - bundleContext.registerService(GrafanaQueryService.class.getName(), grafanaQueryService, null); - - /* Registering Report Service */ ReportManagementService reportManagementService = new ReportManagementServiceImpl(); bundleContext.registerService(ReportManagementService.class.getName(), reportManagementService, null); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/HttpReportingUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/HttpReportingUtil.java index 5080ab2a24..54877fdaa1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/HttpReportingUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/HttpReportingUtil.java @@ -17,10 +17,8 @@ package org.wso2.carbon.device.mgt.core.util; -import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ContentType; @@ -30,17 +28,7 @@ import org.apache.http.impl.client.HttpClients; import org.apache.http.protocol.HTTP; import org.wso2.carbon.device.mgt.common.exceptions.EventPublishingException; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.core.report.mgt.Constants; - -import javax.ws.rs.core.PathSegment; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; public class HttpReportingUtil { @@ -65,115 +53,7 @@ public class HttpReportingUtil { "invoking API. API endpoint: " + endpoint, e); } } - public static String getRequestSubPathFromEnd(URI requestUri, int position) { - String[] pathList = requestUri.getPath().split("/"); - if (pathList.length - 1 >= position) { - return pathList[pathList.length - 1 - position]; - } - return null; - } - - public static String getRequestSubPath(String fullPath, int position) { - String[] pathList = fullPath.split("/"); - if (pathList.length - 1 > position) { - String path = pathList[position + 1]; - if(path.contains(Constants.URI_QUERY_SEPARATOR)) { - path = path.substring(0, path.indexOf(Constants.URI_QUERY_SEPARATOR)); - } - return path; - } - return null; - } - public static String getResponseString(HttpResponse response) throws IOException { - try (BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) { - StringBuilder result = new StringBuilder(); - String line; - while ((line = rd.readLine()) != null) { - result.append(line); - } - return result.toString(); - } - } - public static boolean isQueryParamExist(String param, URI request) { - Map> queryMap = getQueryMap(request); - return queryMap.containsKey(param); - } - public static String getFirstQueryValue(String param, Map> queryMap) { - List valueList = queryMap.get(param); - String firstValue = null; - if(valueList != null) { - firstValue = valueList.get(0); - } - return firstValue; - } - public static Map> getQueryMap(String uri) { - String query = getQueryFromURIPath(uri); - Map> map = new HashMap<>(); - if (query != null) { - String[] params = query.split("&"); - for (String param : params) { - String[] paramArr = param.split("="); - if (paramArr.length == 2) { - String name = paramArr[0]; - String value = paramArr[1]; - if (!map.containsKey(name)) { - List valueList = new ArrayList<>(); - map.put(name, valueList); - } - map.get(name).add(value); - } - } - } - return map; - } - public static Map> getQueryMap(URI request) { - String query = request.getQuery(); - Map> map = new HashMap<>(); - if (query != null) { - String[] params = query.split("&"); - for (String param : params) { - String[] paramArr = param.split("="); - if (paramArr.length == 2) { - String name = paramArr[0]; - String value = paramArr[1]; - if (!map.containsKey(name)) { - List valueList = new ArrayList<>(); - map.put(name, valueList); - } - map.get(name).add(value); - } - } - } - return map; - } - public static String getQueryFromURIPath(String uri) { - String query = null; - if (uri.length() > "?".length() && uri.contains("?")) { - query = uri.substring(uri.lastIndexOf("?") + "?".length()); - } - if (StringUtils.isEmpty(query)) { - query = null; - } - return query; - } - - public static String getMemeType(HttpResponse response) { - String memeType = ""; - Header contentType = response.getEntity().getContentType(); - if (contentType != null) { - memeType = contentType.getValue().split(";")[0].trim(); - } - return memeType; - } - public static String getGrafanaBaseUrl(String scheme) { - String host = "localhost"; - String port = "3000"; - if (scheme.equals(Constants.HTTP_PROTOCOL)) { - port = "3000"; - } - return host + Constants.COLON + port; - } public static boolean isPublishingEnabledForTenant() { Object configuration = DeviceManagerUtil.getConfiguration(IS_EVENT_PUBLISHING_ENABLED); diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml index ba9f7878c8..6d640e57b8 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml @@ -102,6 +102,17 @@ org.wso2.carbon.apimgt.application.extension provided + + org.wso2.carbon.devicemgt + io.entgra.analytics.mgt.grafana.proxy.core + provided + + + org.apache.httpcomponents.wso2 + httpclient + + + org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.core diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/GrafanaHandler.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/GrafanaHandler.java index 4b664e0fef..3ac99b1044 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/GrafanaHandler.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/GrafanaHandler.java @@ -18,6 +18,9 @@ package io.entgra.ui.request.interceptor; +import io.entgra.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException; +import io.entgra.analytics.mgt.grafana.proxy.core.exception.GrafanaEnvVariablesNotDefined; +import io.entgra.analytics.mgt.grafana.proxy.core.util.GrafanaUtil; import io.entgra.ui.request.interceptor.beans.AuthData; import io.entgra.ui.request.interceptor.beans.ProxyResponse; import io.entgra.ui.request.interceptor.util.GrafanaHandlerUtil; @@ -32,10 +35,8 @@ import org.apache.http.HttpStatus; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.*; import org.apache.http.impl.client.CloseableHttpClient; -import org.wso2.carbon.device.mgt.common.exceptions.GrafanaManagementException; import org.wso2.carbon.device.mgt.core.common.util.HttpUtil; -import org.wso2.carbon.device.mgt.core.grafana.mgt.exception.GrafanaEnvVariablesNotDefined; -import org.wso2.carbon.device.mgt.core.grafana.mgt.util.GrafanaUtil; + import javax.servlet.annotation.MultipartConfig; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/websocket/GrafanaLiveSecurityFilter.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/websocket/GrafanaLiveSecurityFilter.java index 6ce15b7b4f..091a1e005b 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/websocket/GrafanaLiveSecurityFilter.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/websocket/GrafanaLiveSecurityFilter.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package io.entgra.ui.request.interceptor.websocket; import io.entgra.ui.request.interceptor.beans.AuthData; @@ -20,7 +38,7 @@ public class GrafanaLiveSecurityFilter implements Filter { private static final Log log = LogFactory.getLog(GrafanaLiveSecurityFilter.class); @Override - public void init(FilterConfig filterConfig) throws ServletException { + public void init(FilterConfig filterConfig) { } diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/websocket/GrafanaWebSocketClient.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/websocket/GrafanaWebSocketClient.java index db921e7719..f6b157e4f7 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/websocket/GrafanaWebSocketClient.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/websocket/GrafanaWebSocketClient.java @@ -1,5 +1,25 @@ +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package io.entgra.ui.request.interceptor.websocket; +import io.entgra.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException; +import io.entgra.analytics.mgt.grafana.proxy.core.util.GrafanaUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -12,19 +32,14 @@ import javax.websocket.OnError; import javax.websocket.CloseReason; import javax.websocket.WebSocketContainer; import java.net.URI; -import io.entgra.ui.request.interceptor.util.HandlerConstants; -import org.wso2.carbon.device.mgt.common.exceptions.GrafanaManagementException; -import org.wso2.carbon.device.mgt.core.grafana.mgt.util.GrafanaUtil; import javax.websocket.ClientEndpointConfig; import javax.websocket.Endpoint; import javax.websocket.EndpointConfig; -import javax.websocket.MessageHandler; import javax.ws.rs.core.HttpHeaders; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.concurrent.Callable; import java.util.function.Consumer; @ClientEndpoint diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/websocket/GrafanaWebSocketHandler.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/websocket/GrafanaWebSocketHandler.java index 567489c9cd..04dff01844 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/websocket/GrafanaWebSocketHandler.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/websocket/GrafanaWebSocketHandler.java @@ -1,10 +1,28 @@ +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package io.entgra.ui.request.interceptor.websocket; +import io.entgra.analytics.mgt.grafana.proxy.core.exception.GrafanaEnvVariablesNotDefined; +import io.entgra.analytics.mgt.grafana.proxy.core.util.GrafanaConstants; +import io.entgra.analytics.mgt.grafana.proxy.core.util.GrafanaUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.core.grafana.mgt.exception.GrafanaEnvVariablesNotDefined; -import org.wso2.carbon.device.mgt.core.grafana.mgt.util.GrafanaConstants; -import org.wso2.carbon.device.mgt.core.grafana.mgt.util.GrafanaUtil; import javax.websocket.CloseReason; import javax.websocket.server.ServerEndpoint; diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml new file mode 100644 index 0000000000..f51fb0820e --- /dev/null +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml @@ -0,0 +1,120 @@ + + + + + + + org.wso2.carbon.devicemgt + grafana-mgt-feature + 5.0.1-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.analytics.mgt.grafana.proxy.api.feature + pom + Entgra - Grafana Proxy API Feature + https://entgra.io + This feature contains the APIs required for Grafana + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + grafana-mgt-copy + package + + copy + + + + + org.wso2.carbon.devicemgt + io.entgra.analytics.mgt.grafana.proxy.api + ${project.version} + war + true + + ${project.build.directory}/maven-shared-archive-resources/webapps + + api#grafana-mgt#v1.0.war + + + + + + + + org.apache.maven.plugins + maven-resources-plugin + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + org.wso2.maven + carbon-p2-plugin + + + p2-feature-generation + package + + p2-feature-gen + + + io.entgra.analytics.mgt.grafana.proxy.api + ../../../etc/feature.properties + + + + org.wso2.carbon.p2.category.type:server + + org.eclipse.equinox.p2.type.group:false + + + + + + + + + + + diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/src/main/resources/build.properties b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/src/main/resources/build.properties new file mode 100644 index 0000000000..9c86577d76 --- /dev/null +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/src/main/resources/build.properties @@ -0,0 +1 @@ +custom = true diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/src/main/resources/p2.inf b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/src/main/resources/p2.inf new file mode 100644 index 0000000000..ca042b5b3e --- /dev/null +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/src/main/resources/p2.inf @@ -0,0 +1,3 @@ +instructions.configure = \ +org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.analytics.mgt.grafana.proxy.api_${feature.version}/webapps/api#grafana-mgt#v1.0.war,target:${installFolder}/../../deployment/server/webapps/api#grafana-mgt#v1.0.war,overwrite:true);\ diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml new file mode 100644 index 0000000000..8896c43ebd --- /dev/null +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml @@ -0,0 +1,140 @@ + + + + + + + org.wso2.carbon.devicemgt + grafana-mgt-feature + 5.0.1-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.analytics.mgt.grafana.proxy.server.feature + pom + + Entgra - Grafana Management Server Feature + https://entgra.io + This feature contains the core bundles required for Back-end Grafana Management functionality + + + + + org.wso2.carbon.devicemgt + io.entgra.analytics.mgt.grafana.proxy.common + + + org.wso2.carbon.devicemgt + io.entgra.analytics.mgt.grafana.proxy.core + + + com.googlecode.plist + dd-plist + ${googlecode.plist.version} + + + commons-validator + commons-validator + ${commons-validator.version} + + + org.apache.cxf + cxf-rt-frontend-jaxrs + ${cxf.version} + + + com.h2database.wso2 + h2-database-engine + + + + + + + maven-resources-plugin + 2.6 + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + org.wso2.maven + carbon-p2-plugin + ${carbon.p2.plugin.version} + + + p2-feature-generation + package + + p2-feature-gen + + + io.entgra.analytics.mgt.grafana.proxy.server + ../../../etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + org.eclipse.equinox.p2.type.group:false + + + + + org.wso2.carbon.devicemgt:io.entgra.analytics.mgt.grafana.proxy.common:${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt:io.entgra.analytics.mgt.grafana.proxy.core:${carbon.device.mgt.version} + + + com.googlecode.plist:dd-plist:${googlecode.plist.version} + + + commons-validator:commons-validator:${commons-validator.version} + + + + + + + + + + + + 1.6 + + diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/src/main/resources/build.properties b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/src/main/resources/build.properties new file mode 100644 index 0000000000..9c86577d76 --- /dev/null +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/src/main/resources/build.properties @@ -0,0 +1 @@ +custom = true diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/grafana-config.xml b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/src/main/resources/conf/grafana-config.xml similarity index 96% rename from features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/grafana-config.xml rename to features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/src/main/resources/conf/grafana-config.xml index 1954dfc2e4..09344263f4 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/grafana-config.xml +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/src/main/resources/conf/grafana-config.xml @@ -19,7 +19,7 @@ --> - + 100 @@ -30,6 +30,6 @@ admin - admin2 + admin diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/src/main/resources/conf_templates.templates.repository.conf/grafana-config.xml.j2 b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/src/main/resources/conf_templates.templates.repository.conf/grafana-config.xml.j2 new file mode 100644 index 0000000000..09344263f4 --- /dev/null +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/src/main/resources/conf_templates.templates.repository.conf/grafana-config.xml.j2 @@ -0,0 +1,35 @@ + + + + + + + + 100 + + + 100 + + + + + admin + admin + + diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/src/main/resources/p2.inf b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/src/main/resources/p2.inf new file mode 100644 index 0000000000..f269b204c4 --- /dev/null +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/src/main/resources/p2.inf @@ -0,0 +1,4 @@ +instructions.configure = \ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.analytics.mgt.grafana.proxy.server_${feature.version}/conf/grafana-config.xml,target:${installFolder}/../../conf/grafana-config.xml,overwrite:true);\ + +instructions.unconfigure = \ \ No newline at end of file diff --git a/features/analytics-mgt/grafana-mgt/pom.xml b/features/analytics-mgt/grafana-mgt/pom.xml new file mode 100644 index 0000000000..cdfca8e5a2 --- /dev/null +++ b/features/analytics-mgt/grafana-mgt/pom.xml @@ -0,0 +1,40 @@ + + + + + + + org.wso2.carbon.devicemgt + analytics-mgt-feature + 5.0.1-SNAPSHOT + ../pom.xml + + + 4.0.0 + grafana-mgt-feature + pom + Entgra - Grafana Management Feature + http://entgra.io + + + io.entgra.analytics.mgt.grafana.proxy.server.feature + io.entgra.analytics.mgt.grafana.proxy.api.feature + + + diff --git a/features/analytics-mgt/pom.xml b/features/analytics-mgt/pom.xml new file mode 100644 index 0000000000..29d65d264a --- /dev/null +++ b/features/analytics-mgt/pom.xml @@ -0,0 +1,19 @@ + + + + carbon-devicemgt + org.wso2.carbon.devicemgt + 5.0.1-SNAPSHOT + ../../pom.xml + + + 4.0.0 + analytics-mgt-feature + pom + Entgra - Analytics Management Feature + http://entgra.io + + + grafana-mgt + + diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml index 88d9b47d29..22f4ef0175 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml @@ -26,6 +26,7 @@ 10000 + analytics_management application_management device_management subscription_management @@ -34,6 +35,7 @@ true + perm:grafana:api:view perm:app:review:view perm:app:review:update perm:app:publisher:view diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/datasources/reporting-mgt-datasources.xml.j2 b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/datasources/reporting-mgt-datasources.xml.j2 new file mode 100644 index 0000000000..c070808f0a --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/datasources/reporting-mgt-datasources.xml.j2 @@ -0,0 +1,48 @@ + + + + + org.wso2.carbon.ndatasource.rdbms.RDBMSDataSourceReader + + + + + + jdbc/MDM_REPORTS_DS + The datasource used for Report Management + + jdbc/MDM_REPORTS_DS + + + + jdbc:mysql://localhost:3306/DM_DB?autoReconnect=true&relaxAutoCommit=true&useSSL=false + root + root + com.mysql.cj.jdbc.Driver + 50 + 60000 + true + SELECT 1 + 30000 + + + + + + diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/reporting-mgt.xml.j2 b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/reporting-mgt.xml.j2 new file mode 100644 index 0000000000..b768822971 --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/reporting-mgt.xml.j2 @@ -0,0 +1,21 @@ + + + + jdbc/MDM_REPORTS_DS + diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/p2.inf b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/p2.inf index 5ebad17202..178b0961b0 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/p2.inf +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/p2.inf @@ -1,7 +1,9 @@ instructions.configure = \ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/conf/datasources/cdm-datasources.xml,target:${installFolder}/../../conf/datasources/cdm-datasources.xml,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/conf/datasources/reporting-mgt-datasources.xml,target:${installFolder}/../../conf/datasources/reporting-mgt-datasources.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/conf/cdm-config.xml,target:${installFolder}/../../conf/cdm-config.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/conf/mdm-ui-config.xml,target:${installFolder}/../../conf/mdm-ui-config.xml,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/conf/reporting-mgt.xml,target:${installFolder}/../../conf/reporting-mgt.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/conf/license-config.xml,target:${installFolder}/../../conf/etc/license-config.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/conf/remote-appmanager-config.xml,target:${installFolder}/../../conf/etc/remote-appmanager-config.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/dbscripts/cdm,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\ diff --git a/pom.xml b/pom.xml index e21b282b4e..ad5bd2918a 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,7 @@ components/certificate-mgt components/ui-request-interceptor components/transport-mgt + components/analytics-mgt components/webapp-authenticator-framework features/device-mgt features/apimgt-extensions @@ -55,6 +56,7 @@ features/jwt-client features/device-mgt-extensions features/transport-mgt + features/analytics-mgt features/webapp-authenticator-framework @@ -287,6 +289,18 @@ org.wso2.carbon.apimgt.application.extension.api ${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt + io.entgra.analytics.mgt.grafana.proxy.api.feature + zip + ${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt + io.entgra.analytics.mgt.grafana.proxy.server.feature + zip + ${carbon.device.mgt.version} + org.wso2.carbon.devicemgt io.entgra.application.mgt.server.feature @@ -314,6 +328,11 @@ io.entgra.transport.mgt.sms.handler.common ${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt + io.entgra.analytics.mgt.grafana.proxy.api + ${carbon.device.mgt.version} + org.wso2.carbon.devicemgt io.entgra.analytics.mgt.grafana.proxy.core