/lang/java/reef-runtime-azbatch/src/main/java/org/apache/reef/runtime/azbatch/util/command/WindowsCommandBuilder.java

https://github.com/apache/reef · Java · 86 lines · 56 code · 9 blank · 21 comment · 0 complexity · d98d3d4dcabc4313bb831fa417f47a7f MD5 · raw file

  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package org.apache.reef.runtime.azbatch.util.command;
  20. import org.apache.commons.lang.StringUtils;
  21. import org.apache.reef.annotations.audience.Private;
  22. import org.apache.reef.runtime.azbatch.evaluator.EvaluatorShimLauncher;
  23. import org.apache.reef.runtime.azbatch.util.AzureBatchFileNames;
  24. import org.apache.reef.runtime.common.REEFLauncher;
  25. import org.apache.reef.runtime.common.files.ClasspathProvider;
  26. import org.apache.reef.runtime.common.files.REEFFileNames;
  27. import org.apache.reef.runtime.common.files.RuntimePathProvider;
  28. import javax.inject.Inject;
  29. import java.util.Arrays;
  30. import java.util.Collections;
  31. import java.util.List;
  32. /**
  33. * Build the launch command for Java REEF processes for Azure Batch Windows pools.
  34. */
  35. @Private
  36. public class WindowsCommandBuilder extends AbstractCommandBuilder {
  37. private static final Class LAUNCHER_CLASS = REEFLauncher.class;
  38. private static final Class SHIM_LAUNCHER_CLASS = EvaluatorShimLauncher.class;
  39. private static final List<String> COMMAND_LIST_PREFIX = Collections.unmodifiableList(
  40. Arrays.asList(
  41. "Add-Type -AssemblyName System.IO.Compression.FileSystem; ",
  42. "[System.IO.Compression.ZipFile]::ExtractToDirectory(\\\"$env:AZ_BATCH_TASK_WORKING_DIR\\" +
  43. AzureBatchFileNames.getTaskJarFileName() + "\\\", " +
  44. "\\\"$env:AZ_BATCH_TASK_WORKING_DIR\\reef\\\"); ")
  45. );
  46. private static final char CLASSPATH_SEPARATOR_CHAR = ';';
  47. private static final String OS_COMMAND_FORMAT = "powershell.exe /c \"%s\";";
  48. @Inject
  49. WindowsCommandBuilder(
  50. final ClasspathProvider classpathProvider,
  51. final RuntimePathProvider runtimePathProvider,
  52. final REEFFileNames reefFileNames,
  53. final AzureBatchFileNames azureBatchFileNames) {
  54. super(LAUNCHER_CLASS, SHIM_LAUNCHER_CLASS, COMMAND_LIST_PREFIX, OS_COMMAND_FORMAT,
  55. classpathProvider, runtimePathProvider, reefFileNames, azureBatchFileNames);
  56. }
  57. @Override
  58. protected String getDriverClasspath() {
  59. return String.format("'%s'", StringUtils.join(
  60. super.classpathProvider.getDriverClasspath(), CLASSPATH_SEPARATOR_CHAR));
  61. }
  62. @Override
  63. protected String getEvaluatorShimClasspath() {
  64. return String.format("'%s'", StringUtils.join(
  65. super.classpathProvider.getEvaluatorClasspath(), CLASSPATH_SEPARATOR_CHAR));
  66. }
  67. @Override
  68. public String getIpAddressFilePath() {
  69. return "%AZ_BATCH_JOB_PREP_WORKING_DIR%\\hostip.txt";
  70. }
  71. @Override
  72. public String captureIpAddressCommandLine() {
  73. return String.format("powershell /c \"Set-Content -Path %s -Value "
  74. + "((Test-Connection -ComputerName $Env:ComputerName -Count 1).IPV4Address.IPAddressToString) "
  75. + " -NoNewline -Force\"", getIpAddressFilePath());
  76. }
  77. }