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.formats.AvroConfigurationSerializer; 024import org.apache.reef.tang.formats.ConfigurationModule; 025import org.apache.reef.tang.formats.ConfigurationModuleBuilder; 026import org.apache.reef.tang.formats.RequiredParameter; 027 028import java.io.File; 029import java.io.IOException; 030 031/** 032 * Same as HDInsightRuntimeConfiguration, but ignores SSL errors on submission. 033 */ 034public final class UnsafeHDInsightRuntimeConfiguration extends ConfigurationModuleBuilder { 035 036 /** 037 * The URL of the hdinsight web service. E.g. http://services.mycompany.com:1234/templeton/v1/ 038 */ 039 public static final RequiredParameter<String> URL = new RequiredParameter<>(); 040 041 /** 042 * The Storage account to be used by Azure. 043 */ 044 public static final RequiredParameter<String> STORAGE_ACCOUNT_NAME = new RequiredParameter<>(); 045 046 /** 047 * The Storage account key to be used by Azure. 048 */ 049 public static final RequiredParameter<String> STORAGE_ACCOUNT_KEY = new RequiredParameter<>(); 050 051 /** 052 * The Container name to be used by Azure. 053 */ 054 public static final RequiredParameter<String> CONTAINER_NAME = new RequiredParameter<>(); 055 056 /** 057 * The username to be used for connecting to hdinsight. 058 */ 059 public static final RequiredParameter<String> USER_NAME = new RequiredParameter<>(); 060 061 /** 062 * The password to be used for connecting to hdinsight. 063 */ 064 public static final RequiredParameter<String> PASSWORD = new RequiredParameter<>(); 065 066 public static final ConfigurationModule CONF = new UnsafeHDInsightRuntimeConfiguration() 067 .merge(UnsafeHDInsightRuntimeConfigurationStatic.CONF) 068 .bindNamedParameter(AzureStorageAccountName.class, STORAGE_ACCOUNT_NAME) 069 .bindNamedParameter(AzureStorageAccountKey.class, STORAGE_ACCOUNT_KEY) 070 .bindNamedParameter(AzureStorageAccountContainerName.class, CONTAINER_NAME) 071 .bindNamedParameter(HDInsightInstanceURL.class, URL) 072 .bindNamedParameter(HDInsightUsername.class, USER_NAME) 073 .bindNamedParameter(HDInsightPassword.class, PASSWORD) 074 .build(); 075 076 /** 077 * Returns an UNSAFE HDInsight runtime configuration from the credentials stored in the given file. 078 * 079 * @param file 080 * @return an UNSAFE HDInsight runtime configuration from the credentials stored in the given file. 081 * @throws java.io.IOException if the file can't be read 082 */ 083 public static Configuration fromTextFile(final File file) throws IOException { 084 return new AvroConfigurationSerializer().fromTextFile(file); 085 } 086 087 /** 088 * @return the RuntimeConfiguration that is stored in a file refered to by the environment 089 * variable HDInsightRuntimeConfiguration.HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE. 090 * @throws IOException 091 * @see HDInsightRuntimeConfiguration#HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE 092 */ 093 public static Configuration fromEnvironment() throws IOException { 094 095 final String configurationPath = System.getenv( 096 HDInsightRuntimeConfiguration.HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE); 097 098 if (null == configurationPath) { 099 throw new IOException("Environment Variable " + 100 HDInsightRuntimeConfiguration.HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE + 101 " not set."); 102 } 103 104 final File configurationFile = new File(configurationPath); 105 if (!configurationFile.canRead()) { 106 throw new IOException("Environment Variable " + 107 HDInsightRuntimeConfiguration.HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE + 108 " points to a file " + configurationFile.getAbsolutePath() + 109 " which can't be read." 110 ); 111 } 112 113 return fromTextFile(configurationFile); 114 } 115}