public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); final List<byte[]> removedHashes = DeploymentUtils.getDeploymentHash(resource); final ModelNode model = context.readModel(PathAddress.EMPTY_ADDRESS); context.removeResource(PathAddress.EMPTY_ADDRESS); if (context.getType() == OperationContext.Type.SERVER) { context.addStep( new OperationStepHandler() { public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { String deploymentUnitName = null; boolean enabled = model.hasDefined(ENABLED) ? model.get(ENABLED).asBoolean() : true; if (enabled) { final ModelNode opAddr = operation.get(OP_ADDR); final PathAddress address = PathAddress.pathAddress(opAddr); final String name = address.getLastElement().getValue(); deploymentUnitName = model.hasDefined(RUNTIME_NAME) ? model.get(RUNTIME_NAME).asString() : name; final ServiceName deploymentUnitServiceName = Services.deploymentUnitName(deploymentUnitName); context.removeService(deploymentUnitServiceName); context.removeService(deploymentUnitServiceName.append("contents")); } if (context.completeStep() == OperationContext.ResultAction.ROLLBACK) { recoverServices(context, operation, model); if (enabled && context.hasFailureDescription()) { ServerLogger.ROOT_LOGGER.undeploymentRolledBack( deploymentUnitName, context.getFailureDescription().asString()); } else if (enabled) { ServerLogger.ROOT_LOGGER.undeploymentRolledBackWithNoMessage(deploymentUnitName); } } else { if (enabled) { ServerLogger.ROOT_LOGGER.deploymentUndeployed(deploymentUnitName); } if (standalone) { for (byte[] hash : removedHashes) { try { contentRepository.removeContent(hash); } catch (Exception e) { // TODO log.infof(e, "Exception occurred removing %s", hash); } } } } } }, OperationContext.Stage.RUNTIME); } context.completeStep(); }
private void initLogstash(String testName) { initLogstashHost(); String pathToLogstash = SGTestHelper.getSGTestRootDir().replace("\\", "/") + "/src/main/resources/logstash"; String confFilePath = pathToLogstash + "/logstash-shipper-client.conf"; String fixedTestName = testName.substring(0, testName.length() - 2); String backupFilePath = pathToLogstash + "/logstash-shipper-client-" + fixedTestName + ".conf"; if (process == null) { try { LogUtils.log("copying file " + confFilePath + " to " + backupFilePath); IOUtils.copyFile(confFilePath, backupFilePath); // backupFilePath = IOUtils.backupFile(confFilePath); IOUtils.replaceTextInFile( backupFilePath, "<path_to_test_folder>", SGTestHelper.getSGTestRootDir().replace("\\", "/") + "/../" + suiteName + "/" + testName); IOUtils.replaceTextInFile(backupFilePath, "<suite_name>", suiteName); IOUtils.replaceTextInFile(backupFilePath, "<test_name>", testName); IOUtils.replaceTextInFile(backupFilePath, "<build_number>", buildNumber); IOUtils.replaceTextInFile(backupFilePath, "<version>", version); IOUtils.replaceTextInFile(backupFilePath, "<host>", logstashHost); String logstashJarPath = DeploymentUtils.getLocalRepository() + "net/logstash/1.2.2/logstash-1.2.2.jar"; logstashLogPath = pathToLogstash + "/logstash-" + fixedTestName + ".txt"; String cmdLine = "java -jar " + logstashJarPath + " agent -f " + backupFilePath + " -l " + logstashLogPath; final String[] parts = cmdLine.split(" "); final ProcessBuilder pb = new ProcessBuilder(parts); LogUtils.log("Executing Command line: " + cmdLine); TimeUnit.SECONDS.sleep(1); process = pb.start(); } catch (Exception e) { e.printStackTrace(); } } }
private void initLogstash2(ITestResult tr) { initLogstashHost(); String simpleClassName = tr.getTestClass().getRealClass().getSimpleName(); String pathToLogstash = SGTestHelper.getSGTestRootDir().replace("\\", "/") + "/src/main/resources/logstash"; String confFilePath2 = pathToLogstash + "/logstash-shipper-client-2.conf"; String backupFilePath2 = pathToLogstash + "/logstash-shipper-client-2-" + simpleClassName + ".conf"; File backupFile2 = new File(backupFilePath2); LogUtils.log( "trying to start logstash agent number 2. simple class name is " + simpleClassName); if (backupFile2.exists()) { LogUtils.log("the file " + backupFilePath2 + " already exists. not starting logstash"); } if (!isAfter(tr) && !backupFile2.exists()) { try { // backupFilePath2 = IOUtils.backupFile(confFilePath2); LogUtils.log("copying file " + confFilePath2 + " to " + backupFilePath2); IOUtils.copyFile(confFilePath2, backupFilePath2); IOUtils.replaceTextInFile(backupFilePath2, "<path_to_build>", SGTestHelper.getBuildDir()); IOUtils.replaceTextInFile( backupFilePath2, "<suite_number>", "suite_" + System.getProperty("iTests.suiteId", "0")); IOUtils.replaceTextInFile( backupFilePath2, "<path_to_test_class_folder>", SGTestHelper.getSGTestRootDir().replace("\\", "/") + "/../" + suiteName + "/" + tr.getTestClass().getName()); IOUtils.replaceTextInFile(backupFilePath2, "<suite_name>", suiteName); IOUtils.replaceTextInFile(backupFilePath2, "<test_name>", simpleClassName); IOUtils.replaceTextInFile(backupFilePath2, "<build_number>", buildNumber); IOUtils.replaceTextInFile(backupFilePath2, "<version>", version); IOUtils.replaceTextInFile(backupFilePath2, "<host>", logstashHost); String logstashJarPath = DeploymentUtils.getLocalRepository() + "net/logstash/1.2.2/logstash-1.2.2.jar"; logstashLogPath2 = pathToLogstash + "/logstash-" + simpleClassName + "-2.txt"; String cmdLine = "java -jar " + logstashJarPath + " agent -f " + backupFilePath2 + " -l " + logstashLogPath2; final String[] parts = cmdLine.split(" "); final ProcessBuilder pb = new ProcessBuilder(parts); LogUtils.log("Executing Command line: " + cmdLine); process2 = pb.start(); } catch (IOException e) { e.printStackTrace(); } } }