Program: 26557
Project: 26557
Buggy source:
/** 
 * Create a cluster to the specification
 * @param clusterSpec cluster specification
 * @param launchArgs
 * @return the exit code from the operation
 */
public int executeClusterStart(Path clusterDirectory,ClusterDescription clusterSpec,LaunchArgsAccessor launchArgs) throws YarnException, IOException {
  String clustername=clusterSpec.name;
  deployedClusterName=clustername;
  HoyaUtils.validateClusterName(clustername);
  verifyNoLiveClusters(clustername);
  Configuration config=getConfig();
  boolean clusterSecure=HoyaUtils.isClusterSecure(config);
  HoyaAMClientProvider hoyaAM=new HoyaAMClientProvider(config);
  ClientProvider provider=createClientProvider(clusterSpec);
  Path generatedConfDirPath=createPathThatMustExist(clusterSpec.generatedConfigurationPath);
  Path origConfPath=createPathThatMustExist(clusterSpec.originConfigurationPath);
  Path imagePath;
  String csip=clusterSpec.getImagePath();
  if (!isUnset(csip)) {
    imagePath=createPathThatMustExist(csip);
  }
 else {
    imagePath=null;
    if (isUnset(clusterSpec.getApplicationHome())) {
      throw new BadClusterStateException("String_Node_Str");
    }
  }
  hoyaAM.validateClusterSpec(clusterSpec);
  provider.validateClusterSpec(clusterSpec);
  if (log.isDebugEnabled()) {
    log.debug(clusterSpec.toString());
  }
  YarnClientApplication application=yarnClient.createApplication();
  ApplicationSubmissionContext appContext=application.getApplicationSubmissionContext();
  ApplicationId appId=appContext.getApplicationId();
  appContext.setApplicationName(clustername);
  appContext.setApplicationType(HoyaKeys.APP_TYPE);
  if (clusterSpec.getOptionBool(OptionKeys.HOYA_TEST_FLAG,false)) {
    appContext.setMaxAppAttempts(1);
  }
  FileSystem fs=getClusterFS();
  HoyaUtils.purgeHoyaAppInstanceTempFiles(fs,clustername);
  Path tempPath=HoyaUtils.createHoyaAppInstanceTempPath(fs,clustername,appId.toString());
  String libdir="String_Node_Str";
  Path libPath=new Path(tempPath,libdir);
  fs.mkdirs(libPath);
  log.debug("String_Node_Str",fs,tempPath,libPath);
  ContainerLaunchContext amContainer=Records.newRecord(ContainerLaunchContext.class);
  Map<String,LocalResource> localResources=new HashMap<String,LocalResource>();
  Path remoteHoyaConfPath=null;
  String relativeHoyaConfDir=null;
  String hoyaConfdirProp=System.getProperty(HoyaKeys.PROPERTY_HOYA_CONF_DIR);
  if (hoyaConfdirProp == null || hoyaConfdirProp.isEmpty()) {
    log.debug("String_Node_Str");
  }
 else {
    File hoyaConfDir=new File(hoyaConfdirProp);
    if (!hoyaConfDir.exists()) {
      throw new BadConfigException("String_Node_Str",hoyaConfDir);
    }
    Path localConfDirPath=HoyaUtils.createLocalPath(hoyaConfDir);
    log.debug("String_Node_Str",localConfDirPath);
    remoteHoyaConfPath=new Path(clusterDirectory,HoyaKeys.SUBMITTED_HOYA_CONF_DIR);
    HoyaUtils.copyDirectory(config,localConfDirPath,remoteHoyaConfPath);
  }
  if (!getUsingMiniMRCluster()) {
    log.debug("String_Node_Str");
    if (remoteHoyaConfPath != null) {
      relativeHoyaConfDir=HoyaKeys.SUBMITTED_HOYA_CONF_DIR;
      Map<String,LocalResource> submittedConfDir=HoyaUtils.submitDirectory(fs,remoteHoyaConfPath,relativeHoyaConfDir);
      HoyaUtils.mergeMaps(localResources,submittedConfDir);
    }
    log.info("String_Node_Str");
    HoyaUtils.putJar(localResources,fs,this.getClass(),tempPath,libdir,HOYA_JAR);
  }
  propagatePrincipals(clusterSpec,config);
  Configuration clientConfExtras=new Configuration(false);
  Map<String,LocalResource> providerResources;
  providerResources=hoyaAM.prepareAMAndConfigForLaunch(fs,config,clusterSpec,origConfPath,generatedConfDirPath,clientConfExtras,libdir,tempPath);
  localResources.putAll(providerResources);
  providerResources=provider.prepareAMAndConfigForLaunch(fs,config,clusterSpec,origConfPath,generatedConfDirPath,clientConfExtras,libdir,tempPath);
  localResources.putAll(providerResources);
  log.debug("String_Node_Str");
  provider.preflightValidateClusterConfiguration(clusterSpec,fs,generatedConfDirPath,clusterSecure);
  if (HoyaUtils.maybeAddImagePath(fs,localResources,imagePath)) {
    log.debug("String_Node_Str",imagePath);
  }
  if (log.isDebugEnabled()) {
    for (    String key : localResources.keySet()) {
      LocalResource val=localResources.get(key);
      log.debug("String_Node_Str",key,HoyaUtils.stringify(val.getResource()));
    }
  }
  amContainer.setLocalResources(localResources);
  Map<String,String> env=HoyaUtils.buildEnvMap(clusterSpec.getOrAddRole(HoyaKeys.ROLE_HOYA_AM));
  String classpath=HoyaUtils.buildClasspath(relativeHoyaConfDir,libdir,getConfig(),getUsingMiniMRCluster());
  env.put("String_Node_Str",classpath);
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str",classpath);
    log.debug("String_Node_Str",HoyaUtils.stringifyMap(env));
    log.debug("String_Node_Str",HoyaUtils.listFSDir(fs,libPath));
  }
  amContainer.setEnvironment(env);
  String rmAddr=launchArgs.getRmAddress();
  if (isUnset(rmAddr) && HoyaUtils.isRmSchedulerAddressDefined(config)) {
    rmAddr=NetUtils.getHostPortString(HoyaUtils.getRmSchedulerAddress(config));
  }
  List<String> commands=new ArrayList<String>(20);
  commands.add(ApplicationConstants.Environment.JAVA_HOME.$() + "String_Node_Str");
  hoyaAM.addJVMOptions(clusterSpec,commands);
  if (serviceArgs.isDebug()) {
    commands.add(HoyaKeys.JVM_ENABLE_ASSERTIONS);
    commands.add(HoyaKeys.JVM_ENABLE_SYSTEM_ASSERTIONS);
  }
  commands.add(String.format(HoyaKeys.FORMAT_D_CLUSTER_NAME,clustername));
  commands.add(String.format(HoyaKeys.FORMAT_D_CLUSTER_TYPE,provider.getName()));
  commands.add(HoyaAMArgs.CLASSNAME);
  commands.add(HoyaActions.ACTION_CREATE);
  commands.add(clustername);
  if (serviceArgs.isDebug()) {
    commands.add(Arguments.ARG_DEBUG);
  }
  commands.add(Arguments.ARG_HOYA_CLUSTER_URI);
  commands.add(clusterDirectory.toUri().toString());
  if (!isUnset(rmAddr)) {
    commands.add(Arguments.ARG_RM_ADDR);
    commands.add(rmAddr);
  }
  if (serviceArgs.getFilesystemURL() != null) {
    commands.add(Arguments.ARG_FILESYSTEM);
    commands.add(serviceArgs.getFilesystemURL().toString());
  }
  if (clusterSecure) {
    propagateConfOption(commands,config,HoyaXmlConfKeys.KEY_HOYA_SECURITY_ENABLED);
    propagateConfOption(commands,config,DFSConfigKeys.DFS_NAMENODE_USER_NAME_KEY);
    Credentials credentials=new Credentials();
    String tokenRenewer=config.get(YarnConfiguration.RM_PRINCIPAL);
    if (isUnset(tokenRenewer)) {
      throw new BadConfigException("String_Node_Str",YarnConfiguration.RM_PRINCIPAL);
    }
    final Token<?>[] tokens=fs.addDelegationTokens(tokenRenewer,credentials);
    if (tokens != null) {
      for (      Token<?> token : tokens) {
        log.debug("String_Node_Str",fs.getUri(),token);
      }
    }
    DataOutputBuffer dob=new DataOutputBuffer();
    credentials.writeTokenStorageToStream(dob);
    ByteBuffer fsTokens=ByteBuffer.wrap(dob.getData(),0,dob.getLength());
    amContainer.setTokens(fsTokens);
  }
  commands.add("String_Node_Str" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "String_Node_Str"+ STDOUT_HOYAAM);
  commands.add("String_Node_Str" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "String_Node_Str"+ STDERR_HOYAAM);
  String cmdStr=HoyaUtils.join(commands,"String_Node_Str");
  log.info("String_Node_Str",cmdStr);
  amContainer.setCommands(commands);
  Resource capability=Records.newRecord(Resource.class);
  capability.setMemory(RoleKeys.DEFAULT_AM_MEMORY);
  capability.setVirtualCores(RoleKeys.DEFAULT_AM_V_CORES);
  hoyaAM.prepareAMResourceRequirements(clusterSpec,capability);
  appContext.setResource(capability);
  Map<String,ByteBuffer> serviceData=new HashMap<String,ByteBuffer>();
  provider.prepareAMServiceData(clusterSpec,serviceData);
  amContainer.setServiceData(serviceData);
  appContext.setAMContainerSpec(amContainer);
  Priority pri=Records.newRecord(Priority.class);
  pri.setPriority(amPriority);
  appContext.setPriority(pri);
  appContext.setQueue(amQueue);
  log.info("String_Node_Str");
  applicationId=yarnClient.submitApplication(appContext);
  int exitCode;
  ApplicationReport report=monitorAppToState(new Duration(ACCEPT_TIME),YarnApplicationState.ACCEPTED);
  if (HoyaUtils.hasAppFinished(report)) {
    exitCode=buildExitCode(appId,report);
  }
 else {
    exitCode=EXIT_SUCCESS;
    int waittime=launchArgs.getWaittime();
    if (waittime != 0) {
      Duration duration=new Duration(waittime * 1000);
      duration.start();
      report=monitorAppToState(duration,YarnApplicationState.RUNNING);
      if (report != null && report.getYarnApplicationState() == YarnApplicationState.RUNNING) {
        exitCode=EXIT_SUCCESS;
      }
 else {
        yarnClient.killRunningApplication(appId,"String_Node_Str");
        exitCode=buildExitCode(appId,report);
      }
    }
  }
  return exitCode;
}

Fixed version (ground truth):
/** 
 * Create a cluster to the specification
 * @param clusterSpec cluster specification
 * @param launchArgs
 * @return the exit code from the operation
 */
public int executeClusterStart(Path clusterDirectory,ClusterDescription clusterSpec,LaunchArgsAccessor launchArgs) throws YarnException, IOException {
  String clustername=clusterSpec.name;
  deployedClusterName=clustername;
  HoyaUtils.validateClusterName(clustername);
  verifyNoLiveClusters(clustername);
  Configuration config=getConfig();
  boolean clusterSecure=HoyaUtils.isClusterSecure(config);
  HoyaAMClientProvider hoyaAM=new HoyaAMClientProvider(config);
  ClientProvider provider=createClientProvider(clusterSpec);
  Path generatedConfDirPath=createPathThatMustExist(clusterSpec.generatedConfigurationPath);
  Path origConfPath=createPathThatMustExist(clusterSpec.originConfigurationPath);
  Path imagePath;
  String csip=clusterSpec.getImagePath();
  if (!isUnset(csip)) {
    imagePath=createPathThatMustExist(csip);
  }
 else {
    imagePath=null;
    if (isUnset(clusterSpec.getApplicationHome())) {
      throw new BadClusterStateException("String_Node_Str");
    }
  }
  hoyaAM.validateClusterSpec(clusterSpec);
  provider.validateClusterSpec(clusterSpec);
  if (log.isDebugEnabled()) {
    log.debug(clusterSpec.toString());
  }
  YarnClientApplication application=yarnClient.createApplication();
  ApplicationSubmissionContext appContext=application.getApplicationSubmissionContext();
  ApplicationId appId=appContext.getApplicationId();
  appContext.setApplicationName(clustername);
  appContext.setApplicationType(HoyaKeys.APP_TYPE);
  if (clusterSpec.getOptionBool(OptionKeys.HOYA_TEST_FLAG,false)) {
    appContext.setMaxAppAttempts(1);
  }
  FileSystem fs=getClusterFS();
  HoyaUtils.purgeHoyaAppInstanceTempFiles(fs,clustername);
  Path tempPath=HoyaUtils.createHoyaAppInstanceTempPath(fs,clustername,appId.toString());
  String libdir="String_Node_Str";
  Path libPath=new Path(tempPath,libdir);
  fs.mkdirs(libPath);
  log.debug("String_Node_Str",fs,tempPath,libPath);
  ContainerLaunchContext amContainer=Records.newRecord(ContainerLaunchContext.class);
  Map<String,LocalResource> localResources=new HashMap<String,LocalResource>();
  Path remoteHoyaConfPath=null;
  String relativeHoyaConfDir=null;
  String hoyaConfdirProp=System.getProperty(HoyaKeys.PROPERTY_HOYA_CONF_DIR);
  if (hoyaConfdirProp == null || hoyaConfdirProp.isEmpty()) {
    log.debug("String_Node_Str");
  }
 else {
    File hoyaConfDir=new File(hoyaConfdirProp);
    if (!hoyaConfDir.exists()) {
      throw new BadConfigException("String_Node_Str",hoyaConfDir);
    }
    Path localConfDirPath=HoyaUtils.createLocalPath(hoyaConfDir);
    log.debug("String_Node_Str",localConfDirPath);
    remoteHoyaConfPath=new Path(clusterDirectory,HoyaKeys.SUBMITTED_HOYA_CONF_DIR);
    HoyaUtils.copyDirectory(config,localConfDirPath,remoteHoyaConfPath);
  }
  if (!getUsingMiniMRCluster()) {
    log.debug("String_Node_Str");
    if (remoteHoyaConfPath != null) {
      relativeHoyaConfDir=HoyaKeys.SUBMITTED_HOYA_CONF_DIR;
      Map<String,LocalResource> submittedConfDir=HoyaUtils.submitDirectory(fs,remoteHoyaConfPath,relativeHoyaConfDir);
      HoyaUtils.mergeMaps(localResources,submittedConfDir);
    }
    log.info("String_Node_Str");
    HoyaUtils.putJar(localResources,fs,this.getClass(),tempPath,libdir,HOYA_JAR);
  }
  propagatePrincipals(clusterSpec,config);
  Configuration clientConfExtras=new Configuration(false);
  Map<String,LocalResource> providerResources;
  providerResources=hoyaAM.prepareAMAndConfigForLaunch(fs,config,clusterSpec,origConfPath,generatedConfDirPath,clientConfExtras,libdir,tempPath);
  localResources.putAll(providerResources);
  providerResources=provider.prepareAMAndConfigForLaunch(fs,config,clusterSpec,origConfPath,generatedConfDirPath,clientConfExtras,libdir,tempPath);
  localResources.putAll(providerResources);
  log.debug("String_Node_Str");
  provider.preflightValidateClusterConfiguration(clusterSpec,fs,generatedConfDirPath,clusterSecure);
  if (HoyaUtils.maybeAddImagePath(fs,localResources,imagePath)) {
    log.debug("String_Node_Str",imagePath);
  }
  if (log.isDebugEnabled()) {
    for (    Map.Entry<String,LocalResource> entry : localResources.entrySet()) {
      String key=entry.getKey();
      LocalResource val=entry.getValue();
      log.debug("String_Node_Str",key,HoyaUtils.stringify(val.getResource()));
    }
  }
  amContainer.setLocalResources(localResources);
  Map<String,String> env=HoyaUtils.buildEnvMap(clusterSpec.getOrAddRole(HoyaKeys.ROLE_HOYA_AM));
  String classpath=HoyaUtils.buildClasspath(relativeHoyaConfDir,libdir,getConfig(),getUsingMiniMRCluster());
  env.put("String_Node_Str",classpath);
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str",classpath);
    log.debug("String_Node_Str",HoyaUtils.stringifyMap(env));
    log.debug("String_Node_Str",HoyaUtils.listFSDir(fs,libPath));
  }
  amContainer.setEnvironment(env);
  String rmAddr=launchArgs.getRmAddress();
  if (isUnset(rmAddr) && HoyaUtils.isRmSchedulerAddressDefined(config)) {
    rmAddr=NetUtils.getHostPortString(HoyaUtils.getRmSchedulerAddress(config));
  }
  List<String> commands=new ArrayList<String>(20);
  commands.add(ApplicationConstants.Environment.JAVA_HOME.$() + "String_Node_Str");
  hoyaAM.addJVMOptions(clusterSpec,commands);
  if (serviceArgs.isDebug()) {
    commands.add(HoyaKeys.JVM_ENABLE_ASSERTIONS);
    commands.add(HoyaKeys.JVM_ENABLE_SYSTEM_ASSERTIONS);
  }
  commands.add(String.format(HoyaKeys.FORMAT_D_CLUSTER_NAME,clustername));
  commands.add(String.format(HoyaKeys.FORMAT_D_CLUSTER_TYPE,provider.getName()));
  commands.add(HoyaAMArgs.CLASSNAME);
  commands.add(HoyaActions.ACTION_CREATE);
  commands.add(clustername);
  if (serviceArgs.isDebug()) {
    commands.add(Arguments.ARG_DEBUG);
  }
  commands.add(Arguments.ARG_HOYA_CLUSTER_URI);
  commands.add(clusterDirectory.toUri().toString());
  if (!isUnset(rmAddr)) {
    commands.add(Arguments.ARG_RM_ADDR);
    commands.add(rmAddr);
  }
  if (serviceArgs.getFilesystemURL() != null) {
    commands.add(Arguments.ARG_FILESYSTEM);
    commands.add(serviceArgs.getFilesystemURL().toString());
  }
  if (clusterSecure) {
    propagateConfOption(commands,config,HoyaXmlConfKeys.KEY_HOYA_SECURITY_ENABLED);
    propagateConfOption(commands,config,DFSConfigKeys.DFS_NAMENODE_USER_NAME_KEY);
    Credentials credentials=new Credentials();
    String tokenRenewer=config.get(YarnConfiguration.RM_PRINCIPAL);
    if (isUnset(tokenRenewer)) {
      throw new BadConfigException("String_Node_Str",YarnConfiguration.RM_PRINCIPAL);
    }
    final Token<?>[] tokens=fs.addDelegationTokens(tokenRenewer,credentials);
    if (tokens != null) {
      for (      Token<?> token : tokens) {
        log.debug("String_Node_Str",fs.getUri(),token);
      }
    }
    DataOutputBuffer dob=new DataOutputBuffer();
    credentials.writeTokenStorageToStream(dob);
    ByteBuffer fsTokens=ByteBuffer.wrap(dob.getData(),0,dob.getLength());
    amContainer.setTokens(fsTokens);
  }
  commands.add("String_Node_Str" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "String_Node_Str"+ STDOUT_HOYAAM);
  commands.add("String_Node_Str" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "String_Node_Str"+ STDERR_HOYAAM);
  String cmdStr=HoyaUtils.join(commands,"String_Node_Str");
  log.info("String_Node_Str",cmdStr);
  amContainer.setCommands(commands);
  Resource capability=Records.newRecord(Resource.class);
  capability.setMemory(RoleKeys.DEFAULT_AM_MEMORY);
  capability.setVirtualCores(RoleKeys.DEFAULT_AM_V_CORES);
  hoyaAM.prepareAMResourceRequirements(clusterSpec,capability);
  appContext.setResource(capability);
  Map<String,ByteBuffer> serviceData=new HashMap<String,ByteBuffer>();
  provider.prepareAMServiceData(clusterSpec,serviceData);
  amContainer.setServiceData(serviceData);
  appContext.setAMContainerSpec(amContainer);
  Priority pri=Records.newRecord(Priority.class);
  pri.setPriority(amPriority);
  appContext.setPriority(pri);
  appContext.setQueue(amQueue);
  log.info("String_Node_Str");
  applicationId=yarnClient.submitApplication(appContext);
  int exitCode;
  ApplicationReport report=monitorAppToState(new Duration(ACCEPT_TIME),YarnApplicationState.ACCEPTED);
  if (HoyaUtils.hasAppFinished(report)) {
    exitCode=buildExitCode(appId,report);
  }
 else {
    exitCode=EXIT_SUCCESS;
    int waittime=launchArgs.getWaittime();
    if (waittime != 0) {
      Duration duration=new Duration(waittime * 1000);
      duration.start();
      report=monitorAppToState(duration,YarnApplicationState.RUNNING);
      if (report != null && report.getYarnApplicationState() == YarnApplicationState.RUNNING) {
        exitCode=EXIT_SUCCESS;
      }
 else {
        yarnClient.killRunningApplication(appId,"String_Node_Str");
        exitCode=buildExitCode(appId,report);
      }
    }
  }
  return exitCode;
}