Program: 79375
Project: 79375
Buggy source:
protected MachineLocation obtainOnce(ConfigBag setup) throws NoMachinesAvailableException {
  AccessController.Response access=getManagementContext().getAccessController().canProvisionLocation(this);
  if (!access.isAllowed()) {
    throw new IllegalStateException("String_Node_Str" + this + "String_Node_Str"+ access.getMsg());
  }
  setCreationString(setup);
  boolean waitForSshable=!"String_Node_Str".equalsIgnoreCase(setup.get(WAIT_FOR_SSHABLE));
  boolean waitForWinRmable=!"String_Node_Str".equalsIgnoreCase(setup.get(WAIT_FOR_WINRM_AVAILABLE));
  boolean usePortForwarding=setup.get(USE_PORT_FORWARDING);
  boolean skipJcloudsSshing=Boolean.FALSE.equals(setup.get(USE_JCLOUDS_SSH_INIT)) || usePortForwarding;
  JcloudsPortForwarderExtension portForwarder=setup.get(PORT_FORWARDER);
  if (usePortForwarding)   checkNotNull(portForwarder,"String_Node_Str");
  final ComputeService computeService=getConfig(COMPUTE_SERVICE_REGISTRY).findComputeService(setup,true);
  CloudMachineNamer cloudMachineNamer=getCloudMachineNamer(setup);
  String groupId=elvis(setup.get(GROUP_ID),cloudMachineNamer.generateNewGroupId(setup));
  NodeMetadata node=null;
  JcloudsMachineLocation machineLocation=null;
  try {
    LOG.info("String_Node_Str" + setup.getDescription() + "String_Node_Str"+ this);
    Semaphore machineCreationSemaphore=getMachineCreationSemaphore();
    boolean acquired=machineCreationSemaphore.tryAcquire(0,TimeUnit.SECONDS);
    if (!acquired) {
      LOG.info("String_Node_Str",new Object[]{this,machineCreationSemaphore.getQueueLength()});
      Stopwatch blockStopwatch=Stopwatch.createStarted();
      machineCreationSemaphore.acquire();
      LOG.info("String_Node_Str",this,Time.makeTimeStringRounded(blockStopwatch));
    }
 else {
      LOG.debug("String_Node_Str",this);
    }
    Stopwatch provisioningStopwatch=Stopwatch.createStarted();
    Duration templateTimestamp, provisionTimestamp, usableTimestamp, customizedTimestamp;
    LoginCredentials userCredentials=null;
    Set<? extends NodeMetadata> nodes;
    Template template;
    try {
      template=buildTemplate(computeService,setup);
      boolean expectWindows=isWindows(template,setup);
      if (!skipJcloudsSshing) {
        if (expectWindows) {
          LOG.warn("String_Node_Str" + template.getImage() + "String_Node_Str"+ USE_JCLOUDS_SSH_INIT.getName()+ "String_Node_Str");
          skipJcloudsSshing=true;
        }
 else         if (waitForSshable) {
          userCredentials=initTemplateForCreateUser(template,setup);
        }
      }
      templateTimestamp=Duration.of(provisioningStopwatch);
      template.getOptions().getUserMetadata().put("String_Node_Str",cloudMachineNamer.generateNewMachineUniqueNameFromGroupId(setup,groupId));
      if (setup.get(JcloudsLocationConfig.INCLUDE_BROOKLYN_USER_METADATA)) {
        template.getOptions().getUserMetadata().put("String_Node_Str",System.getProperty("String_Node_Str"));
        Object context=setup.get(CALLER_CONTEXT);
        if (context instanceof Entity) {
          Entity entity=(Entity)context;
          template.getOptions().getUserMetadata().put("String_Node_Str",entity.getApplicationId());
          template.getOptions().getUserMetadata().put("String_Node_Str",entity.getApplication().getDisplayName());
          template.getOptions().getUserMetadata().put("String_Node_Str",entity.getId());
          template.getOptions().getUserMetadata().put("String_Node_Str",entity.getDisplayName());
          template.getOptions().getUserMetadata().put("String_Node_Str",Time.makeDateSimpleStampString());
        }
      }
      customizeTemplate(setup,computeService,template);
      LOG.debug("String_Node_Str",new Object[]{template,template.getOptions(),setup.getDescription()});
      if (!setup.getUnusedConfig().isEmpty())       LOG.debug("String_Node_Str" + setup.getDescription() + "String_Node_Str"+ setup.getUnusedConfig());
      nodes=computeService.createNodesInGroup(groupId,1,template);
      provisionTimestamp=Duration.of(provisioningStopwatch);
    }
  finally {
      machineCreationSemaphore.release();
    }
    node=Iterables.getOnlyElement(nodes,null);
    LOG.debug("String_Node_Str",node,setup.getDescription());
    if (node == null)     throw new IllegalStateException("String_Node_Str" + setup.getDescription());
    boolean windows=isWindows(node,setup);
    if (windows) {
      int newLoginPort=node.getLoginPort() == 22 ? 5985 : node.getLoginPort();
      String newLoginUser="String_Node_Str".equals(node.getCredentials().getUser()) ? "String_Node_Str" : node.getCredentials().getUser();
      LOG.debug("String_Node_Str",new Object[]{node,node.getLoginPort(),newLoginPort,node.getCredentials().getUser(),newLoginUser});
      node=NodeMetadataBuilder.fromNodeMetadata(node).loginPort(newLoginPort).credentials(LoginCredentials.builder(node.getCredentials()).user(newLoginUser).build()).build();
    }
    Optional<HostAndPort> sshHostAndPortOverride;
    if (usePortForwarding) {
      sshHostAndPortOverride=Optional.of(portForwarder.openPortForwarding(node,node.getLoginPort(),Optional.<Integer>absent(),Protocol.TCP,Cidr.UNIVERSAL));
    }
 else {
      sshHostAndPortOverride=Optional.absent();
    }
    if (skipJcloudsSshing) {
      boolean waitForConnectable=(windows) ? waitForWinRmable : waitForSshable;
      if (waitForConnectable) {
        if (windows) {
          waitForWinRmAvailable(computeService,node,sshHostAndPortOverride,node.getCredentials(),setup);
        }
 else {
          waitForSshable(computeService,node,sshHostAndPortOverride,node.getCredentials(),setup);
        }
        userCredentials=createUser(computeService,node,sshHostAndPortOverride,setup);
      }
    }
    LoginCredentials customCredentials=setup.get(CUSTOM_CREDENTIALS);
    if (customCredentials != null) {
      userCredentials=customCredentials;
      Object oldUsername=setup.put(USER,customCredentials.getUser());
      LOG.debug("String_Node_Str",new Object[]{node,customCredentials.getUser(),oldUsername});
      if (customCredentials.getOptionalPassword().isPresent())       setup.put(PASSWORD,customCredentials.getOptionalPassword().get());
      if (customCredentials.getOptionalPrivateKey().isPresent())       setup.put(PRIVATE_KEY_DATA,customCredentials.getOptionalPrivateKey().get());
    }
    if (userCredentials == null) {
      userCredentials=extractVmCredentials(setup,node);
    }
    if (userCredentials != null) {
      node=NodeMetadataBuilder.fromNodeMetadata(node).credentials(userCredentials).build();
    }
 else {
      userCredentials=LoginCredentials.fromCredentials(node.getCredentials());
    }
    setup.putIfNotNull(JcloudsLocationConfig.PASSWORD,userCredentials.getOptionalPassword().orNull());
    setup.putIfNotNull(JcloudsLocationConfig.PRIVATE_KEY_DATA,userCredentials.getOptionalPrivateKey().orNull());
    if (waitForSshable && !windows) {
      waitForSshable(computeService,node,sshHostAndPortOverride,userCredentials,setup);
    }
 else {
      LOG.debug("String_Node_Str",node,setup.getDescription());
    }
    usableTimestamp=Duration.of(provisioningStopwatch);
    if (windows) {
      machineLocation=registerWinRmMachineLocation(computeService,node,userCredentials,sshHostAndPortOverride,setup);
    }
 else {
      machineLocation=registerJcloudsSshMachineLocation(computeService,node,userCredentials,sshHostAndPortOverride,setup);
      if (template != null && machineLocation.getTemplate() == null) {
        ((JcloudsSshMachineLocation)machineLocation).template=template;
      }
    }
    if (usePortForwarding && sshHostAndPortOverride.isPresent()) {
      PortForwardManager portForwardManager=setup.get(PORT_FORWARDING_MANAGER);
      if (portForwardManager != null) {
        portForwardManager.associate(node.getId(),sshHostAndPortOverride.get(),machineLocation,node.getLoginPort());
      }
 else {
        LOG.warn("String_Node_Str",new Object[]{this,node.getLoginPort(),sshHostAndPortOverride,machineLocation});
      }
    }
    if ("String_Node_Str".equals(this.getProvider())) {
      if (windows) {
        throw new UnsupportedOperationException("String_Node_Str");
      }
      Map<Integer,Integer> portMappings=JcloudsUtil.dockerPortMappingsFor(this,node.getId());
      PortForwardManager portForwardManager=setup.get(PORT_FORWARDING_MANAGER);
      if (portForwardManager != null) {
        for (        Integer containerPort : portMappings.keySet()) {
          Integer hostPort=portMappings.get(containerPort);
          String dockerHost=((JcloudsSshMachineLocation)machineLocation).getSshHostAndPort().getHostText();
          portForwardManager.associate(node.getId(),HostAndPort.fromParts(dockerHost,hostPort),machineLocation,containerPort);
        }
      }
 else {
        LOG.warn("String_Node_Str",this,machineLocation);
      }
    }
    List<String> customisationForLogging=new ArrayList<String>();
    if (waitForSshable) {
      String setupScript=setup.get(JcloudsLocationConfig.CUSTOM_MACHINE_SETUP_SCRIPT_URL);
      List<String> setupScripts=setup.get(JcloudsLocationConfig.CUSTOM_MACHINE_SETUP_SCRIPT_URL_LIST);
      Collection<String> allScripts=new MutableList<String>().appendIfNotNull(setupScript).appendAll(setupScripts);
      for (      String setupScriptItem : allScripts) {
        if (Strings.isNonBlank(setupScriptItem)) {
          customisationForLogging.add("String_Node_Str" + setupScriptItem);
          String setupVarsString=setup.get(JcloudsLocationConfig.CUSTOM_MACHINE_SETUP_SCRIPT_VARS);
          Map<String,String> substitutions=(setupVarsString != null) ? Splitter.on("String_Node_Str").withKeyValueSeparator("String_Node_Str").split(setupVarsString) : ImmutableMap.<String,String>of();
          String scriptContent=ResourceUtils.create(this).getResourceAsString(setupScriptItem);
          String script=TemplateProcessor.processTemplateContents(scriptContent,getManagementContext(),substitutions);
          if (windows) {
            ((WinRmMachineLocation)machineLocation).executeScript(ImmutableList.copyOf((script.replace("String_Node_Str","String_Node_Str").split("String_Node_Str"))));
          }
 else {
            ((SshMachineLocation)machineLocation).execCommands("String_Node_Str" + this,ImmutableList.of(script));
          }
        }
      }
      if (setup.get(JcloudsLocationConfig.MAP_DEV_RANDOM_TO_DEV_URANDOM)) {
        if (windows) {
          LOG.warn("String_Node_Str",machineLocation);
        }
 else {
          customisationForLogging.add("String_Node_Str");
          ((SshMachineLocation)machineLocation).execCommands("String_Node_Str",Arrays.asList("String_Node_Str","String_Node_Str"));
        }
      }
      if (setup.get(GENERATE_HOSTNAME)) {
        if (windows) {
          LOG.warn("String_Node_Str",machineLocation);
        }
 else {
          customisationForLogging.add("String_Node_Str");
          ((SshMachineLocation)machineLocation).execCommands("String_Node_Str" + node.getName(),Arrays.asList("String_Node_Str" + node.getName(),"String_Node_Str" + node.getName() + "String_Node_Str","String_Node_Str"));
        }
      }
      if (setup.get(OPEN_IPTABLES)) {
        if (windows) {
          LOG.warn("String_Node_Str",machineLocation);
        }
 else {
          @SuppressWarnings("String_Node_Str") Iterable<Integer> inboundPorts=(Iterable<Integer>)setup.get(INBOUND_PORTS);
          if (inboundPorts == null || Iterables.isEmpty(inboundPorts)) {
            LOG.info("String_Node_Str",machineLocation,this);
          }
 else {
            customisationForLogging.add("String_Node_Str");
            List<String> iptablesRules=Lists.newArrayList();
            if (isLocationFirewalldEnabled((SshMachineLocation)machineLocation)) {
              for (              Integer port : inboundPorts) {
                iptablesRules.add(IptablesCommands.addFirewalldRule(Chain.INPUT,Protocol.TCP,port,Policy.ACCEPT));
              }
            }
 else {
              iptablesRules=createIptablesRulesForNetworkInterface(inboundPorts);
              iptablesRules.add(IptablesCommands.saveIptablesRules());
            }
            List<String> batch=Lists.newArrayList();
            for (            String rule : iptablesRules) {
              batch.add(rule);
              if (batch.size() == 50) {
                ((SshMachineLocation)machineLocation).execCommands("String_Node_Str",batch);
                batch.clear();
              }
            }
            if (batch.size() > 0) {
              ((SshMachineLocation)machineLocation).execCommands("String_Node_Str",batch);
            }
            ((SshMachineLocation)machineLocation).execCommands("String_Node_Str",ImmutableList.of(IptablesCommands.listIptablesRule()));
          }
        }
      }
      if (setup.get(STOP_IPTABLES)) {
        if (windows) {
          LOG.warn("String_Node_Str",machineLocation);
        }
 else {
          customisationForLogging.add("String_Node_Str");
          List<String> cmds=ImmutableList.<String>of();
          if (isLocationFirewalldEnabled((SshMachineLocation)machineLocation)) {
            cmds=ImmutableList.of(IptablesCommands.firewalldServiceStop(),IptablesCommands.firewalldServiceStatus());
          }
 else {
            cmds=ImmutableList.of(IptablesCommands.iptablesServiceStop(),IptablesCommands.iptablesServiceStatus());
          }
          ((SshMachineLocation)machineLocation).execCommands("String_Node_Str",cmds);
        }
      }
      List<String> extraKeyUrlsToAuth=setup.get(EXTRA_PUBLIC_KEY_URLS_TO_AUTH);
      if (extraKeyUrlsToAuth != null && !extraKeyUrlsToAuth.isEmpty()) {
        if (windows) {
          LOG.warn("String_Node_Str",machineLocation);
        }
 else {
          List<String> extraKeyDataToAuth=MutableList.of();
          for (          String keyUrl : extraKeyUrlsToAuth) {
            extraKeyDataToAuth.add(ResourceUtils.create().getResourceAsString(keyUrl));
          }
          ((SshMachineLocation)machineLocation).execCommands("String_Node_Str",ImmutableList.of(new AuthorizeRSAPublicKeys(extraKeyDataToAuth).render(org.jclouds.scriptbuilder.domain.OsFamily.UNIX)));
        }
      }
    }
 else {
    }
    for (    JcloudsLocationCustomizer customizer : getCustomizers(setup)) {
      customizer.customize(this,computeService,machineLocation);
    }
    customizedTimestamp=Duration.of(provisioningStopwatch);
    try {
      String logMessage="String_Node_Str" + setup.getDescription() + "String_Node_Str"+ "String_Node_Str"+ machineLocation.getUser()+ "String_Node_Str"+ machineLocation.getAddress()+ "String_Node_Str"+ machineLocation.getPort()+ (Boolean.TRUE.equals(setup.get(LOG_CREDENTIALS)) ? "String_Node_Str" + userCredentials.getOptionalPassword().or("String_Node_Str") + "String_Node_Str"+ userCredentials.getOptionalPrivateKey().or("String_Node_Str") : "String_Node_Str")+ "String_Node_Str"+ Duration.of(provisioningStopwatch).toStringRounded()+ "String_Node_Str"+ template+ "String_Node_Str"+ Duration.of(templateTimestamp).toStringRounded()+ "String_Node_Str"+ "String_Node_Str"+ node+ "String_Node_Str"+ Duration.of(provisionTimestamp).subtract(templateTimestamp).toStringRounded()+ "String_Node_Str"+ "String_Node_Str"+ machineLocation+ "String_Node_Str"+ Duration.of(usableTimestamp).subtract(provisionTimestamp).toStringRounded()+ "String_Node_Str"+ "String_Node_Str"+ Duration.of(customizedTimestamp).subtract(usableTimestamp).toStringRounded()+ "String_Node_Str"+ Joiner.on("String_Node_Str").join(customisationForLogging)+ "String_Node_Str";
      LOG.info(logMessage);
    }
 catch (    Exception e) {
      Exceptions.propagateIfFatal(e);
      LOG.warn("String_Node_Str" + machineLocation + "String_Node_Str"+ this,e);
    }
    return machineLocation;
  }
 catch (  Exception e) {
    if (e instanceof RunNodesException && ((RunNodesException)e).getNodeErrors().size() > 0) {
      node=Iterables.get(((RunNodesException)e).getNodeErrors().keySet(),0);
    }
    boolean destroyNode=(node != null) && Boolean.TRUE.equals(setup.get(DESTROY_ON_FAILURE));
    LOG.error("String_Node_Str",new Object[]{setup.getDescription(),(destroyNode ? "String_Node_Str" + node + "String_Node_Str" : "String_Node_Str"),e.getMessage()});
    LOG.debug(Throwables.getStackTraceAsString(e));
    if (destroyNode) {
      if (machineLocation != null) {
        releaseSafely(machineLocation);
      }
 else {
        releaseNodeSafely(node);
      }
    }
    throw Exceptions.propagate(e);
  }
}

Fixed version (ground truth):
protected MachineLocation obtainOnce(ConfigBag setup) throws NoMachinesAvailableException {
  AccessController.Response access=getManagementContext().getAccessController().canProvisionLocation(this);
  if (!access.isAllowed()) {
    throw new IllegalStateException("String_Node_Str" + this + "String_Node_Str"+ access.getMsg());
  }
  setCreationString(setup);
  boolean waitForSshable=!"String_Node_Str".equalsIgnoreCase(setup.get(WAIT_FOR_SSHABLE));
  boolean waitForWinRmable=!"String_Node_Str".equalsIgnoreCase(setup.get(WAIT_FOR_WINRM_AVAILABLE));
  boolean usePortForwarding=setup.get(USE_PORT_FORWARDING);
  boolean skipJcloudsSshing=Boolean.FALSE.equals(setup.get(USE_JCLOUDS_SSH_INIT)) || usePortForwarding;
  JcloudsPortForwarderExtension portForwarder=setup.get(PORT_FORWARDER);
  if (usePortForwarding)   checkNotNull(portForwarder,"String_Node_Str");
  final ComputeService computeService=getConfig(COMPUTE_SERVICE_REGISTRY).findComputeService(setup,true);
  CloudMachineNamer cloudMachineNamer=getCloudMachineNamer(setup);
  String groupId=elvis(setup.get(GROUP_ID),cloudMachineNamer.generateNewGroupId(setup));
  NodeMetadata node=null;
  JcloudsMachineLocation machineLocation=null;
  try {
    LOG.info("String_Node_Str" + setup.getDescription() + "String_Node_Str"+ this);
    Semaphore machineCreationSemaphore=getMachineCreationSemaphore();
    boolean acquired=machineCreationSemaphore.tryAcquire(0,TimeUnit.SECONDS);
    if (!acquired) {
      LOG.info("String_Node_Str",new Object[]{this,machineCreationSemaphore.getQueueLength()});
      Stopwatch blockStopwatch=Stopwatch.createStarted();
      machineCreationSemaphore.acquire();
      LOG.info("String_Node_Str",this,Time.makeTimeStringRounded(blockStopwatch));
    }
 else {
      LOG.debug("String_Node_Str",this);
    }
    Stopwatch provisioningStopwatch=Stopwatch.createStarted();
    Duration templateTimestamp, provisionTimestamp, usableTimestamp, customizedTimestamp;
    LoginCredentials userCredentials=null;
    Set<? extends NodeMetadata> nodes;
    Template template;
    try {
      template=buildTemplate(computeService,setup);
      boolean expectWindows=isWindows(template,setup);
      if (!skipJcloudsSshing) {
        if (expectWindows) {
          LOG.warn("String_Node_Str" + template.getImage() + "String_Node_Str"+ USE_JCLOUDS_SSH_INIT.getName()+ "String_Node_Str");
          skipJcloudsSshing=true;
        }
 else         if (waitForSshable) {
          userCredentials=initTemplateForCreateUser(template,setup);
        }
      }
      templateTimestamp=Duration.of(provisioningStopwatch);
      template.getOptions().getUserMetadata().put("String_Node_Str",cloudMachineNamer.generateNewMachineUniqueNameFromGroupId(setup,groupId));
      if (setup.get(JcloudsLocationConfig.INCLUDE_BROOKLYN_USER_METADATA)) {
        template.getOptions().getUserMetadata().put("String_Node_Str",System.getProperty("String_Node_Str"));
        Object context=setup.get(CALLER_CONTEXT);
        if (context instanceof Entity) {
          Entity entity=(Entity)context;
          template.getOptions().getUserMetadata().put("String_Node_Str",entity.getApplicationId());
          template.getOptions().getUserMetadata().put("String_Node_Str",entity.getApplication().getDisplayName());
          template.getOptions().getUserMetadata().put("String_Node_Str",entity.getId());
          template.getOptions().getUserMetadata().put("String_Node_Str",entity.getDisplayName());
          template.getOptions().getUserMetadata().put("String_Node_Str",Time.makeDateSimpleStampString());
        }
      }
      customizeTemplate(setup,computeService,template);
      LOG.debug("String_Node_Str",new Object[]{template,template.getOptions(),setup.getDescription()});
      if (!setup.getUnusedConfig().isEmpty())       LOG.debug("String_Node_Str" + setup.getDescription() + "String_Node_Str"+ setup.getUnusedConfig());
      nodes=computeService.createNodesInGroup(groupId,1,template);
      provisionTimestamp=Duration.of(provisioningStopwatch);
    }
  finally {
      machineCreationSemaphore.release();
    }
    node=Iterables.getOnlyElement(nodes,null);
    LOG.debug("String_Node_Str",node,setup.getDescription());
    if (node == null)     throw new IllegalStateException("String_Node_Str" + setup.getDescription());
    boolean windows=isWindows(node,setup);
    if (windows) {
      int newLoginPort=node.getLoginPort() == 22 ? 5985 : node.getLoginPort();
      String newLoginUser="String_Node_Str".equals(node.getCredentials().getUser()) ? "String_Node_Str" : node.getCredentials().getUser();
      LOG.debug("String_Node_Str",new Object[]{node,node.getLoginPort(),newLoginPort,node.getCredentials().getUser(),newLoginUser});
      node=NodeMetadataBuilder.fromNodeMetadata(node).loginPort(newLoginPort).credentials(LoginCredentials.builder(node.getCredentials()).user(newLoginUser).build()).build();
    }
    Optional<HostAndPort> sshHostAndPortOverride;
    if (usePortForwarding) {
      sshHostAndPortOverride=Optional.of(portForwarder.openPortForwarding(node,node.getLoginPort(),Optional.<Integer>absent(),Protocol.TCP,Cidr.UNIVERSAL));
    }
 else {
      sshHostAndPortOverride=Optional.absent();
    }
    if (skipJcloudsSshing) {
      boolean waitForConnectable=(windows) ? waitForWinRmable : waitForSshable;
      if (waitForConnectable) {
        if (windows) {
          waitForWinRmAvailable(computeService,node,sshHostAndPortOverride,node.getCredentials(),setup);
        }
 else {
          waitForSshable(computeService,node,sshHostAndPortOverride,node.getCredentials(),setup);
        }
        userCredentials=createUser(computeService,node,sshHostAndPortOverride,setup);
      }
    }
    LoginCredentials customCredentials=setup.get(CUSTOM_CREDENTIALS);
    if (customCredentials != null) {
      userCredentials=customCredentials;
      Object oldUsername=setup.put(USER,customCredentials.getUser());
      LOG.debug("String_Node_Str",new Object[]{node,customCredentials.getUser(),oldUsername});
      if (customCredentials.getOptionalPassword().isPresent())       setup.put(PASSWORD,customCredentials.getOptionalPassword().get());
      if (customCredentials.getOptionalPrivateKey().isPresent())       setup.put(PRIVATE_KEY_DATA,customCredentials.getOptionalPrivateKey().get());
    }
    if (userCredentials == null) {
      userCredentials=extractVmCredentials(setup,node);
    }
    if (userCredentials != null) {
      node=NodeMetadataBuilder.fromNodeMetadata(node).credentials(userCredentials).build();
    }
 else {
      userCredentials=LoginCredentials.fromCredentials(node.getCredentials());
    }
    setup.putIfNotNull(JcloudsLocationConfig.PASSWORD,userCredentials.getOptionalPassword().orNull());
    setup.putIfNotNull(JcloudsLocationConfig.PRIVATE_KEY_DATA,userCredentials.getOptionalPrivateKey().orNull());
    if (waitForSshable && !windows) {
      waitForSshable(computeService,node,sshHostAndPortOverride,userCredentials,setup);
    }
 else {
      LOG.debug("String_Node_Str",node,setup.getDescription());
    }
    usableTimestamp=Duration.of(provisioningStopwatch);
    if (windows) {
      machineLocation=registerWinRmMachineLocation(computeService,node,userCredentials,sshHostAndPortOverride,setup);
    }
 else {
      machineLocation=registerJcloudsSshMachineLocation(computeService,node,userCredentials,sshHostAndPortOverride,setup);
      if (template != null && machineLocation.getTemplate() == null) {
        ((JcloudsSshMachineLocation)machineLocation).template=template;
      }
    }
    if (usePortForwarding && sshHostAndPortOverride.isPresent()) {
      PortForwardManager portForwardManager=setup.get(PORT_FORWARDING_MANAGER);
      if (portForwardManager != null) {
        portForwardManager.associate(node.getId(),sshHostAndPortOverride.get(),machineLocation,node.getLoginPort());
      }
 else {
        LOG.warn("String_Node_Str",new Object[]{this,node.getLoginPort(),sshHostAndPortOverride,machineLocation});
      }
    }
    if ("String_Node_Str".equals(this.getProvider())) {
      if (windows) {
        throw new UnsupportedOperationException("String_Node_Str");
      }
      Map<Integer,Integer> portMappings=JcloudsUtil.dockerPortMappingsFor(this,node.getId());
      PortForwardManager portForwardManager=setup.get(PORT_FORWARDING_MANAGER);
      if (portForwardManager != null) {
        for (        Integer containerPort : portMappings.keySet()) {
          Integer hostPort=portMappings.get(containerPort);
          String dockerHost=((JcloudsSshMachineLocation)machineLocation).getSshHostAndPort().getHostText();
          portForwardManager.associate(node.getId(),HostAndPort.fromParts(dockerHost,hostPort),machineLocation,containerPort);
        }
      }
 else {
        LOG.warn("String_Node_Str",this,machineLocation);
      }
    }
    List<String> customisationForLogging=new ArrayList<String>();
    if (waitForSshable) {
      String setupScript=setup.get(JcloudsLocationConfig.CUSTOM_MACHINE_SETUP_SCRIPT_URL);
      List<String> setupScripts=setup.get(JcloudsLocationConfig.CUSTOM_MACHINE_SETUP_SCRIPT_URL_LIST);
      Collection<String> allScripts=new MutableList<String>().appendIfNotNull(setupScript).appendAll(setupScripts);
      for (      String setupScriptItem : allScripts) {
        if (Strings.isNonBlank(setupScriptItem)) {
          customisationForLogging.add("String_Node_Str" + setupScriptItem);
          String setupVarsString=setup.get(JcloudsLocationConfig.CUSTOM_MACHINE_SETUP_SCRIPT_VARS);
          Map<String,String> substitutions=(setupVarsString != null) ? Splitter.on("String_Node_Str").withKeyValueSeparator("String_Node_Str").split(setupVarsString) : ImmutableMap.<String,String>of();
          String scriptContent=ResourceUtils.create(this).getResourceAsString(setupScriptItem);
          String script=TemplateProcessor.processTemplateContents(scriptContent,getManagementContext(),substitutions);
          if (windows) {
            ((WinRmMachineLocation)machineLocation).executeScript(ImmutableList.copyOf((script.replace("String_Node_Str","String_Node_Str").split("String_Node_Str"))));
          }
 else {
            ((SshMachineLocation)machineLocation).execCommands("String_Node_Str" + this,ImmutableList.of(script));
          }
        }
      }
      if (setup.get(JcloudsLocationConfig.MAP_DEV_RANDOM_TO_DEV_URANDOM)) {
        if (windows) {
          LOG.warn("String_Node_Str",machineLocation);
        }
 else {
          customisationForLogging.add("String_Node_Str");
          ((SshMachineLocation)machineLocation).execCommands("String_Node_Str",Arrays.asList("String_Node_Str","String_Node_Str"));
        }
      }
      if (setup.get(GENERATE_HOSTNAME)) {
        if (windows) {
          LOG.warn("String_Node_Str",machineLocation);
        }
 else {
          customisationForLogging.add("String_Node_Str");
          ((SshMachineLocation)machineLocation).execCommands("String_Node_Str" + node.getName(),Arrays.asList("String_Node_Str" + node.getName(),"String_Node_Str" + node.getName() + "String_Node_Str","String_Node_Str"));
        }
      }
      if (setup.get(OPEN_IPTABLES)) {
        if (windows) {
          LOG.warn("String_Node_Str",machineLocation);
        }
 else {
          @SuppressWarnings("String_Node_Str") Iterable<Integer> inboundPorts=(Iterable<Integer>)setup.get(INBOUND_PORTS);
          if (inboundPorts == null || Iterables.isEmpty(inboundPorts)) {
            LOG.info("String_Node_Str",machineLocation,this);
          }
 else {
            customisationForLogging.add("String_Node_Str");
            List<String> iptablesRules=Lists.newArrayList();
            if (isLocationFirewalldEnabled((SshMachineLocation)machineLocation)) {
              for (              Integer port : inboundPorts) {
                iptablesRules.add(IptablesCommands.addFirewalldRule(Chain.INPUT,Protocol.TCP,port,Policy.ACCEPT));
              }
            }
 else {
              iptablesRules=createIptablesRulesForNetworkInterface(inboundPorts);
              iptablesRules.add(IptablesCommands.saveIptablesRules());
            }
            List<String> batch=Lists.newArrayList();
            for (            String rule : iptablesRules) {
              batch.add(rule);
              if (batch.size() == 50) {
                ((SshMachineLocation)machineLocation).execCommands("String_Node_Str",batch);
                batch.clear();
              }
            }
            if (batch.size() > 0) {
              ((SshMachineLocation)machineLocation).execCommands("String_Node_Str",batch);
            }
            ((SshMachineLocation)machineLocation).execCommands("String_Node_Str",ImmutableList.of(IptablesCommands.listIptablesRule()));
          }
        }
      }
      if (setup.get(STOP_IPTABLES)) {
        if (windows) {
          LOG.warn("String_Node_Str",machineLocation);
        }
 else {
          customisationForLogging.add("String_Node_Str");
          List<String> cmds=ImmutableList.<String>of();
          if (isLocationFirewalldEnabled((SshMachineLocation)machineLocation)) {
            cmds=ImmutableList.of(IptablesCommands.firewalldServiceStop(),IptablesCommands.firewalldServiceStatus());
          }
 else {
            cmds=ImmutableList.of(IptablesCommands.iptablesServiceStop(),IptablesCommands.iptablesServiceStatus());
          }
          ((SshMachineLocation)machineLocation).execCommands("String_Node_Str",cmds);
        }
      }
      List<String> extraKeyUrlsToAuth=setup.get(EXTRA_PUBLIC_KEY_URLS_TO_AUTH);
      if (extraKeyUrlsToAuth != null && !extraKeyUrlsToAuth.isEmpty()) {
        if (windows) {
          LOG.warn("String_Node_Str",machineLocation);
        }
 else {
          List<String> extraKeyDataToAuth=MutableList.of();
          for (          String keyUrl : extraKeyUrlsToAuth) {
            extraKeyDataToAuth.add(ResourceUtils.create().getResourceAsString(keyUrl));
          }
          ((SshMachineLocation)machineLocation).execCommands("String_Node_Str",ImmutableList.of(new AuthorizeRSAPublicKeys(extraKeyDataToAuth).render(org.jclouds.scriptbuilder.domain.OsFamily.UNIX)));
        }
      }
    }
 else {
    }
    for (    JcloudsLocationCustomizer customizer : getCustomizers(setup)) {
      customizer.customize(this,computeService,machineLocation);
    }
    customizedTimestamp=Duration.of(provisioningStopwatch);
    try {
      String logMessage="String_Node_Str" + setup.getDescription() + "String_Node_Str"+ "String_Node_Str"+ machineLocation.getUser()+ "String_Node_Str"+ machineLocation.getAddress()+ "String_Node_Str"+ machineLocation.getPort()+ (Boolean.TRUE.equals(setup.get(LOG_CREDENTIALS)) ? "String_Node_Str" + userCredentials.getOptionalPassword().or("String_Node_Str") + "String_Node_Str"+ userCredentials.getOptionalPrivateKey().or("String_Node_Str") : "String_Node_Str")+ "String_Node_Str"+ Duration.of(provisioningStopwatch).toStringRounded()+ "String_Node_Str"+ template+ "String_Node_Str"+ Duration.of(templateTimestamp).toStringRounded()+ "String_Node_Str"+ "String_Node_Str"+ node+ "String_Node_Str"+ Duration.of(provisionTimestamp).subtract(templateTimestamp).toStringRounded()+ "String_Node_Str"+ "String_Node_Str"+ machineLocation+ "String_Node_Str"+ Duration.of(usableTimestamp).subtract(provisionTimestamp).toStringRounded()+ "String_Node_Str"+ "String_Node_Str"+ Duration.of(customizedTimestamp).subtract(usableTimestamp).toStringRounded()+ "String_Node_Str"+ Joiner.on("String_Node_Str").join(customisationForLogging)+ "String_Node_Str";
      LOG.info(logMessage);
    }
 catch (    Exception e) {
      Exceptions.propagateIfFatal(e);
      LOG.warn("String_Node_Str" + machineLocation + "String_Node_Str"+ this,e);
    }
    return machineLocation;
  }
 catch (  Exception e) {
    if (e instanceof RunNodesException && ((RunNodesException)e).getNodeErrors().size() > 0) {
      node=Iterables.get(((RunNodesException)e).getNodeErrors().keySet(),0);
    }
    boolean destroyNode=(node != null) && Boolean.TRUE.equals(setup.get(DESTROY_ON_FAILURE));
    if (e.toString().contains("String_Node_Str")) {
      LOG.error("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
    }
    LOG.error("String_Node_Str",new Object[]{setup.getDescription(),(destroyNode ? "String_Node_Str" + node + "String_Node_Str" : "String_Node_Str"),e.getMessage()});
    LOG.debug(Throwables.getStackTraceAsString(e));
    if (destroyNode) {
      if (machineLocation != null) {
        releaseSafely(machineLocation);
      }
 else {
        releaseNodeSafely(node);
      }
    }
    throw Exceptions.propagate(e);
  }
}