protected DeploymentUnit createAndDeployUnit(String groupId, String artifactid, String version) throws Exception { List<String> processes = getProcessDefinitionFiles(); if (processes!= null && !processes.isEmpty()) { KieServices ks = KieServices.Factory.get(); ReleaseId releaseId = ks.newReleaseId(groupId, artifactid, version); InternalKieModule kJar1 = createKieJar(ks, releaseId, processes); File pom = new File("target/kmodule", "pom.xml"); pom.getParentFile().mkdir(); FileOutputStream fs = new FileOutputStream(pom); fs.write(getPom(releaseId).getBytes()); fs.close(); KieMavenRepository repository = getKieMavenRepository(); repository.deployArtifact(releaseId, kJar1, pom); DeploymentUnit deploymentUnit = createDeploymentUnit(groupId, artifactid, version); deploymentService.deploy(deploymentUnit); return deploymentUnit; } return null; }
@Override public void redeploy() { for (DeploymentUnit unit : deploymentUnits) { if (deploymentService.getDeployedUnit(unit.getIdentifier()) != null) { deploymentService.undeploy(unit); } deploymentService.deploy(unit); } }
@Override public void activateContainer(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) { deploymentService.activate(id); }
@RequestMapping(value="/undeploy", method=RequestMethod.POST) public String undeploy(@RequestParam("id")String id) { String outcome = ""; DeployedUnit deployed = deploymentService.getDeployedUnit(id); if (deployed != null) { deploymentService.undeploy(deployed.getDeploymentUnit()); outcome = "Deployment " + id + " undeployed successfully"; } else { outcome = "No deployment " + id + " found"; } return outcome; } }
@Override public void initDeployments(Set<DeploymentUnit> deploymentUnits) { for (DeploymentUnit unit : deploymentUnits) { if (deploymentService.getDeployedUnit(unit.getIdentifier()) == null) { try { if ("true".equals(System.getProperty("org.kie.clean.onstartup"))) { cleanup(unit.getIdentifier()); } deploymentService.deploy(unit); } catch (Exception e) { logger.warn("Error when deploying unit {} error message {}", unit, e.getMessage()); logger.debug("Stacktrace:", e); } } } }
@Test public void testSupportProcess() { DeploymentUnit deploymentUnitSupport = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION); deploymentService.deploy(deploymentUnitSupport); units.add(deploymentUnitSupport); params.put("customer", "polymita"); RuntimeManager managerSupport = deploymentService.getRuntimeManager(deploymentUnitSupport.getIdentifier()); assertNotNull(managerSupport); assertEquals(0, currentNumberOfEvents); RuntimeEngine engine = managerSupport.getRuntimeEngine(EmptyContext.get()); assertNotNull(engine); ProcessInstance pI = engine.getKieSession().startProcess("support.process", params); assertNotNull(pI); TaskService taskService = engine.getTaskService();
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = TestConfig.class, loader = AnnotationConfigContextLoader.class) public class JunitTest { @Configuration @ComponentScan(basePackages = { "de.foo }) public static class TestMConfig { @Autowired private DeploymentService service; @PostConstruct public void init() { service.deploy(...); } } @Test public void test() { ... } }
/** * Test coverage for BZ-1171810. */ @Test public void testDuplicateDeployment() { // pretend any deployment unit is deployed when(deploymentService.isDeployed(anyString())).thenReturn(true); // process a successful build result GAV gav = new GAV("g:a:1"); BuildResults result = new BuildResults(gav); deploymentManager.process(result); // deployment unit with the build result GAV must not be deployed (it has already been deployed) verify(deploymentService, atLeast(1)).isDeployed("g:a:1"); verify(deploymentService, never()).undeploy(any(DeploymentUnit.class)); verify(deploymentService, never()).deploy(any(DeploymentUnit.class)); // check error messages added to the build result assertNotEquals(0, result.getErrorMessages().size()); for (BuildMessage msg : result.getErrorMessages()) { assertTrue(msg.getText(), msg.getText().contains("already deployed")); } } }
@Override public void disposeContainer(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) { if (!deploymentService.isDeployed(id)) { logger.info("No container with id {} found", id); return; states.add(ProcessInstance.STATE_SUSPENDED); KModuleDeploymentUnit unit = (KModuleDeploymentUnit) deploymentService.getDeployedUnit(id).getDeploymentUnit(); deploymentService.undeploy(new CustomIdKmoduleDeploymentUnit(id, unit.getGroupId(), unit.getArtifactId(), unit.getVersion()));
@SuppressWarnings("unchecked") @Override public void createContainer(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) { if (!initialized) { return; } List<Message> messages = (List<Message>) parameters.get(KieServerConstants.KIE_SERVER_PARAM_MESSAGES); try { DeployedUnit deployedUnit = deploymentService.getDeployedUnit(id); if(deployedUnit != null) { String kieBaseName = ((KModuleDeploymentUnit)deployedUnit.getDeploymentUnit()).getKbaseName(); KieContainer kieContainer = kieContainerInstance.getKieContainer(); imageReferences.putIfAbsent(id, new ImageReference(kieContainer, kieBaseName)); formRendererBase.indexDeploymentForms(id); } } catch (Exception e) { messages.add(new Message(Severity.WARN, "Unable to create image reference for container " + id +" by extension " + this + " due to " + e.getMessage())); logger.warn("Unable to create image reference for container {} due to {}", id, e.getMessage(), e); } }
buildResults.getGAV().getArtifactId(), buildResults.getGAV().getVersion(), "", "", null, null); if(!deploymentService.isDeployed(id) || (deploymentService.isDeployed(id) && overrideDeploymentsEnabled) || id.contains("SNAPSHOT")){ undeploy(unit);
@RequestMapping("/") public Collection<String> index() { Collection<DeployedUnit> deployed = deploymentService.getDeployedUnits(); Collection<String> units = new ArrayList<String>(); for (DeployedUnit dUnit : deployed) { units.add(dUnit.getDeploymentUnit().getIdentifier()); } return units; }
@Override public void deactivateContainer(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) { deploymentService.deactivate(id); }
@RequestMapping(value="/deploy", method=RequestMethod.POST) public String deploy(@RequestParam("id")String id, @RequestParam(value="strategy", defaultValue="SINGLETON") String strategy) { String outcome = "Deployment " + id + " deployed successfully"; String[] gav = id.split(":"); KModuleDeploymentUnit unit = new KModuleDeploymentUnit(gav[0], gav[1], gav[2], null, null, strategy); deploymentService.deploy(unit); return outcome; }
protected boolean deploy(DeploymentUnit unit) { if (deploymentService.getDeployedUnit(unit.getIdentifier()) == null) { String[] gavElemes = unit.getIdentifier().split(":"); GAV gav = new GAV(gavElemes[0], gavElemes[1], gavElemes[2]); BuildResults buildResults = new BuildResults(gav); try { deploymentService.deploy(unit); return true; } catch (Exception e) { BuildMessage message = new BuildMessage(); message.setLevel(Level.ERROR); message.setText("Deployment of unit " + gav + " failed: " + e.getMessage()); logger.warn("Deployment of unit " + gav + " failed: " + e.getMessage(), e); buildResults.addBuildMessage(message); throw new DeploymentException(e.getMessage(), e); } finally { buildResultsEvent.fire(buildResults); } } return false; }
protected void undeploy(DeploymentUnit unit) { String[] gavElemes = unit.getIdentifier().split(":"); GAV gav = new GAV(gavElemes[0], gavElemes[1], gavElemes[2]); BuildResults buildResults = new BuildResults(gav); try { if (deploymentService.getDeployedUnit(unit.getIdentifier()) != null) { deploymentService.undeploy(unit); cleanup(unit.getIdentifier()); } } catch (Exception e) { BuildMessage message = new BuildMessage(); message.setLevel(Level.ERROR); message.setText("Undeployment of unit " + gav + " failed: " + e.getMessage()); logger.warn("Undeployment of unit " + gav + " failed: " + e.getMessage(), e); buildResults.addBuildMessage(message); throw new DeploymentException(e.getMessage(), e); } finally { buildResultsEvent.fire(buildResults); } }
DeployedUnit deployedUnit = deployment.getDeployedUnit(identifier); if (deployedUnit == null) { return handlers;
@Override public void deploy(DeploymentUnitSummary unitSummary) { DeploymentUnit unit = null; if(!deploymentService.isDeployed(unitSummary.getId()) || (deploymentService.isDeployed(unitSummary.getId()) && overrideDeploymentsEnabled) || unitSummary.getId().contains("SNAPSHOT")){ if (unitSummary.getType().equals("kjar")) {