diff --git a/components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/Utils.java b/components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/Utils.java index ecdcd2d254..b8b7155257 100644 --- a/components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/Utils.java +++ b/components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/Utils.java @@ -37,7 +37,6 @@ import org.osgi.service.cm.Configuration; import org.osgi.service.cm.ConfigurationAdmin; import org.wso2.micro.core.util.AuditLogger; -import org.wso2.micro.integrator.initializer.dashboard.ArtifactUpdateListener; import org.wso2.micro.integrator.initializer.utils.ConfigurationHolder; import org.wso2.micro.integrator.registry.MicroIntegratorRegistry; import org.wso2.micro.integrator.security.MicroIntegratorSecurityUtils; @@ -168,13 +167,11 @@ static JSONObject handleTracing(String performedBy, String type, String artifact msg = "Enabled tracing for ('" + artifactName + "')"; response.put(Constants.MESSAGE, msg); AuditLogger.logAuditMessage(performedBy, type, Constants.AUDIT_LOG_ACTION_ENABLE, info); - ArtifactUpdateListener.addToUpdatedArtifactsQueue(artifactType, artifactName); } else if (Constants.DISABLE.equalsIgnoreCase(traceState)) { config.disableTracing(); msg = "Disabled tracing for ('" + artifactName + "')"; response.put(Constants.MESSAGE, msg); AuditLogger.logAuditMessage(performedBy, type, Constants.AUDIT_LOG_ACTION_DISABLED, info); - ArtifactUpdateListener.addToUpdatedArtifactsQueue(artifactType, artifactName); } else { msg = "Invalid value for state " + Constants.TRACE; response = createJsonError(msg, axisMsgCtx, Constants.BAD_REQUEST); diff --git a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/dashboard/ArtifactDeploymentListener.java b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/dashboard/ArtifactDeploymentListener.java deleted file mode 100644 index 4abb388bd5..0000000000 --- a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/dashboard/ArtifactDeploymentListener.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2021, 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 org.wso2.micro.integrator.initializer.dashboard; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Manages deployed and undeployed artifacts in micro integrator to notify the dashboard. - */ -public class ArtifactDeploymentListener { - - private ArtifactDeploymentListener() { - - } - private static final Log log = LogFactory.getLog(ArtifactDeploymentListener.class); - - private static JsonArray deployedArtifacts = new JsonArray(); - private static JsonArray undeployedArtifacts = new JsonArray(); - - public static void addToDeployedArtifactsQueue(JsonObject deployedArtifact) { - if (HeartBeatComponent.isDashboardConfigured()) { - log.debug("Adding " + deployedArtifact.get("type").toString() + " " + - deployedArtifact.get("name").toString() + " to deployed artifacts queue."); - deployedArtifacts.add(deployedArtifact); - } - } - - public static void addToUndeployedArtifactsQueue(JsonObject undeployedArtifact) { - if (HeartBeatComponent.isDashboardConfigured()) { - log.debug("Adding " + undeployedArtifact.get("type").toString() + " " + - undeployedArtifact.get("name").toString() + " to undeployed artifacts queue."); - undeployedArtifacts.add(undeployedArtifact); - } - } - - public static JsonArray getDeployedArtifacts() { - return deployedArtifacts; - } - - public static JsonArray getUndeployedArtifacts() { - return undeployedArtifacts; - } - - public static void removeFromDeployedArtifactsQueue(int artifactsSize) { - for (int i = 0; i < artifactsSize; i++) { - deployedArtifacts.remove(0); - } - } - - public static void removeFromUndeployedArtifactsQueue(int artifactsSize) { - for (int i = 0; i < artifactsSize; i++) { - undeployedArtifacts.remove(0); - } - } - -} diff --git a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/dashboard/ArtifactUpdateListener.java b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/dashboard/ArtifactUpdateListener.java deleted file mode 100644 index 2ef127e7c4..0000000000 --- a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/dashboard/ArtifactUpdateListener.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.wso2.micro.integrator.initializer.dashboard; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Manages updated artifacts in micro integrator using the management api to notify the dashboard. - */ -public class ArtifactUpdateListener { - - private ArtifactUpdateListener() { - - } - - private static final Log log = LogFactory.getLog(ArtifactUpdateListener.class); - - private static JsonArray stateChangedArtifacts = new JsonArray(); - - public static void addToUpdatedArtifactsQueue(String artifactType, String name) { - if (HeartBeatComponent.isDashboardConfigured()) { - JsonObject updatedArtifact = getUpdatedArtifact(artifactType, name); - log.debug("Adding " + updatedArtifact.get("type").toString() + " " + updatedArtifact.get("name").toString() + - " to state changed artifacts queue."); - stateChangedArtifacts.add(updatedArtifact); - } - } - - public static JsonArray getStateChangedArtifacts() { - return stateChangedArtifacts; - } - - public static void removeFromUpdatedArtifactQueue(int artifactsSize) { - for (int i = 0; i < artifactsSize; i++) { - stateChangedArtifacts.remove(0); - } - } - - private static JsonObject getUpdatedArtifact(String type, String name) { - JsonObject updatedArtifact = new JsonObject(); - updatedArtifact.addProperty("type", type); - updatedArtifact.addProperty("name", name); - return updatedArtifact; - } -} diff --git a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/dashboard/HeartBeatComponent.java b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/dashboard/HeartBeatComponent.java index 904d8e62ea..9f5b7d031a 100644 --- a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/dashboard/HeartBeatComponent.java +++ b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/dashboard/HeartBeatComponent.java @@ -17,7 +17,6 @@ */ package org.wso2.micro.integrator.initializer.dashboard; -import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import com.google.gson.JsonParser; @@ -40,9 +39,6 @@ import org.wso2.micro.core.util.StringUtils; import java.io.IOException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; import java.util.Map; import java.util.UUID; import java.util.concurrent.Executors; @@ -74,10 +70,6 @@ private HeartBeatComponent(){ private static final Log log = LogFactory.getLog(HeartBeatComponent.class); private static final Map configs = ConfigParser.getParsedConfigs(); - private static final String CHANGE_NOTIFICATION = "changeNotification"; - private static final String DEPLOYED_ARTIFACTS = "deployedArtifacts"; - private static final String UNDEPLOYED_ARTIFACTS = "undeployedArtifacts"; - private static final String STATE_CHANGED_ARTIFACTS = "stateChangedArtifacts"; public static void invokeHeartbeatExecutorService() { String heartbeatApiUrl = configs.get(DASHBOARD_CONFIG_URL) + "/heartbeat"; @@ -100,8 +92,6 @@ public static void invokeHeartbeatExecutorService() { ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); Runnable runnableTask = () -> { - JsonObject changeNotification = createChangeNotification(); - heartbeatPayload.add(CHANGE_NOTIFICATION, changeNotification); try (CloseableHttpClient client = HttpClients.custom().setSSLSocketFactory( new SSLConnectionSocketFactory( @@ -113,15 +103,9 @@ public static void invokeHeartbeatExecutorService() { CloseableHttpResponse response = client.execute(httpPost); JsonObject jsonResponse = getJsonResponse(response); if (jsonResponse != null && jsonResponse.get("status").getAsString().equals("success")) { - int deployedArtifactsCount = heartbeatPayload.get(CHANGE_NOTIFICATION).getAsJsonObject() - .get(DEPLOYED_ARTIFACTS).getAsJsonArray().size(); - int undeployedArtifactsCount = heartbeatPayload.get(CHANGE_NOTIFICATION).getAsJsonObject() - .get(UNDEPLOYED_ARTIFACTS).getAsJsonArray().size(); - int updatedArtifactsCount = heartbeatPayload.get(CHANGE_NOTIFICATION).getAsJsonObject() - .get(STATE_CHANGED_ARTIFACTS).getAsJsonArray().size(); - ArtifactDeploymentListener.removeFromUndeployedArtifactsQueue(undeployedArtifactsCount); - ArtifactDeploymentListener.removeFromDeployedArtifactsQueue(deployedArtifactsCount); - ArtifactUpdateListener.removeFromUpdatedArtifactQueue(updatedArtifactsCount); + log.debug("Heartbeat sent successfully."); + } else { + log.debug("Error occurred while sending the heartbeat."); } } catch (Exception e) { log.debug("Error occurred while processing the heartbeat.", e); @@ -189,17 +173,6 @@ private static String generateRandomId() { return UUID.randomUUID().toString(); } - private static JsonObject createChangeNotification() { - JsonObject changeNotification = new JsonObject(); - JsonArray deployedArtifacts = ArtifactDeploymentListener.getDeployedArtifacts(); - JsonArray undeployedArtifacts = ArtifactDeploymentListener.getUndeployedArtifacts(); - JsonArray stateChangedArtifacts = ArtifactUpdateListener.getStateChangedArtifacts(); - changeNotification.add(DEPLOYED_ARTIFACTS, deployedArtifacts); - changeNotification.add(UNDEPLOYED_ARTIFACTS, undeployedArtifacts); - changeNotification.add(STATE_CHANGED_ARTIFACTS, stateChangedArtifacts); - return changeNotification; - } - public static boolean isDashboardConfigured() { return configs.get(DASHBOARD_CONFIG_URL) != null; } diff --git a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/application/deployer/CappDeployer.java b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/application/deployer/CappDeployer.java index fa54a81387..ebfe88af65 100644 --- a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/application/deployer/CappDeployer.java +++ b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/application/deployer/CappDeployer.java @@ -42,7 +42,6 @@ import org.wso2.micro.core.CarbonAxisConfigurator; import org.wso2.micro.core.util.CarbonException; import org.wso2.micro.core.util.FileManipulator; -import org.wso2.micro.integrator.initializer.dashboard.ArtifactDeploymentListener; import org.wso2.micro.integrator.initializer.serviceCatalog.ServiceCatalogDeployer; import org.wso2.micro.integrator.initializer.utils.DeployerUtil; import org.wso2.micro.integrator.initializer.utils.ServiceCatalogUtils; @@ -203,14 +202,6 @@ private void deployCarbonApps(String artifactPath) throws CarbonException { this.addCarbonApp(currentApp); log.info("Successfully Deployed Carbon Application : " + currentApp.getAppNameWithVersion() + AppDeployerUtils.getTenantIdLogString(AppDeployerUtils.getTenantId())); - for (Artifact.Dependency dependency : currentApp.getAppConfig().getApplicationArtifact().getDependencies()) { - if (dependency.getServerRole().equals("DataServicesServer")) { - JsonObject deployedDataService = createUpdatedDataServiceInfoObject(dependency); - ArtifactDeploymentListener.addToDeployedArtifactsQueue(deployedDataService); - } - } - JsonObject deployedCarbonApp = createUpdatedCappInfoObject(currentApp); - ArtifactDeploymentListener.addToDeployedArtifactsQueue(deployedCarbonApp); } } catch (DeploymentException e) { log.error("Error occurred while deploying the Carbon application: " + cAppName @@ -622,35 +613,11 @@ private void undeployCarbonApp(CarbonApplication carbonApp, FileManipulator.deleteDir(carbonApp.getExtractedPath()); log.info("Successfully undeployed Carbon Application : " + carbonApp.getAppNameWithVersion() + AppDeployerUtils.getTenantIdLogString(AppDeployerUtils.getTenantId())); - for (Artifact.Dependency dependency : carbonApp.getAppConfig().getApplicationArtifact().getDependencies()) { - if (dependency.getServerRole().equals("DataServicesServer")) { - JsonObject undeployedDataService = createUpdatedDataServiceInfoObject(dependency); - ArtifactDeploymentListener.addToUndeployedArtifactsQueue(undeployedDataService); - } - } - JsonObject undeployedCarbonApp = createUpdatedCappInfoObject(carbonApp); - ArtifactDeploymentListener.addToUndeployedArtifactsQueue(undeployedCarbonApp); } catch (Exception e) { log.error("Error occurred while trying to unDeploy : " + carbonApp.getAppNameWithVersion(), e); } } - private JsonObject createUpdatedCappInfoObject(CarbonApplication capp) { - JsonObject cappInfo = new JsonObject(); - cappInfo.addProperty("type", "applications"); - cappInfo.addProperty("name", capp.getAppName()); - cappInfo.addProperty("version", capp.getAppVersion()); - return cappInfo; - } - - private JsonObject createUpdatedDataServiceInfoObject(Artifact.Dependency dataService) { - JsonObject dataServiceInfo = new JsonObject(); - dataServiceInfo.addProperty("type", "data-services"); - dataServiceInfo.addProperty("name", dataService.getName()); - dataServiceInfo.addProperty("version", dataService.getVersion()); - return dataServiceInfo; - } - /** * Remove a carbon application from cAppMap. * diff --git a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/synapse/deployer/SynapseAppDeployer.java b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/synapse/deployer/SynapseAppDeployer.java index 3423b15096..1a127dc753 100644 --- a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/synapse/deployer/SynapseAppDeployer.java +++ b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/synapse/deployer/SynapseAppDeployer.java @@ -78,7 +78,6 @@ import org.wso2.micro.integrator.core.util.MicroIntegratorBaseUtils; import org.wso2.micro.integrator.initializer.ServiceBusConstants; import org.wso2.micro.integrator.initializer.ServiceBusUtils; -import org.wso2.micro.integrator.initializer.dashboard.ArtifactDeploymentListener; import org.wso2.micro.integrator.initializer.persistence.MediationPersistenceManager; import org.wso2.micro.integrator.initializer.utils.ConfigurationHolder; import org.wso2.micro.integrator.initializer.utils.DeployerUtil; @@ -326,9 +325,6 @@ && handleMainFaultSeqUndeployment(artifact, axisConfig)) { log.error("Error occured while trying to un deploy : "+ artifactName); } } - - JsonObject undeployedArtifact = createUpdatedArtifactInfoObject(artifact, artifactPath, false); - ArtifactDeploymentListener.addToUndeployedArtifactsQueue(undeployedArtifact); } } @@ -1145,10 +1141,6 @@ public void deployArtifactType(List artifacts, CarbonApplic } } } - - JsonObject deployedArtifact = createUpdatedArtifactInfoObject(artifact, artifactPath, true); - ArtifactDeploymentListener.addToDeployedArtifactsQueue(deployedArtifact); - } } @@ -1303,25 +1295,6 @@ private void registerSynapseDeployer(AxisConfiguration axisConfig, String artifa } } - private JsonObject createUpdatedArtifactInfoObject(Artifact artifact, String artifactPath, boolean isDeploy) { - JsonObject artifactInfo = new JsonObject(); - String type = getArtifactDirName(artifact.getType()); - String name = artifact.getName(); - if ("api".equals(type)) { - type = "apis"; - } else if ("synapse-libs".equals(type)) { - type = "connectors"; - name = getConnectorName(name); - } - if (isDeploy && "templates".equals(type)) { - name = getTemplateName(artifactPath, name); - } - artifactInfo.addProperty("type", type); - artifactInfo.addProperty("name", name); - artifactInfo.addProperty("version", artifact.getVersion()); - return artifactInfo; - } - private String getConnectorName(String artifactName) { return artifactName.substring(0, artifactName.lastIndexOf("-connector")); }