Clover coverage report - Globus Unit Tests
Coverage timestamp: Fri Apr 13 2007 07:12:08 CDT
file stats: LOC: 223   Methods: 5
NCLOC: 156   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DeployClient.java 0% 0% 0% 0%
coverage
 1    /*
 2    * Copyright 1999-2006 University of Chicago
 3    *
 4    * Licensed under the Apache License, Version 2.0 (the "License");
 5    * you may not use this file except in compliance with the License.
 6    * You may obtain a copy of the License at
 7    *
 8    * http://www.apache.org/licenses/LICENSE-2.0
 9    *
 10    * Unless required by applicable law or agreed to in writing, software
 11    * distributed under the License is distributed on an "AS IS" BASIS,
 12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13    * See the License for the specific language governing permissions and
 14    * limitations under the License.
 15    */
 16    package org.globus.wsrf.container.deploy.client;
 17   
 18    import java.util.List;
 19    import java.util.Properties;
 20    import java.io.File;
 21   
 22    import javax.xml.rpc.Stub;
 23   
 24    import javax.activation.DataHandler;
 25    import javax.activation.FileDataSource;
 26   
 27    import org.apache.axis.client.Call;
 28   
 29    import org.apache.commons.cli.Option;
 30    import org.apache.commons.cli.OptionBuilder;
 31    import org.apache.commons.cli.CommandLine;
 32    import org.apache.commons.cli.ParseException;
 33   
 34    import org.globus.wsrf.client.BaseClient;
 35    import org.globus.wsrf.core.deploy.service.DeployServiceAddressingLocator;
 36    import org.globus.wsrf.core.deploy.DeployPortType;
 37    import org.globus.wsrf.core.deploy.DeployRequest;
 38    import org.globus.wsrf.core.deploy.DeployOptions;
 39    import org.globus.wsrf.core.deploy.TransferResponse;
 40    import org.globus.wsrf.utils.FaultHelper;
 41   
 42    /**
 43    * Client for deploy operation for DeployService.
 44    */
 45    public class DeployClient extends BaseClient {
 46   
 47    private static final Option DEPLOY_OPTION =
 48    OptionBuilder.withDescription("Perform GAR deploy only")
 49    .withLongOpt("deploy")
 50    .create("y");
 51   
 52    private static final Option TRANSFER_OPTION =
 53    OptionBuilder.withDescription("Perform GAR transfer only")
 54    .withLongOpt("transfer")
 55    .create("n");
 56   
 57    private static final Option CREATE_BACKUP =
 58    OptionBuilder.withDescription("Create backup of configuration files")
 59    .withLongOpt("backup")
 60    .create("b");
 61   
 62    private static final Option OVERWRITE_OPTION =
 63    OptionBuilder.withDescription("Overwrite existing deployment")
 64    .withLongOpt("overwrite")
 65    .create("o");
 66   
 67    private static final Option PROFILE_OPTION =
 68    OptionBuilder.withArgName( "name" )
 69    .hasArg()
 70    .withDescription("Specify configuration profile name")
 71    .withLongOpt("profile")
 72    .create("r");
 73   
 74  0 public DeployClient() {
 75  0 super();
 76  0 options.addOption(DEPLOY_OPTION);
 77  0 options.addOption(TRANSFER_OPTION);
 78  0 options.addOption(CREATE_BACKUP);
 79  0 options.addOption(OVERWRITE_OPTION);
 80  0 options.addOption(PROFILE_OPTION);
 81    }
 82   
 83  0 public static void main(String [] args) throws Exception {
 84  0 Properties defaultOptions = new Properties();
 85    // default service address
 86  0 defaultOptions.put(BaseClient.SERVICE_URL.getOpt(),
 87    "https://localhost:8443/wsrf/services/DeployService");
 88    // GSI Secure Msg (signature)
 89  0 defaultOptions.put(BaseClient.PROTECTION.getOpt(),
 90    "sig");
 91   
 92    // self authorization
 93  0 defaultOptions.put(BaseClient.AUTHZ.getOpt(),
 94    "hostSelf");
 95   
 96  0 String garFile = null;
 97  0 CommandLine line = null;
 98  0 DeployClient client = new DeployClient();
 99  0 client.setCustomUsage("gar");
 100  0 try {
 101  0 line = client.parse(args, defaultOptions);
 102  0 List options = line.getArgList();
 103  0 if (options == null || options.isEmpty()) {
 104  0 throw new ParseException("Expected gar argument");
 105    }
 106  0 garFile = (String)options.get(0);
 107   
 108  0 if (line.hasOption(DEPLOY_OPTION.getOpt()) &&
 109    line.hasOption(TRANSFER_OPTION.getOpt())) {
 110  0 throw new ParseException(DEPLOY_OPTION.getOpt() +
 111    " and " +
 112    TRANSFER_OPTION.getOpt() +
 113    " arguments are exclusive");
 114    }
 115    } catch(ParseException e) {
 116  0 System.err.println("Error: " + e.getMessage());
 117  0 System.exit(COMMAND_LINE_ERROR);
 118    } catch (Exception e) {
 119  0 System.err.println("Error: " + e.getMessage());
 120  0 System.exit(COMMAND_LINE_ERROR);
 121    }
 122   
 123  0 DeployServiceAddressingLocator locator =
 124    new DeployServiceAddressingLocator();
 125   
 126  0 DeployOptions options = new DeployOptions();
 127   
 128    //options.setPerformValidation(Boolean.FALSE);
 129   
 130    // profile name
 131  0 if (line.hasOption(PROFILE_OPTION.getOpt())) {
 132  0 options.setProfile(line.getOptionValue(PROFILE_OPTION.getOpt()));
 133    }
 134   
 135    // overwrite option
 136  0 options.setOverwrite( (line.hasOption(OVERWRITE_OPTION.getOpt())) ?
 137    Boolean.TRUE : Boolean.FALSE );
 138   
 139    // create backup
 140  0 options.setCreateBackup( (line.hasOption(CREATE_BACKUP.getOpt())) ?
 141    Boolean.TRUE : Boolean.FALSE );
 142   
 143    // always deploy only (do not undeploy first)
 144  0 options.setUndeployFirst(Boolean.FALSE);
 145   
 146  0 try {
 147  0 DeployPortType port =
 148    locator.getDeployPortTypePort(client.getEPR());
 149  0 client.setOptions((Stub)port);
 150   
 151  0 if (line.hasOption(DEPLOY_OPTION.getOpt())) {
 152  0 deploy(port, options, garFile);
 153  0 } else if (line.hasOption(TRANSFER_OPTION.getOpt())) {
 154  0 transfer(port, garFile);
 155    } else {
 156  0 String id = transfer(port, garFile);
 157  0 deploy(port, options, id);
 158    }
 159   
 160    } catch(Exception e) {
 161  0 if (client.isDebugMode()) {
 162  0 FaultHelper.printStackTrace(e);
 163    } else {
 164  0 System.err.println("GAR deploy failed: " +
 165    FaultHelper.getMessage(e));
 166    }
 167  0 System.exit(APPLICATION_ERROR);
 168    }
 169    }
 170   
 171  0 private static void deploy(DeployPortType port,
 172    DeployOptions options,
 173    String id)
 174    throws Exception {
 175  0 DeployRequest request = new DeployRequest();
 176  0 request.setID(id);
 177  0 request.setOptions(options);
 178   
 179  0 port.deploy(request);
 180   
 181  0 System.out.println("GAR was successfully deployed.");
 182    }
 183   
 184  0 private static String transfer(DeployPortType port, String garFile)
 185    throws Exception {
 186  0 String id = null;
 187  0 if (garFile.indexOf("://") == -1) {
 188  0 File fp = new File(garFile);
 189   
 190  0 DataHandler sendDH =
 191    new DataHandler(new FileDataSource(fp));
 192   
 193  0 ((Stub)port)._setProperty(
 194    Call.ATTACHMENT_ENCAPSULATION_FORMAT,
 195    Call.ATTACHMENT_ENCAPSULATION_FORMAT_MTOM);
 196   
 197  0 ((org.apache.axis.client.Stub)port).addAttachment(sendDH);
 198   
 199  0 TransferResponse upResponse = port.upload(getName(fp));
 200   
 201  0 id = upResponse.getID();
 202   
 203  0 System.out.println("Uploaded GAR ID: " + id);
 204    } else {
 205  0 TransferResponse downResponse = port.download(garFile);
 206   
 207  0 id = downResponse.getID();
 208   
 209  0 System.out.println("Downloaded GAR ID: " + id);
 210    }
 211  0 return id;
 212    }
 213   
 214  0 private static String getName(File f) {
 215  0 String name = f.getName();
 216  0 int pos = name.lastIndexOf('.');
 217  0 if (pos != -1) {
 218  0 name = name.substring(0, pos);
 219    }
 220  0 return name;
 221    }
 222   
 223    }