public ConfTreeOperations(ConfTree confTree) { assert confTree != null : "null tree"; assert confTree.components != null : "null tree components"; this.confTree = confTree; globalOptions = new MapOperations("global", confTree.global); }
public ConfTreeOperations(ConfTree confTree) { assert confTree != null : "null tree"; assert confTree.components != null : "null tree components"; this.confTree = confTree; globalOptions = new MapOperations("global", confTree.global); }
/** * look up a component and return its options * @param component component name * @return component mapping or null */ public MapOperations getComponent(String component) { Map<String, String> instance = confTree.components.get(component); if (instance != null) { return new MapOperations(component, instance); } return null; }
/** * look up a component and return its options * @param component component name * @return component mapping or null */ public MapOperations getComponent(String component) { Map<String, String> instance = confTree.components.get(component); if (instance != null) { return new MapOperations(component, instance); } return null; }
/** * look up a component and return its options with the specified replacements * @param component component name * @param replacementOptions replacement options * @return component mapping or null */ public MapOperations getComponent(String component, Map<String,String> replacementOptions) { Map<String, String> instance = confTree.components.get(component); if (instance != null) { Map<String, String> newInstance = new HashMap<>(); newInstance.putAll(instance); newInstance.putAll(replacementOptions); return new MapOperations(component, newInstance); } return null; }
/** * look up a component and return its options with the specified replacements * @param component component name * @param replacementOptions replacement options * @return component mapping or null */ public MapOperations getComponent(String component, Map<String,String> replacementOptions) { Map<String, String> instance = confTree.components.get(component); if (instance != null) { Map<String, String> newInstance = new HashMap<>(); newInstance.putAll(instance); newInstance.putAll(replacementOptions); return new MapOperations(component, newInstance); } return null; }
/** * Return the label expression and if not set null * @param map map to look up * @return extracted label or null */ public String extractLabelExpression(Map<String, String> map) { if (map != null) { MapOperations options = new MapOperations("", map); return options.getOption(ResourceKeys.YARN_LABEL_EXPRESSION, null); } return null; }
/** * Return the label expression and if not set null * @param map map to look up * @return extracted label or null */ public String extractLabelExpression(Map<String, String> map) { if (map != null) { MapOperations options = new MapOperations("", map); return options.getOption(ResourceKeys.YARN_LABEL_EXPRESSION, null); } return null; }
/** * Get a component -adding it to the components map if * none with that name exists * @param name role * @return role mapping */ public MapOperations getOrAddComponent(String name) { MapOperations operations = getComponent(name); if (operations != null) { return operations; } //create a new instances Map<String, String> map = new HashMap<>(); confTree.components.put(name, map); return new MapOperations(name, map); }
/** * Get a component -adding it to the components map if * none with that name exists * @param name role * @return role mapping */ public MapOperations getOrAddComponent(String name) { MapOperations operations = getComponent(name); if (operations != null) { return operations; } //create a new instances Map<String, String> map = new HashMap<>(); confTree.components.put(name, map); return new MapOperations(name, map); }
@Before public void setup() throws Exception { certMan = new CertificateManager(); MapOperations compOperations = new MapOperations(); secDir = new File(workDir.getRoot(), SliderKeys.SECURITY_DIR); File keystoreFile = new File(secDir, SliderKeys.KEYSTORE_FILE_NAME); compOperations.put(SliderXmlConfKeys.KEY_KEYSTORE_LOCATION, keystoreFile.getAbsolutePath()); certMan.initialize(compOperations, "cahost", null, null); }
@Before public void setup() throws Exception { certMan = new CertificateManager(); MapOperations compOperations = new MapOperations(); secDir = new File(workDir.getRoot(), SliderKeys.SECURITY_DIR); File keystoreFile = new File(secDir, SliderKeys.KEYSTORE_FILE_NAME); compOperations.put(SliderXmlConfKeys.KEY_KEYSTORE_LOCATION, keystoreFile.getAbsolutePath()); certMan.initialize(compOperations, "cahost", null, null); }
@BeforeClass public static void setupClass() throws SliderException { MapOperations configMap = new MapOperations(); SecurityUtils.initializeSecurityParameters(configMap, true); certificateManager = new CertificateManager(); certificateManager.initialize(configMap); String keystoreFile = SecurityUtils.getSecurityDir() + File.separator + SliderKeys.KEYSTORE_FILE_NAME; String password = SecurityUtils.getKeystorePass(); System.setProperty("javax.net.ssl.trustStore", keystoreFile); System.setProperty("javax.net.ssl.trustStorePassword", password); System.setProperty("javax.net.ssl.trustStoreType", "PKCS12"); }
@BeforeClass public static void setupClass() throws SliderException { MapOperations configMap = new MapOperations(); SecurityUtils.initializeSecurityParameters(configMap, true); certificateManager = new CertificateManager(); certificateManager.initialize(configMap); String keystoreFile = SecurityUtils.getSecurityDir() + File.separator + SliderKeys.KEYSTORE_FILE_NAME; String password = SecurityUtils.getKeystorePass(); System.setProperty("javax.net.ssl.trustStore", keystoreFile); System.setProperty("javax.net.ssl.trustStorePassword", password); System.setProperty("javax.net.ssl.trustStoreType", "PKCS12"); }
/** * Extract any resource requirements from this component's settings. * All fields that are set will override the existing values -if * unset that resource field will be left unchanged. * * Important: the configuration must already be fully resolved * in order to pick up global options. * @param resource resource to configure * @param map map of options */ public void extractResourceRequirements(Resource resource, Map<String, String> map) { if (map != null) { MapOperations options = new MapOperations("", map); resource.setMemory(options.getOptionInt(ResourceKeys.YARN_MEMORY, resource.getMemory())); resource.setVirtualCores(options.getOptionInt(ResourceKeys.YARN_CORES, resource.getVirtualCores())); } }
@Test public void testContainerStoresGenerationMisconfiguration() throws Exception { AggregateConf instanceDefinition = new AggregateConf(); MapOperations compOps = new MapOperations(); compOps.put(SliderKeys.COMP_STORES_REQUIRED_KEY, "true"); setupCredentials(instanceDefinition, "cant.be.found", null); try { StoresGenerator.generateSecurityStores("testhost", "container1", "component1", instanceDefinition, compOps); Assert.fail("SliderException should have been generated"); } catch (SliderException e) { // ignore - should be thrown } }
@Test public void testContainerStoresGenerationMisconfiguration() throws Exception { AggregateConf instanceDefinition = new AggregateConf(); MapOperations compOps = new MapOperations(); compOps.put(SliderKeys.COMP_STORES_REQUIRED_KEY, "true"); setupCredentials(instanceDefinition, "cant.be.found", null); try { StoresGenerator.generateSecurityStores("testhost", "container1", "component1", instanceDefinition, compOps); Assert.fail("SliderException should have been generated"); } catch (SliderException e) { // ignore - should be thrown } }
@Test public void testContainerKeystoreGenerationViaStoresGenerator() throws Exception { AggregateConf instanceDefinition = new AggregateConf(); MapOperations compOps = new MapOperations(); instanceDefinition.getAppConf().components.put("component1", compOps); compOps.put(SliderKeys.COMP_KEYSTORE_PASSWORD_PROPERTY_KEY, "app1.component1.password.property"); compOps.put(SliderKeys.COMP_STORES_REQUIRED_KEY, "true"); instanceDefinition.getAppConf().global.put( "app1.component1.password.property", "password"); instanceDefinition.resolve(); SecurityStore[] files = StoresGenerator.generateSecurityStores("testhost", "container1", "component1", instanceDefinition, compOps); assertEquals("wrong number of stores", 1, files.length); validateKeystore(files[0].getFile(), "testhost", "cahost"); }
@Test public void testContainerKeystoreGenerationViaStoresGeneratorUsingGlobalProps() throws Exception { AggregateConf instanceDefinition = new AggregateConf(); MapOperations compOps = new MapOperations(); instanceDefinition.getAppConf().components.put("component1", compOps); compOps.put(SliderKeys.COMP_KEYSTORE_PASSWORD_PROPERTY_KEY, "app1.component1.password.property"); instanceDefinition.getAppConf().global.put(SliderKeys.COMP_STORES_REQUIRED_KEY, "true"); compOps.put( "app1.component1.password.property", "password"); instanceDefinition.resolve(); SecurityStore[] files = StoresGenerator.generateSecurityStores("testhost", "container1", "component1", instanceDefinition, compOps); assertEquals("wrong number of stores", 1, files.length); validateKeystore(files[0].getFile(), "testhost", "cahost"); }
@Test public void testContainerKeystoreGenerationViaStoresGenerator() throws Exception { AggregateConf instanceDefinition = new AggregateConf(); MapOperations compOps = new MapOperations(); instanceDefinition.getAppConf().components.put("component1", compOps); compOps.put(SliderKeys.COMP_KEYSTORE_PASSWORD_PROPERTY_KEY, "app1.component1.password.property"); compOps.put(SliderKeys.COMP_STORES_REQUIRED_KEY, "true"); instanceDefinition.getAppConf().global.put( "app1.component1.password.property", "password"); instanceDefinition.resolve(); SecurityStore[] files = StoresGenerator.generateSecurityStores("testhost", "container1", "component1", instanceDefinition, compOps); assertEquals("wrong number of stores", 1, files.length); validateKeystore(files[0].getFile(), "testhost", "cahost"); }