-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GOBBLIN-2172] Enable launching GoT YARN AM and workers with proxy HT…
…TPS host+port (#4075)
- Loading branch information
1 parent
13a6926
commit 4bb0c40
Showing
7 changed files
with
160 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
gobblin-utility/src/main/java/org/apache/gobblin/util/AzkabanLauncherUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.gobblin.util; | ||
|
||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
|
||
import com.google.common.base.Splitter; | ||
import com.google.common.collect.ImmutableBiMap; | ||
|
||
/** | ||
* Utility class for Azkaban App Launcher. | ||
*/ | ||
public class AzkabanLauncherUtils { | ||
public static final String PLACEHOLDER_MAP_KEY = "placeholderMap"; | ||
|
||
/** | ||
* Reverts properties that were converted to placeholders back to their original values. | ||
* It checks if the properties contain placeholderMap key and, if so, uses it as an inverse map | ||
* to replace placeholder values with their original values. | ||
* | ||
* @param appProperties the properties object containing the application properties alongwith the inverse map | ||
* @return a new Properties object with placeholders reverted to their original values, or the original properties if no placeholderMap | ||
*/ | ||
public static Properties undoPlaceholderConversion(Properties appProperties) { | ||
if (StringUtils.EMPTY.equals(appProperties.getProperty(PLACEHOLDER_MAP_KEY, StringUtils.EMPTY))) { | ||
return appProperties; | ||
} | ||
|
||
Properties convertedProperties = new Properties(); | ||
convertedProperties.putAll(appProperties); | ||
|
||
// Undo properties converted to placeholders | ||
Map<String, String> inversePlaceholderMap = ImmutableBiMap.copyOf(Splitter.on(",").withKeyValueSeparator(":") | ||
.split(convertedProperties.get(PLACEHOLDER_MAP_KEY).toString())).inverse(); | ||
for (Map.Entry<Object, Object> entry : convertedProperties.entrySet()) { | ||
if (inversePlaceholderMap.containsKey(entry.getValue().toString())) { | ||
convertedProperties.put(entry.getKey(), inversePlaceholderMap.get(entry.getValue().toString())); | ||
} | ||
} | ||
return convertedProperties; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
gobblin-utility/src/test/java/org/apache/gobblin/AzkabanLauncherUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.gobblin; | ||
|
||
import java.util.Properties; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import org.apache.gobblin.util.AzkabanLauncherUtils; | ||
|
||
|
||
@Test | ||
public class AzkabanLauncherUtilsTest { | ||
|
||
@Test | ||
public void testPropertyPlaceholderReplacement() { | ||
Properties props = new Properties(); | ||
|
||
props.setProperty("placeholderMap", ":emptyStringPlaceholder, :spacePlaceholder,\\t:tabPlaceholder"); | ||
props.setProperty("key1", "emptyStringPlaceholder"); | ||
props.setProperty("key2", "spacePlaceholder"); | ||
props.setProperty("key3", "tabPlaceholder"); | ||
props.setProperty("key4", "someOtherValue"); | ||
props.setProperty("key5", "123emptyStringPlaceholder"); | ||
|
||
props = AzkabanLauncherUtils.undoPlaceholderConversion(props); | ||
Assert.assertEquals(props.get("key1").toString(), ""); | ||
Assert.assertEquals(props.get("key2").toString(), " "); | ||
Assert.assertEquals(props.get("key3").toString(), "\\t"); | ||
Assert.assertEquals(props.get("key4").toString(), "someOtherValue"); | ||
|
||
// should replace exact matches only | ||
Assert.assertEquals(props.get("key5").toString(), "123emptyStringPlaceholder"); | ||
} | ||
|
||
@Test | ||
public void testPlaceholderMapMissing() { | ||
Properties props = new Properties(); | ||
props.setProperty("key1", "emptyStringPlaceholder"); | ||
|
||
props = AzkabanLauncherUtils.undoPlaceholderConversion(props); | ||
Assert.assertEquals(props.get("key1").toString(), "emptyStringPlaceholder"); | ||
} | ||
|
||
@Test | ||
public void testEmptyPlaceholderMap() { | ||
Properties props = new Properties(); | ||
props.setProperty("placeholderMap", ""); | ||
props.setProperty("key1", "emptyStringPlaceholder"); | ||
|
||
props = AzkabanLauncherUtils.undoPlaceholderConversion(props); | ||
Assert.assertEquals(props.get("key1").toString(), "emptyStringPlaceholder"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters