This project has retired. For details please refer to its Attic page.
Source code
001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.runtime.hdinsight.client;
020
021import org.apache.reef.runtime.hdinsight.parameters.*;
022import org.apache.reef.tang.Configuration;
023import org.apache.reef.tang.Configurations;
024import org.apache.reef.tang.formats.AvroConfigurationSerializer;
025import org.apache.reef.tang.formats.ConfigurationModule;
026import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
027import org.apache.reef.tang.formats.RequiredParameter;
028
029import java.io.File;
030import java.io.IOException;
031
032/**
033 * Configuration module to setup REEF to submit jobs to HDInsight.
034 */
035public final class HDInsightRuntimeConfiguration extends ConfigurationModuleBuilder {
036
037  /**
038   * The URL of the hdinsight web service. E.g. http://services.mycompany.com:1234/templeton/v1/
039   */
040  public static final RequiredParameter<String> URL = new RequiredParameter<>();
041
042  /**
043   * The Storage account to be used by Azure.
044   */
045  public static final RequiredParameter<String> STORAGE_ACCOUNT_NAME = new RequiredParameter<>();
046
047  /**
048   * The Storage account key to be used by Azure.
049   */
050  public static final RequiredParameter<String> STORAGE_ACCOUNT_KEY = new RequiredParameter<>();
051
052  /**
053   * The Container name to be used by Azure.
054   */
055  public static final RequiredParameter<String> CONTAINER_NAME = new RequiredParameter<>();
056
057  /**
058   * The username to be used for connecting to hdinsight.
059   */
060  public static final RequiredParameter<String> USER_NAME = new RequiredParameter<>();
061
062  /**
063   * The password to be used for connecting to hdinsight.
064   */
065  public static final RequiredParameter<String> PASSWORD = new RequiredParameter<>();
066
067  /**
068   * The environment variable that holds the path to the default configuration file
069   */
070  public static final String HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE = "REEF_HDI_CONF";
071
072  public static final ConfigurationModule CONF = new HDInsightRuntimeConfiguration()
073      .merge(HDInsightRuntimeConfigurationStatic.CONF)
074      .bindNamedParameter(AzureStorageAccountName.class, STORAGE_ACCOUNT_NAME)
075      .bindNamedParameter(AzureStorageAccountKey.class, STORAGE_ACCOUNT_KEY)
076      .bindNamedParameter(AzureStorageAccountContainerName.class, CONTAINER_NAME)
077      .bindNamedParameter(HDInsightInstanceURL.class, URL)
078      .bindNamedParameter(HDInsightUsername.class, USER_NAME)
079      .bindNamedParameter(HDInsightPassword.class, PASSWORD)
080      .build();
081
082  /**
083   * Returns a HDInsight runtime configuration from the credentials stored in the given file.
084   *
085   * @param file
086   * @return a HDInsight runtime configuration from the credentials stored in the given file.
087   * @throws IOException if the file can't be read
088   */
089  public static Configuration fromTextFile(final File file) throws IOException {
090    final Configuration loaded = new AvroConfigurationSerializer().fromTextFile(file);
091    final Configuration staticConfiguration = HDInsightRuntimeConfigurationStatic.CONF.build();
092    return Configurations.merge(loaded, staticConfiguration);
093  }
094
095  /**
096   * @return the RuntimeConfiguration that is stored in a file refered to
097   * by the environment variable HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE.
098   * @throws IOException
099   * @see HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE
100   */
101  public static Configuration fromEnvironment() throws IOException {
102
103    final String configurationPath =
104        System.getenv(HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE);
105
106    if (null == configurationPath) {
107      throw new IOException("Environment Variable " +
108          HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE +
109          " not set.");
110    }
111
112    final File configurationFile = new File(configurationPath);
113    if (!configurationFile.canRead()) {
114      throw new IOException("Environment Variable " +
115          HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE +
116          " points to a file " + configurationFile.getAbsolutePath() +
117          " which can't be read."
118      );
119    }
120
121    return fromTextFile(configurationFile);
122  }
123}