@Override public Map<String, Object> getParameters() { return MapUtil.unmodifiable(parameters); }
public static <K, V> Map<K, V> castUnmodifiable(Map<?, ?> map) { return unmodifiable(MapUtil.<K, V> cast(map)); }
private static Map<String, Map<String, Object>> mergeBindingParameters( Map<String, Map<String, Object>> descriptorProvidedBindingParameters, Map<String, Map<String, Object>> fileProvidedBindingParameters) { Map<String, Map<String, Object>> bindingParameters = new HashMap<>(); Set<String> serviceNames = new HashSet<>(descriptorProvidedBindingParameters.keySet()); serviceNames.addAll(fileProvidedBindingParameters.keySet()); for (String serviceName : serviceNames) { bindingParameters.put(serviceName, MapUtil.mergeSafely(fileProvidedBindingParameters.get(serviceName), descriptorProvidedBindingParameters.get(serviceName))); } return bindingParameters; }
@SuppressWarnings("unchecked") protected Resource getResource(List<Map<String, Object>> parametersList) { if (!shouldCreateUserProvidedService(parametersList)) { return null; } String userProvidedServiceName = (String) getPropertyValue(parametersList, SupportedParameters.USER_PROVIDED_SERVICE_NAME, null); if (userProvidedServiceName == null || userProvidedServiceName.isEmpty()) { return null; } Map<String, Object> userProvidedServiceConfig = (Map<String, Object>) getPropertyValue(parametersList, SupportedParameters.USER_PROVIDED_SERVICE_CONFIG, Collections.emptyMap()); return createResource(userProvidedServiceName, MapUtil.asMap(SupportedParameters.SERVICE_CONFIG, userProvidedServiceConfig)); }
public Map<String, Object> validate(String prefix, Object container, Class<?> containerClass, Map<String, Object> parameters) { Map<String, Object> correctedParameters = new TreeMap<>(); for (ParameterValidator validator : parameterValidators) { if (!validator.getContainerType() .isAssignableFrom(containerClass)) { continue; } correctedParameters = correctInvalidSingleParameters(prefix, container, validator, parameters, correctedParameters); correctedParameters = correctInvalidPluralParameters(prefix, container, validator, parameters, correctedParameters); } return MapUtil.merge(parameters, correctedParameters); }
protected void addMtaMetadata(Map<String, Object> env) { Map<String, Object> mtaMetadata = new TreeMap<>(); MapUtil.addNonNull(mtaMetadata, Constants.ATTR_ID, deploymentDescriptor.getId()); MapUtil.addNonNull(mtaMetadata, Constants.ATTR_VERSION, deploymentDescriptor.getVersion()); MapUtil.addNonNull(mtaMetadata, Constants.ATTR_DESCRIPTION, deploymentDescriptor.getDescription()); MapUtil.addNonNull(mtaMetadata, Constants.ATTR_PROVIDER, deploymentDescriptor.getProvider()); MapUtil.addNonNull(mtaMetadata, Constants.ATTR_COPYRIGHT, deploymentDescriptor.getCopyright()); env.put(Constants.ENV_MTA_METADATA, mtaMetadata); }
public void updateApplicationEnvironment(String envPropertyKey, String key, Object value) { try { Map<String, String> appEnvAsMap = app.getEnvAsMap(); if (envPropertyKey == null) { Map<String, Object> updatedEnv = addToEnvironmentProperty(cast(appEnvAsMap), key, value); updateEnvironment(updatedEnv); return; } String locatedEnvString = appEnvAsMap.get(envPropertyKey); Map<String, Object> updatedEnv = addToEnvironmentProperty(JsonUtil.convertJsonToMap(locatedEnvString), key, value); appEnvAsMap.put(envPropertyKey, JsonUtil.toJson(updatedEnv, prettyPrinting)); updateEnvironment(cast(appEnvAsMap)); } catch (Exception e) { throw new SLException(e, "Error updating environment of application"); } }
protected void injectServiceKeysCredentialsInAppEnv(DelegateExecution context, CloudControllerClient client, CloudApplicationExtended app, Map<String, String> appEnv) { Map<String, String> appServiceKeysCredentials = buildServiceKeysCredentials(client, app, appEnv); app.setEnv(MapUtil.upcast(appEnv)); updateContextWithServiceKeysCredentials(context, app, appServiceKeysCredentials); }
@Override protected StepPhase executeStep(ExecutionWrapper execution) throws Exception { try { CloudApplicationExtended app = StepsUtil.getApp(execution.getContext()); getStepLogger().debug(Messages.BUILDING_CLOUD_APP_MODEL, app.getName()); DeploymentDescriptor descriptor = StepsUtil.getDeploymentDescriptor(execution.getContext()); Module applicationModule = getApplicationModule(app, descriptor); List<CloudApplicationExtended> modifiedApps = getApplicationsCloudModelBuilder(execution.getContext()) .build(Arrays.asList(applicationModule), moduleToDeployHelper); CloudApplicationExtended modifiedApp = findApplication(modifiedApps, app.getName()); setApplicationUris(execution.getContext(), app, modifiedApp); app.setIdleUris(modifiedApp.getIdleUris()); app.setEnv(MapUtil.upcastUnmodifiable(modifiedApp.getEnvAsMap())); SecureSerializationFacade secureSerializationFacade = new SecureSerializationFacade(); String appJson = secureSerializationFacade.toJson(app); getStepLogger().debug(Messages.APP_WITH_UPDATED_ENVIRONMENT, appJson); StepsUtil.setApp(execution.getContext(), app); buildConfigurationEntries(execution.getContext(), app); getStepLogger().debug(Messages.CLOUD_APP_MODEL_BUILT); } catch (SLException e) { getStepLogger().error(e, Messages.ERROR_BUILDING_CLOUD_APP_MODEL); throw e; } return StepPhase.DONE; }
public static Stream<Arguments> testValidate() { return Stream.of( // @formatter:off // (1) All conditions are true Arguments.of(MapUtil.of(new Pair("vcap-application",true), new Pair("vcap-services",true), new Pair("user-provided",true)), true), // (2) All conditions are false Arguments.of(MapUtil.of(new Pair("vcap-application",false), new Pair("vcap-services",false), new Pair("user-provided",false)), true), // (3) Test with error value for vcap-application Arguments.of(MapUtil.of(new Pair("vcap-application","foo.bar"), new Pair("vcap-services",false), new Pair("user-provided",false)), false), // (4) Test with error value for vcap-services Arguments.of(MapUtil.of(new Pair("vcap-application",false), new Pair("vcap-services","foo.bar"), new Pair("user-provided",true)), false), // (5) Test with error value for user-provided Arguments.of(MapUtil.of(new Pair("vcap-application",false), new Pair("vcap-services",true), new Pair("user-provided","bar.xyz")), false), // (6) Test with not map object Arguments.of(null, false), // (7) Arguments.of(MapUtil.of(new Pair("vcap-application",false), new Pair("vcap-services",true), new Pair("user-provided",false)), true), // (8) Arguments.of(MapUtil.of(new Pair("vcap-application",true), new Pair("vcap-services",true), new Pair("user-provided",false)), true), // (9) Not all parameters set Arguments.of(MapUtil.of(new Pair("vcap-services",false), new Pair("user-provided",true)), true), // (10) Arguments.of(MapUtil.of(new Pair("user-provided",true)), true), // (11) Arguments.of(MapUtil.of(new Pair("vcap-application",false)), true) // @formatter:on ); }
private CloudSpace attemptToGetSpace(CloudControllerClient client, String spaceId) { RestTemplate restTemplate = getRestTemplate(client); String url = getUrlForEndpoint(client, GET_SPACE_ENDPOINT); Map<String, Object> urlVariables = MapUtil.asMap("id", spaceId); return executeGetSpaceRequest(restTemplate, url, urlVariables); }
@Override public void visit(ElementContext context, DeploymentDescriptor descriptor) { Platform v2Platform = platform; descriptor.setParameters(MapUtil.merge(v2Platform.getParameters(), descriptor.getParameters())); }
protected void addMtaModuleMetadata(Map<String, Object> env, Module module) { Map<String, Object> mtaModuleMetadata = new TreeMap<>(); MapUtil.addNonNull(mtaModuleMetadata, Constants.ATTR_NAME, module.getName()); MapUtil.addNonNull(mtaModuleMetadata, Constants.ATTR_DESCRIPTION, module.getDescription()); env.put(Constants.ENV_MTA_MODULE_METADATA, mtaModuleMetadata); }
protected void injectServiceKeysCredentialsInAppEnv(DelegateExecution context, CloudControllerClient client, CloudApplicationExtended app, Map<String, String> appEnv) { Map<String, String> appServiceKeysCredentials = buildServiceKeysCredentials(client, app, appEnv); app.setEnv(MapUtil.upcast(appEnv)); updateContextWithServiceKeysCredentials(context, app, appServiceKeysCredentials); }
@Override protected StepPhase executeStep(ExecutionWrapper execution) throws Exception { try { CloudApplicationExtended app = StepsUtil.getApp(execution.getContext()); getStepLogger().debug(Messages.BUILDING_CLOUD_APP_MODEL, app.getName()); DeploymentDescriptor descriptor = StepsUtil.getDeploymentDescriptor(execution.getContext()); Module applicationModule = getApplicationModule(app, descriptor); List<CloudApplicationExtended> modifiedApps = getApplicationsCloudModelBuilder(execution.getContext()) .build(Arrays.asList(applicationModule), moduleToDeployHelper); CloudApplicationExtended modifiedApp = findApplication(modifiedApps, app.getName()); setApplicationUris(execution.getContext(), app, modifiedApp); app.setIdleUris(modifiedApp.getIdleUris()); app.setEnv(MapUtil.upcastUnmodifiable(modifiedApp.getEnvAsMap())); SecureSerializationFacade secureSerializationFacade = new SecureSerializationFacade(); String appJson = secureSerializationFacade.toJson(app); getStepLogger().debug(Messages.APP_WITH_UPDATED_ENVIRONMENT, appJson); StepsUtil.setApp(execution.getContext(), app); buildConfigurationEntries(execution.getContext(), app); getStepLogger().debug(Messages.CLOUD_APP_MODEL_BUILT); } catch (SLException e) { getStepLogger().error(e, Messages.ERROR_BUILDING_CLOUD_APP_MODEL); throw e; } return StepPhase.DONE; }
@Override public Map<String, Object> getParameters() { return MapUtil.unmodifiable(parameters); }
protected SystemParameters createSystemParameters(DeploymentDescriptor descriptor, String defaultDomain) { Map<String, Object> generalParameters = new HashMap<>(); generalParameters.put(SupportedParameters.DEFAULT_DOMAIN, defaultDomain); Map<String, Map<String, Object>> moduleParameters = new HashMap<>(); for (Module module : descriptor.getModules2()) { String moduleName = module.getName(); moduleParameters.put(moduleName, MapUtil.asMap(SupportedParameters.DEFAULT_HOST, moduleName)); } return new SystemParameters(generalParameters, moduleParameters, Collections.emptyMap(), Collections.emptyMap()); }
protected Map<String, Object> mergeProperties(Resource resource, ConfigurationEntry configurationEntry) { return merge(JsonUtil.convertJsonToMap(configurationEntry.getContent()), resource.getProperties()); } }
protected void addBindingParameters(Map<String, Map<String, Object>> result, RequiredDependency dependency, Module module) { Resource resource = getResource(dependency.getName()); if (resource != null) { MapUtil.addNonNull(result, cloudServiceNameMapper.getServiceName(resource.getName()), getBindingParameters(dependency, module.getName())); } }
private static Map<String, Map<String, Object>> mergeBindingParameters( Map<String, Map<String, Object>> descriptorProvidedBindingParameters, Map<String, Map<String, Object>> fileProvidedBindingParameters) { Map<String, Map<String, Object>> bindingParameters = new HashMap<>(); Set<String> serviceNames = new HashSet<>(descriptorProvidedBindingParameters.keySet()); serviceNames.addAll(fileProvidedBindingParameters.keySet()); for (String serviceName : serviceNames) { bindingParameters.put(serviceName, MapUtil.mergeSafely(fileProvidedBindingParameters.get(serviceName), descriptorProvidedBindingParameters.get(serviceName))); } return bindingParameters; }