Skip to content

Commit

Permalink
Merge pull request #3314 from dulanjalidilmi/userstore-v1
Browse files Browse the repository at this point in the history
Remove change notification from heartbeat request
  • Loading branch information
dulanjalidilmi authored Jun 13, 2024
2 parents 75a93e4 + 73d2f47 commit fa83908
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 231 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -74,10 +70,6 @@ private HeartBeatComponent(){
private static final Log log = LogFactory.getLog(HeartBeatComponent.class);
private static final Map<String, Object> 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";
Expand All @@ -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(
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -1145,10 +1141,6 @@ public void deployArtifactType(List<Artifact.Dependency> artifacts, CarbonApplic
}
}
}

JsonObject deployedArtifact = createUpdatedArtifactInfoObject(artifact, artifactPath, true);
ArtifactDeploymentListener.addToDeployedArtifactsQueue(deployedArtifact);

}
}

Expand Down Expand Up @@ -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"));
}
Expand Down

0 comments on commit fa83908

Please sign in to comment.