@Test public void testValidateInstanceDefinition() throws Exception { AgentClientProvider provider = new AgentClientProvider(null); AggregateConf instanceDefinition = new AggregateConf(); try { provider.validateInstanceDefinition(instanceDefinition, null); Assert.assertFalse("Should fail with BadConfigException", true); } catch (BadConfigException e) { log.info(e.toString()); Assert.assertTrue(e.getMessage().contains("Application definition must be provided")); } }
@Override public void validateInstanceDefinition(AggregateConf instanceDefinition, SliderFileSystem fs) throws SliderException { super.validateInstanceDefinition(instanceDefinition, fs); log.debug("Validating conf {}", instanceDefinition); ConfTreeOperations resources = instanceDefinition.getResourceOperations(); providerUtils.validateNodeCount(instanceDefinition, ROLE_NODE, 0, -1); String appDef = null; try { appDef = SliderUtils.getApplicationDefinitionPath(instanceDefinition .getAppConfOperations()); } catch (BadConfigException bce) { throw new BadConfigException("Application definition must be provided. " + bce.getMessage()); } log.info("Validating app definition {}", appDef); String extension = appDef.substring(appDef.lastIndexOf(".") + 1, appDef.length()); if (!"zip".equals(extension.toLowerCase(Locale.ENGLISH))) { throw new BadConfigException("App definition must be packaged as a .zip file. File provided is " + appDef); } Set<String> names = resources.getComponentNames(); names.remove(SliderKeys.COMPONENT_AM); Map<Integer, String> priorityMap = new HashMap<Integer, String>(); for (String name : names) { try { appDef = SliderUtils.getApplicationDefinitionPath(instanceDefinition .getAppConfOperations(), name); } catch (BadConfigException bce) { throw new BadConfigException("Application definition must be provided. " + bce.getMessage()); } Metainfo metaInfo = getMetainfo(fs, appDef); MapOperations component = resources.getMandatoryComponent(name); if (metaInfo != null) { Component componentDef = metaInfo.getApplicationComponent( AgentUtils.getMetainfoComponentName(name, instanceDefinition.getAppConfOperations())); if (componentDef == null) { throw new BadConfigException( "Component %s is not a member of application.", name); } } int priority = component.getMandatoryOptionInt(ResourceKeys.COMPONENT_PRIORITY); if (priority <= 0) { throw new BadConfigException("Component %s %s value out of range %d", name, ResourceKeys.COMPONENT_PRIORITY, priority); } String existing = priorityMap.get(priority); if (existing != null) { throw new BadConfigException( "Component %s has a %s value %d which duplicates that of %s", name, ResourceKeys.COMPONENT_PRIORITY, priority, existing); } priorityMap.put(priority, name); if (metaInfo != null) { Component componentDef = metaInfo.getApplicationComponent( AgentUtils.getMetainfoComponentName(name, instanceDefinition.getAppConfOperations())); if ("CLIENT".equals(componentDef.getCategory())) { MapOperations componentConfig = resources.getMandatoryComponent(name); int count = componentConfig.getMandatoryOptionInt(ResourceKeys.COMPONENT_INSTANCES); if (count > 0) { throw new BadConfigException("Component %s is of type CLIENT and cannot be instantiated." + " Use \"slider client install ...\" command instead.", name); } } else { MapOperations componentConfig = resources.getMandatoryComponent(name); int count = componentConfig.getMandatoryOptionInt(ResourceKeys.COMPONENT_INSTANCES); int definedMinCount = componentDef.getMinInstanceCountInt(); int definedMaxCount = componentDef.getMaxInstanceCountInt(); if (count < definedMinCount || count > definedMaxCount) { throw new BadConfigException("Component %s, %s value %d out of range. " + "Expected minimum is %d and maximum is %d", name, ResourceKeys.COMPONENT_INSTANCES, count, definedMinCount, definedMaxCount); } } } } }
AgentClientProvider extends AbstractClientProvider implements AgentKeys, SliderKeys { @Override public void validateInstanceDefinition(AggregateConf instanceDefinition, SliderFileSystem fs) throws SliderException { super.validateInstanceDefinition(instanceDefinition, fs); log.debug("Validating conf {}", instanceDefinition); ConfTreeOperations resources = instanceDefinition.getResourceOperations(); providerUtils.validateNodeCount(instanceDefinition, ROLE_NODE, 0, -1); String appDef = null; try { appDef = SliderUtils.getApplicationDefinitionPath(instanceDefinition .getAppConfOperations()); } catch (BadConfigException bce) { throw new BadConfigException("Application definition must be provided. " + bce.getMessage()); } log.info("Validating app definition {}", appDef); String extension = appDef.substring(appDef.lastIndexOf(".") + 1, appDef.length()); if (!"zip".equals(extension.toLowerCase(Locale.ENGLISH))) { throw new BadConfigException("App definition must be packaged as a .zip file. File provided is " + appDef); } Set<String> names = resources.getComponentNames(); names.remove(SliderKeys.COMPONENT_AM); Map<Integer, String> priorityMap = new HashMap<Integer, String>(); for (String name : names) { try { appDef = SliderUtils.getApplicationDefinitionPath(instanceDefinition .getAppConfOperations(), name); } catch (BadConfigException bce) { throw new BadConfigException("Application definition must be provided. " + bce.getMessage()); } Metainfo metaInfo = getMetainfo(fs, appDef); MapOperations component = resources.getMandatoryComponent(name); if (metaInfo != null) { Component componentDef = metaInfo.getApplicationComponent( AgentUtils.getMetainfoComponentName(name, instanceDefinition.getAppConfOperations())); if (componentDef == null) { throw new BadConfigException( "Component %s is not a member of application.", name); } } int priority = component.getMandatoryOptionInt(ResourceKeys.COMPONENT_PRIORITY); if (priority <= 0) { throw new BadConfigException("Component %s %s value out of range %d", name, ResourceKeys.COMPONENT_PRIORITY, priority); } String existing = priorityMap.get(priority); if (existing != null) { throw new BadConfigException( "Component %s has a %s value %d which duplicates that of %s", name, ResourceKeys.COMPONENT_PRIORITY, priority, existing); } priorityMap.put(priority, name); if (metaInfo != null) { Component componentDef = metaInfo.getApplicationComponent( AgentUtils.getMetainfoComponentName(name, instanceDefinition.getAppConfOperations())); if ("CLIENT".equals(componentDef.getCategory())) { MapOperations componentConfig = resources.getMandatoryComponent(name); int count = componentConfig.getMandatoryOptionInt(ResourceKeys.COMPONENT_INSTANCES); if (count > 0) { throw new BadConfigException("Component %s is of type CLIENT and cannot be instantiated." + " Use \"slider client install ...\" command instead.", name); } } else { MapOperations componentConfig = resources.getMandatoryComponent(name); int count = componentConfig.getMandatoryOptionInt(ResourceKeys.COMPONENT_INSTANCES); int definedMinCount = componentDef.getMinInstanceCountInt(); int definedMaxCount = componentDef.getMaxInstanceCountInt(); if (count < definedMinCount || count > definedMaxCount) { throw new BadConfigException("Component %s, %s value %d out of range. " + "Expected minimum is %d and maximum is %d", name, ResourceKeys.COMPONENT_INSTANCES, count, definedMinCount, definedMaxCount); } } } } } }
AgentClientProvider extends AbstractClientProvider implements AgentKeys, SliderKeys { @Override public void validateInstanceDefinition(AggregateConf instanceDefinition, SliderFileSystem fs) throws SliderException { super.validateInstanceDefinition(instanceDefinition, fs); log.debug("Validating conf {}", instanceDefinition); ConfTreeOperations resources = instanceDefinition.getResourceOperations(); providerUtils.validateNodeCount(instanceDefinition, ROLE_NODE, 0, -1); String appDef = null; try { appDef = SliderUtils.getApplicationDefinitionPath(instanceDefinition .getAppConfOperations()); } catch (BadConfigException bce) { throw new BadConfigException("Application definition must be provided. " + bce.getMessage()); } log.info("Validating app definition {}", appDef); String extension = appDef.substring(appDef.lastIndexOf(".") + 1, appDef.length()); if (!"zip".equals(extension.toLowerCase(Locale.ENGLISH))) { throw new BadConfigException("App definition must be packaged as a .zip file. File provided is " + appDef); } Set<String> names = resources.getComponentNames(); names.remove(SliderKeys.COMPONENT_AM); Map<Integer, String> priorityMap = new HashMap<Integer, String>(); for (String name : names) { try { appDef = SliderUtils.getApplicationDefinitionPath(instanceDefinition .getAppConfOperations(), name); } catch (BadConfigException bce) { throw new BadConfigException("Application definition must be provided. " + bce.getMessage()); } Metainfo metaInfo = getMetainfo(fs, appDef); MapOperations component = resources.getMandatoryComponent(name); if (metaInfo != null) { Component componentDef = metaInfo.getApplicationComponent( AgentUtils.getMetainfoComponentName(name, instanceDefinition.getAppConfOperations())); if (componentDef == null) { throw new BadConfigException( "Component %s is not a member of application.", name); } } int priority = component.getMandatoryOptionInt(ResourceKeys.COMPONENT_PRIORITY); if (priority <= 0) { throw new BadConfigException("Component %s %s value out of range %d", name, ResourceKeys.COMPONENT_PRIORITY, priority); } String existing = priorityMap.get(priority); if (existing != null) { throw new BadConfigException( "Component %s has a %s value %d which duplicates that of %s", name, ResourceKeys.COMPONENT_PRIORITY, priority, existing); } priorityMap.put(priority, name); if (metaInfo != null) { Component componentDef = metaInfo.getApplicationComponent( AgentUtils.getMetainfoComponentName(name, instanceDefinition.getAppConfOperations())); if ("CLIENT".equals(componentDef.getCategory())) { MapOperations componentConfig = resources.getMandatoryComponent(name); int count = componentConfig.getMandatoryOptionInt(ResourceKeys.COMPONENT_INSTANCES); if (count > 0) { throw new BadConfigException("Component %s is of type CLIENT and cannot be instantiated." + " Use \"slider client install ...\" command instead.", name); } } else { MapOperations componentConfig = resources.getMandatoryComponent(name); int count = componentConfig.getMandatoryOptionInt(ResourceKeys.COMPONENT_INSTANCES); int definedMinCount = componentDef.getMinInstanceCountInt(); int definedMaxCount = componentDef.getMaxInstanceCountInt(); if (count < definedMinCount || count > definedMaxCount) { throw new BadConfigException("Component %s, %s value %d out of range. " + "Expected minimum is %d and maximum is %d", name, ResourceKeys.COMPONENT_INSTANCES, count, definedMinCount, definedMaxCount); } } } } } protected  AgentClientProvider(Configuration conf); }
AgentClientProvider extends AbstractClientProvider implements AgentKeys, SliderKeys { @Override public void validateInstanceDefinition(AggregateConf instanceDefinition, SliderFileSystem fs) throws SliderException { super.validateInstanceDefinition(instanceDefinition, fs); log.debug("Validating conf {}", instanceDefinition); ConfTreeOperations resources = instanceDefinition.getResourceOperations(); providerUtils.validateNodeCount(instanceDefinition, ROLE_NODE, 0, -1); String appDef = null; try { appDef = SliderUtils.getApplicationDefinitionPath(instanceDefinition .getAppConfOperations()); } catch (BadConfigException bce) { throw new BadConfigException("Application definition must be provided. " + bce.getMessage()); } log.info("Validating app definition {}", appDef); String extension = appDef.substring(appDef.lastIndexOf(".") + 1, appDef.length()); if (!"zip".equals(extension.toLowerCase(Locale.ENGLISH))) { throw new BadConfigException("App definition must be packaged as a .zip file. File provided is " + appDef); } Set<String> names = resources.getComponentNames(); names.remove(SliderKeys.COMPONENT_AM); Map<Integer, String> priorityMap = new HashMap<Integer, String>(); for (String name : names) { try { appDef = SliderUtils.getApplicationDefinitionPath(instanceDefinition .getAppConfOperations(), name); } catch (BadConfigException bce) { throw new BadConfigException("Application definition must be provided. " + bce.getMessage()); } Metainfo metaInfo = getMetainfo(fs, appDef); MapOperations component = resources.getMandatoryComponent(name); if (metaInfo != null) { Component componentDef = metaInfo.getApplicationComponent( AgentUtils.getMetainfoComponentName(name, instanceDefinition.getAppConfOperations())); if (componentDef == null) { throw new BadConfigException( "Component %s is not a member of application.", name); } } int priority = component.getMandatoryOptionInt(ResourceKeys.COMPONENT_PRIORITY); if (priority <= 0) { throw new BadConfigException("Component %s %s value out of range %d", name, ResourceKeys.COMPONENT_PRIORITY, priority); } String existing = priorityMap.get(priority); if (existing != null) { throw new BadConfigException( "Component %s has a %s value %d which duplicates that of %s", name, ResourceKeys.COMPONENT_PRIORITY, priority, existing); } priorityMap.put(priority, name); if (metaInfo != null) { Component componentDef = metaInfo.getApplicationComponent( AgentUtils.getMetainfoComponentName(name, instanceDefinition.getAppConfOperations())); if ("CLIENT".equals(componentDef.getCategory())) { MapOperations componentConfig = resources.getMandatoryComponent(name); int count = componentConfig.getMandatoryOptionInt(ResourceKeys.COMPONENT_INSTANCES); if (count > 0) { throw new BadConfigException("Component %s is of type CLIENT and cannot be instantiated." + " Use \"slider client install ...\" command instead.", name); } } else { MapOperations componentConfig = resources.getMandatoryComponent(name); int count = componentConfig.getMandatoryOptionInt(ResourceKeys.COMPONENT_INSTANCES); int definedMinCount = componentDef.getMinInstanceCountInt(); int definedMaxCount = componentDef.getMaxInstanceCountInt(); if (count < definedMinCount || count > definedMaxCount) { throw new BadConfigException("Component %s, %s value %d out of range. " + "Expected minimum is %d and maximum is %d", name, ResourceKeys.COMPONENT_INSTANCES, count, definedMinCount, definedMaxCount); } } } } } protected  AgentClientProvider(Configuration conf); @Override String getName(); @Override List<ProviderRole> getRoles(); @Override //Client void preflightValidateClusterConfiguration(SliderFileSystem sliderFileSystem,
                                                    String clustername,
                                                    Configuration configuration,
                                                    AggregateConf instanceDefinition,
                                                    Path clusterDirPath,
                                                    Path generatedConfDirPath,
                                                    boolean secure); @Override void validateInstanceDefinition(AggregateConf instanceDefinition, SliderFileSystem fs); @Override void prepareAMAndConfigForLaunch(SliderFileSystem fileSystem,
                                          Configuration serviceConf,
                                          AbstractLauncher launcher,
                                          AggregateConf instanceDefinition,
                                          Path snapshotConfDirPath,
                                          Path generatedConfDirPath,
                                          Configuration clientConfExtras,
                                          String libdir,
                                          Path tempPath,
                                          boolean miniClusterTestRun); @Override Set<String> getApplicationTags(SliderFileSystem fileSystem,
                                        String appDef); @Override void processClientOperation(SliderFileSystem fileSystem,
                                     RegistryOperations rops,
                                     Configuration configuration,
                                     String operation,
                                     File clientInstallPath,
                                     File appPackage,
                                     JSONObject config,
                                     String name); }
AgentClientProvider extends AbstractClientProvider implements AgentKeys, SliderKeys { @Override public void validateInstanceDefinition(AggregateConf instanceDefinition, SliderFileSystem fs) throws SliderException { super.validateInstanceDefinition(instanceDefinition, fs); log.debug("Validating conf {}", instanceDefinition); ConfTreeOperations resources = instanceDefinition.getResourceOperations(); providerUtils.validateNodeCount(instanceDefinition, ROLE_NODE, 0, -1); String appDef = null; try { appDef = SliderUtils.getApplicationDefinitionPath(instanceDefinition .getAppConfOperations()); } catch (BadConfigException bce) { throw new BadConfigException("Application definition must be provided. " + bce.getMessage()); } log.info("Validating app definition {}", appDef); String extension = appDef.substring(appDef.lastIndexOf(".") + 1, appDef.length()); if (!"zip".equals(extension.toLowerCase(Locale.ENGLISH))) { throw new BadConfigException("App definition must be packaged as a .zip file. File provided is " + appDef); } Set<String> names = resources.getComponentNames(); names.remove(SliderKeys.COMPONENT_AM); Map<Integer, String> priorityMap = new HashMap<Integer, String>(); for (String name : names) { try { appDef = SliderUtils.getApplicationDefinitionPath(instanceDefinition .getAppConfOperations(), name); } catch (BadConfigException bce) { throw new BadConfigException("Application definition must be provided. " + bce.getMessage()); } Metainfo metaInfo = getMetainfo(fs, appDef); MapOperations component = resources.getMandatoryComponent(name); if (metaInfo != null) { Component componentDef = metaInfo.getApplicationComponent( AgentUtils.getMetainfoComponentName(name, instanceDefinition.getAppConfOperations())); if (componentDef == null) { throw new BadConfigException( "Component %s is not a member of application.", name); } } int priority = component.getMandatoryOptionInt(ResourceKeys.COMPONENT_PRIORITY); if (priority <= 0) { throw new BadConfigException("Component %s %s value out of range %d", name, ResourceKeys.COMPONENT_PRIORITY, priority); } String existing = priorityMap.get(priority); if (existing != null) { throw new BadConfigException( "Component %s has a %s value %d which duplicates that of %s", name, ResourceKeys.COMPONENT_PRIORITY, priority, existing); } priorityMap.put(priority, name); if (metaInfo != null) { Component componentDef = metaInfo.getApplicationComponent( AgentUtils.getMetainfoComponentName(name, instanceDefinition.getAppConfOperations())); if ("CLIENT".equals(componentDef.getCategory())) { MapOperations componentConfig = resources.getMandatoryComponent(name); int count = componentConfig.getMandatoryOptionInt(ResourceKeys.COMPONENT_INSTANCES); if (count > 0) { throw new BadConfigException("Component %s is of type CLIENT and cannot be instantiated." + " Use \"slider client install ...\" command instead.", name); } } else { MapOperations componentConfig = resources.getMandatoryComponent(name); int count = componentConfig.getMandatoryOptionInt(ResourceKeys.COMPONENT_INSTANCES); int definedMinCount = componentDef.getMinInstanceCountInt(); int definedMaxCount = componentDef.getMaxInstanceCountInt(); if (count < definedMinCount || count > definedMaxCount) { throw new BadConfigException("Component %s, %s value %d out of range. " + "Expected minimum is %d and maximum is %d", name, ResourceKeys.COMPONENT_INSTANCES, count, definedMinCount, definedMaxCount); } } } } } protected  AgentClientProvider(Configuration conf); @Override String getName(); @Override List<ProviderRole> getRoles(); @Override //Client void preflightValidateClusterConfiguration(SliderFileSystem sliderFileSystem,
                                                    String clustername,
                                                    Configuration configuration,
                                                    AggregateConf instanceDefinition,
                                                    Path clusterDirPath,
                                                    Path generatedConfDirPath,
                                                    boolean secure); @Override void validateInstanceDefinition(AggregateConf instanceDefinition, SliderFileSystem fs); @Override void prepareAMAndConfigForLaunch(SliderFileSystem fileSystem,
                                          Configuration serviceConf,
                                          AbstractLauncher launcher,
                                          AggregateConf instanceDefinition,
                                          Path snapshotConfDirPath,
                                          Path generatedConfDirPath,
                                          Configuration clientConfExtras,
                                          String libdir,
                                          Path tempPath,
                                          boolean miniClusterTestRun); @Override Set<String> getApplicationTags(SliderFileSystem fileSystem,
                                        String appDef); @Override void processClientOperation(SliderFileSystem fileSystem,
                                     RegistryOperations rops,
                                     Configuration configuration,
                                     String operation,
                                     File clientInstallPath,
                                     File appPackage,
                                     JSONObject config,
                                     String name); static final String E_COULD_NOT_READ_METAINFO; }