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 * Same as HDInsightRuntimeConfiguration, but ignores SSL errors on submission. 034 */ 035public final class UnsafeHDInsightRuntimeConfiguration 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 public static final ConfigurationModule CONF = new UnsafeHDInsightRuntimeConfiguration() 068 .merge(UnsafeHDInsightRuntimeConfigurationStatic.CONF) 069 .bindNamedParameter(AzureStorageAccountName.class, STORAGE_ACCOUNT_NAME) 070 .bindNamedParameter(AzureStorageAccountKey.class, STORAGE_ACCOUNT_KEY) 071 .bindNamedParameter(AzureStorageAccountContainerName.class, CONTAINER_NAME) 072 .bindNamedParameter(HDInsightInstanceURL.class, URL) 073 .bindNamedParameter(HDInsightUsername.class, USER_NAME) 074 .bindNamedParameter(HDInsightPassword.class, PASSWORD) 075 .build(); 076 077 /** 078 * Returns an UNSAFE HDInsight runtime configuration from the credentials stored in the given file. 079 * 080 * @param file 081 * @return an UNSAFE HDInsight runtime configuration from the credentials stored in the given file. 082 * @throws java.io.IOException if the file can't be read 083 */ 084 public static Configuration fromTextFile(final File file) throws IOException { 085 final Configuration loaded = new AvroConfigurationSerializer().fromTextFile(file); 086 final Configuration staticConfiguration = UnsafeHDInsightRuntimeConfigurationStatic.CONF.build(); 087 return Configurations.merge(loaded, staticConfiguration); 088 } 089 090 /** 091 * @return the RuntimeConfiguration that is stored in a file refered to by the environment 092 * variable HDInsightRuntimeConfiguration.HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE. 093 * @throws IOException 094 * @see HDInsightRuntimeConfiguration.HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE 095 */ 096 public static Configuration fromEnvironment() throws IOException { 097 098 final String configurationPath = System.getenv( 099 HDInsightRuntimeConfiguration.HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE); 100 101 if (null == configurationPath) { 102 throw new IOException("Environment Variable " + 103 HDInsightRuntimeConfiguration.HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE + 104 " not set."); 105 } 106 107 final File configurationFile = new File(configurationPath); 108 if (!configurationFile.canRead()) { 109 throw new IOException("Environment Variable " + 110 HDInsightRuntimeConfiguration.HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE + 111 " points to a file " + configurationFile.getAbsolutePath() + 112 " which can't be read." 113 ); 114 } 115 116 return fromTextFile(configurationFile); 117 } 118}