Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added observer methods to react on vfs synchronization events to deploy/... #23

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import org.uberfire.backend.deployment.DeploymentConfigService;

import org.kie.workbench.common.services.shared.builder.model.DeployResult;
import org.uberfire.backend.server.config.Added;
import org.uberfire.backend.server.config.Removed;
import org.uberfire.backend.server.deployment.DeploymentConfigChangedEvent;

@Service
@ApplicationScoped
Expand Down Expand Up @@ -72,11 +75,13 @@ public void deploy(DeploymentUnitSummary unitSummary) {
((KModuleDeploymentUnitSummary) unitSummary).getKbaseName(),
((KModuleDeploymentUnitSummary) unitSummary).getKsessionName());
}// add for vfs
deploy(unit);
}

protected void deploy(DeploymentUnit unit) {
if (deploymentService.getDeployedUnit(unit.getIdentifier()) == null) {
deploymentService.deploy(unit);
}

}

@Override
Expand All @@ -89,15 +94,19 @@ public void undeploy(DeploymentUnitSummary unitSummary) {
((KModuleDeploymentUnitSummary) unitSummary).getKbaseName(),
((KModuleDeploymentUnitSummary) unitSummary).getKsessionName());
}// add for vfs
undeploy(unit);
}

protected void undeploy(DeploymentUnit unit) {
try {
if (deploymentService.getDeployedUnit(unit.getIdentifier()) != null) {
deploymentService.undeploy(unit);
cleanup(unit.getIdentifier());
}
} catch (IllegalStateException e) {
throw new DeploymentException(e.getMessage(), e);
}
}


@Override
public void redeploy() {
Expand Down Expand Up @@ -130,30 +139,45 @@ public boolean accept(File dir, String name) {
}
}

@Override
public List<KModuleDeploymentUnitSummary> getDeploymentUnits() {
Collection<DeployedUnit> deployedUnits = deploymentService.getDeployedUnits();
List<KModuleDeploymentUnitSummary> unitsIds = new ArrayList<KModuleDeploymentUnitSummary>(deployedUnits.size());
for (DeployedUnit du : deployedUnits) {
KModuleDeploymentUnit kdu = (KModuleDeploymentUnit)du.getDeploymentUnit();
KModuleDeploymentUnitSummary duSummary = new KModuleDeploymentUnitSummary(kdu.getIdentifier(), kdu.getGroupId(),
kdu.getArtifactId(), kdu.getVersion(), kdu.getKbaseName(), kdu.getKsessionName());
unitsIds.add(duSummary);

}
return unitsIds;
}

/**
* Reacts on events fired by deployment service upon successful deployment to runtime environment so that can be stored in
* system repository
* @param event deploymentEvent that holds all required information from runtime point of view
*/
public void saveDeployment(@Observes @Deploy DeploymentEvent event) {
if (deploymentConfigService.getDeployment(event.getDeploymentId()) == null) {
deploymentConfigService.addDeployment(event.getDeploymentId(), event.getDeployedUnit().getDeploymentUnit());
}
}

/**
* Reacts on events fired by deployment service upon successful undeployment from runtime environment
* so that can be stored in system repository
* @param event deploymentEvent that holds all required information from runtime point of view
*/
public void removeDeployment(@Observes @Undeploy DeploymentEvent event) {
deploymentConfigService.removeDeployment(event.getDeploymentId());
}

@Override
public List<KModuleDeploymentUnitSummary> getDeploymentUnits() {
Collection<DeployedUnit> deployedUnits = deploymentService.getDeployedUnits();
List<KModuleDeploymentUnitSummary> unitsIds = new ArrayList<KModuleDeploymentUnitSummary>(deployedUnits.size());
for (DeployedUnit du : deployedUnits) {
KModuleDeploymentUnit kdu = (KModuleDeploymentUnit)du.getDeploymentUnit();
KModuleDeploymentUnitSummary duSummary = new KModuleDeploymentUnitSummary(kdu.getIdentifier(), kdu.getGroupId(),
kdu.getArtifactId(), kdu.getVersion(), kdu.getKbaseName(), kdu.getKsessionName());
unitsIds.add(duSummary);

}
return unitsIds;
}

/**
* Auto deployed reacts to events fired from authoring environment after successful build and deploy (to maven)
* @param result Maven deploy result that holds GAV to construct KModuleDeploymentUnit
*/
public void autoDeploy(@Observes DeployResult result) {
try {
KModuleDeploymentUnitSummary unit = new KModuleDeploymentUnitSummary("",
Expand All @@ -169,4 +193,22 @@ public void autoDeploy(@Observes DeployResult result) {
e.printStackTrace();
}
}

/**
* Reacts on events fired based on changes to system repository - important in cluster environment
* where system repo will ny synchronized
* @param event - event that carries the complete DeploymentUnit to be undeployed
*/
public void undeployOnEvent(@Observes @Removed DeploymentConfigChangedEvent event) {
undeploy((DeploymentUnit) event.getDeploymentUnit());
}

/**
* Reacts on events fired based on changes to system repository - important in cluster environment
* where system repo will ny synchronized
* @param event - event that carries the complete DeploymentUnit to be deployed
*/
public void deployOnEvent(@Observes @Added DeploymentConfigChangedEvent event) {
deploy((DeploymentUnit) event.getDeploymentUnit());
}
}