/lang/java/reef-runtime-azbatch/src/main/java/org/apache/reef/runtime/azbatch/client/AzureBatchRuntimeConfigurationCreator.java

https://github.com/apache/reef · Java · 87 lines · 45 code · 9 blank · 33 comment · 4 complexity · eb607ca0b886e4a937065c01bf69395e 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.client;
  20. import org.apache.reef.annotations.audience.Private;
  21. import org.apache.reef.runtime.azbatch.parameters.*;
  22. import org.apache.reef.runtime.azbatch.util.command.CommandBuilder;
  23. import org.apache.reef.runtime.azbatch.util.command.LinuxCommandBuilder;
  24. import org.apache.reef.runtime.azbatch.util.command.WindowsCommandBuilder;
  25. import org.apache.reef.tang.formats.ConfigurationModule;
  26. import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
  27. import org.apache.reef.wake.remote.ports.parameters.TcpPortSet;
  28. /**
  29. * Class that builds the ConfigurationModule for Azure Batch runtime.
  30. */
  31. @Private
  32. public final class AzureBatchRuntimeConfigurationCreator {
  33. /**
  34. * The ConfigurationModule for Azure Batch.
  35. */
  36. private static ConfigurationModule conf;
  37. /**
  38. * Get or create a {@link ConfigurationModule} for the Azure Batch runtime.
  39. *
  40. * @param isWindows true if Azure Batch pool nodes run Windows, false otherwise.
  41. * @return the configuration module object.
  42. */
  43. public static ConfigurationModule getOrCreateAzureBatchRuntimeConfiguration(
  44. final boolean isWindows) {
  45. if (AzureBatchRuntimeConfigurationCreator.conf == null) {
  46. ConfigurationModuleBuilder builder = AzureBatchRuntimeConfigurationStatic.CONF;
  47. if (isWindows) {
  48. builder = builder.bindImplementation(CommandBuilder.class, WindowsCommandBuilder.class);
  49. } else {
  50. builder = builder.bindImplementation(CommandBuilder.class, LinuxCommandBuilder.class);
  51. }
  52. AzureBatchRuntimeConfigurationCreator.conf = new AzureBatchRuntimeConfiguration()
  53. .merge(builder.build())
  54. .bindNamedParameter(AzureBatchAccountName.class, AzureBatchRuntimeConfiguration.AZURE_BATCH_ACCOUNT_NAME)
  55. .bindNamedParameter(AzureBatchAccountUri.class, AzureBatchRuntimeConfiguration.AZURE_BATCH_ACCOUNT_URI)
  56. .bindNamedParameter(AzureBatchAccountKey.class, AzureBatchRuntimeConfiguration.AZURE_BATCH_ACCOUNT_KEY)
  57. .bindNamedParameter(AzureBatchPoolId.class, AzureBatchRuntimeConfiguration.AZURE_BATCH_POOL_ID)
  58. .bindNamedParameter(AzureStorageAccountName.class, AzureBatchRuntimeConfiguration.AZURE_STORAGE_ACCOUNT_NAME)
  59. .bindNamedParameter(AzureStorageAccountKey.class, AzureBatchRuntimeConfiguration.AZURE_STORAGE_ACCOUNT_KEY)
  60. .bindNamedParameter(ContainerRegistryServer.class, AzureBatchRuntimeConfiguration.CONTAINER_REGISTRY_SERVER)
  61. .bindNamedParameter(
  62. ContainerRegistryUsername.class, AzureBatchRuntimeConfiguration.CONTAINER_REGISTRY_USERNAME)
  63. .bindNamedParameter(
  64. ContainerRegistryPassword.class, AzureBatchRuntimeConfiguration.CONTAINER_REGISTRY_PASSWORD)
  65. .bindNamedParameter(ContainerImageName.class, AzureBatchRuntimeConfiguration.CONTAINER_IMAGE_NAME)
  66. .bindNamedParameter(
  67. AzureStorageContainerName.class, AzureBatchRuntimeConfiguration.AZURE_STORAGE_CONTAINER_NAME)
  68. .bindSetEntry(TcpPortSet.class, AzureBatchRuntimeConfiguration.TCP_PORT_SET)
  69. .build();
  70. }
  71. return AzureBatchRuntimeConfigurationCreator.conf;
  72. }
  73. /*
  74. * Private constructor since this is a utility class.
  75. */
  76. private AzureBatchRuntimeConfigurationCreator() {
  77. }
  78. }