1 23 24 package com.sun.enterprise.cli.commands; 25 26 import com.sun.enterprise.cli.framework.*; 27 28 import com.sun.enterprise.deployment.util.DeploymentProperties; 29 import com.sun.enterprise.deployment.client.DeploymentFacility; 30 import com.sun.enterprise.deployment.client.ServerConnectionIdentifier; 31 import com.sun.enterprise.deployment.client.DeploymentFacilityFactory; 32 import com.sun.enterprise.deployment.client.JESTarget; 33 import com.sun.enterprise.deployment.client.JESProgressObject; 34 import com.sun.enterprise.deployment.backend.DeploymentStatus; 35 import javax.enterprise.deploy.spi.Target ; 36 import com.sun.enterprise.server.Constants; 37 38 import java.io.*; 40 import java.util.Iterator ; 41 import java.util.Map ; 42 import java.util.Properties ; 43 44 45 49 public class UndeployCommand extends S1ASCommand 50 { 51 private static final String CASCADE_OPTION = "cascade"; 52 private static final String DROPTABLES_OPTION = "droptables"; 53 private static final String TARGET_OPTION = "target"; 54 55 59 public void runCommand() 60 throws CommandException, CommandValidationException 61 { 62 validateOptions(); 63 64 DeploymentFacility df = DeploymentFacilityFactory.getDeploymentFacility(); 65 ServerConnectionIdentifier conn = createServerConnectionIdentifier( 66 getHost(), getPort(), getUser(), getPassword()); 67 df.connect(conn); 68 69 final String targetName = getOption(TARGET_OPTION); 72 Map deployOptions = createDeploymentProperties(); 74 75 JESProgressObject progressObject = null; 76 77 try 78 { 79 if (df.isConnected()) 80 { 81 CLILogger.getInstance().printDebugMessage("Calling the undeploy with DeployOptions"); 82 Target[] targets = df.createTargets(new String []{targetName}); 83 if (targets == null) 84 { 85 throw new CommandException(getLocalizedString("InvalidTarget", new Object [] {targetName})); 87 } 88 89 progressObject = df.undeploy(targets, getComponentName(), deployOptions); 90 } else 91 { 92 CLILogger.getInstance().printError( 93 getLocalizedString("CouldNotConnectToDAS")); 94 } 95 } 96 catch (Exception e) 97 { 98 if (e.getLocalizedMessage() != null) 99 CLILogger.getInstance().printDetailMessage( 100 e.getLocalizedMessage()); 101 102 throw new CommandException(getLocalizedString( 103 "CommandUnSuccessful", new Object [] {name} ), e); 104 } 105 106 DeploymentStatus status = df.waitFor(progressObject); 107 final String statusString = status.getStageStatusMessage(); 108 109 110 if (status != null && 111 status.getStatus() == DeploymentStatus.FAILURE) { 112 throw new CommandException(getLocalizedString( 113 "CommandUnSuccessfulWithMsg", new Object [] {name, 114 statusString} )); 115 } else if (status != null && 116 status.getStatus() == DeploymentStatus.WARNING) { 117 CLILogger.getInstance().printDetailMessage(getLocalizedString( 118 "CommandSuccessfulWithMsg", 119 new Object [] {name, statusString})); 120 } else { 121 CLILogger.getInstance().printDetailMessage(getLocalizedString( 122 "CommandSuccessful", new Object [] {name} )); 123 } 124 125 } 126 127 128 135 public boolean validateOptions() throws CommandValidationException 136 { 137 return super.validateOptions(); 138 } 139 140 141 145 private String getComponentName() 146 { 147 return (String ) getOperands().get(0); 148 } 149 150 151 155 private Map createDeploymentProperties() 156 { 157 Properties props = new Properties(); 158 final String cascadeOption = getOption(CASCADE_OPTION); 159 final String dropTablesOption = getOption(DROPTABLES_OPTION); 160 final String target = getOption(TARGET_OPTION); 161 162 if (props != null) 163 props.put(DeploymentProperties.TARGET, target); 164 165 props.put(DeploymentProperties.NAME, getComponentName() ); 166 167 if (cascadeOption != null) 168 props.put(DeploymentProperties.CASCADE, cascadeOption); 169 if (dropTablesOption != null) 170 props.put(Constants.CMP_DROP_TABLES, dropTablesOption); 171 return props; 172 } 173 174 175 } 176 | Popular Tags |