private String attemptToParseDescriptionFromResponseBody(String responseBody) { Map<String, Object> responseEntity = JsonUtil.convertJsonToMap(responseBody); Object result = responseEntity.get("description"); return result instanceof String ? (String) result : null; }
private Platform parsePlatform(String json, ConfigurationParser parser) { if (json == null) { throw new IllegalStateException(Messages.PLATFORMS_NOT_SPECIFIED); } Platform result = parser.parsePlatformJson(json); LOGGER.info(format(Messages.PLATFORMS, JsonUtil.toJson(result, true))); return result; }
@SuppressWarnings("unchecked") public static List<CloudApplicationExtended> getAppsToDeploy(DelegateExecution context) { List<String> cloudApplicationsAsStrings = (List<String>) context.getVariable(Constants.VAR_APPS_TO_DEPLOY); return cloudApplicationsAsStrings.stream() .map(app -> (CloudApplicationExtended) JsonUtil.fromJson(app, CloudApplicationExtended.class)) .collect(Collectors.toList()); }
private void updateAppDigest(Map<String, String> newAppEnv, Map<String, String> existingAppEnv) { Object existingFileDigest = getExistingAppFileDigest(existingAppEnv); if (existingFileDigest == null) { return; } String newAppDeployAttributes = newAppEnv.get(com.sap.cloud.lm.sl.cf.core.Constants.ENV_DEPLOY_ATTRIBUTES); TreeMap<String, Object> newAppDeployAttributesMap = new TreeMap<>(JsonUtil.convertJsonToMap(newAppDeployAttributes)); newAppDeployAttributesMap.put(com.sap.cloud.lm.sl.cf.core.Constants.ATTR_APP_CONTENT_DIGEST, existingFileDigest); newAppEnv.put(com.sap.cloud.lm.sl.cf.core.Constants.ENV_DEPLOY_ATTRIBUTES, JsonUtil.toJson(newAppDeployAttributesMap, true)); }
public ConfigurationSubscription toConfigurationSubscription() { try { ConfigurationFilter parsedFilter = JsonUtil.fromJson(filter, ConfigurationFilter.class); Map<String, Object> parsedResourceProperties = JsonUtil.convertJsonToMap(resourceProperties); ResourceDto resourceDto = new ResourceDto(resourceName, parsedResourceProperties); ModuleDto moduleDto = JsonUtil.fromJson(module, ModuleDto.class); return new ConfigurationSubscription(id, mtaId, spaceId, appName, parsedFilter, moduleDto, resourceDto); } catch (SLException e) { throw new IllegalStateException(format(Messages.UNABLE_TO_PARSE_SUBSCRIPTION, e.getMessage()), e); } }
private DeploymentDescriptor buildDummyDescriptor(ConfigurationSubscription subscription, HandlerFactory handlerFactory) { ModuleDto moduleDto = subscription.getModuleDto(); String resourceJson = toJson(subscription.getResourceDto()); Map<String, Object> resourceMap = convertJsonToMap(resourceJson); Map<String, Object> moduleMap = new TreeMap<>(); moduleMap.put(ModuleParser.NAME, moduleDto.getName()); moduleMap.put(ModuleParser.TYPE, moduleDto.getName()); moduleMap.put(ModuleParser.PROPERTIES, moduleDto.getProperties()); moduleMap.put(ModuleParser.PROVIDES, convertJsonToList(toJson(moduleDto.getProvidedDependencies()))); moduleMap.put(ModuleParser.REQUIRES, convertJsonToList(toJson(moduleDto.getRequiredDependencies()))); Map<String, Object> dummyDescriptorMap = new TreeMap<>(); dummyDescriptorMap.put(DeploymentDescriptorParser.SCHEMA_VERSION, SCHEMA_VERSION); dummyDescriptorMap.put(DeploymentDescriptorParser.ID, subscription.getMtaId()); dummyDescriptorMap.put(DeploymentDescriptorParser.MODULES, Arrays.asList(moduleMap)); dummyDescriptorMap.put(DeploymentDescriptorParser.VERSION, DUMMY_VERSION); dummyDescriptorMap.put(DeploymentDescriptorParser.RESOURCES, Arrays.asList(resourceMap)); return handlerFactory.getDescriptorParser() .parseDeploymentDescriptor(dummyDescriptorMap); }
private List<CloudTarget> getParsedVisibility(String visibility) { if (visibility == null) { return null; } return JsonUtil.convertJsonToList(visibility, new TypeToken<List<CloudTarget>>() { }.getType()); }
static List<CloudApplication> getDeployedApps(DelegateExecution context) { CloudApplication[] apps = JsonUtil.fromBinaryJson((byte[]) context.getVariable(Constants.VAR_DEPLOYED_APPS), CloudApplication[].class); return Arrays.asList(apps); }
static void setDeletedEntries(DelegateExecution context, List<ConfigurationEntry> deletedEntries) { if (deletedEntries == null) { return; } byte[] deletedEntriesByteArray = JsonUtil.toBinaryJson(deletedEntries.toArray(new ConfigurationEntry[] {})); context.setVariable(Constants.VAR_DELETED_ENTRIES, deletedEntriesByteArray); }
private DeploymentDescriptor buildDummyDescriptor(ConfigurationSubscription subscription, HandlerFactory handlerFactory) { ModuleDto moduleDto = subscription.getModuleDto(); String resourceJson = toJson(subscription.getResourceDto()); Map<String, Object> resourceMap = convertJsonToMap(resourceJson); Map<String, Object> moduleMap = new TreeMap<>(); moduleMap.put(ModuleParser.NAME, moduleDto.getName()); moduleMap.put(ModuleParser.TYPE, moduleDto.getName()); moduleMap.put(ModuleParser.PROPERTIES, moduleDto.getProperties()); moduleMap.put(ModuleParser.PROVIDES, convertJsonToList(toJson(moduleDto.getProvidedDependencies()))); moduleMap.put(ModuleParser.REQUIRES, convertJsonToList(toJson(moduleDto.getRequiredDependencies()))); Map<String, Object> dummyDescriptorMap = new TreeMap<>(); dummyDescriptorMap.put(DeploymentDescriptorParser.SCHEMA_VERSION, SCHEMA_VERSION); dummyDescriptorMap.put(DeploymentDescriptorParser.ID, subscription.getMtaId()); dummyDescriptorMap.put(DeploymentDescriptorParser.MODULES, Arrays.asList(moduleMap)); dummyDescriptorMap.put(DeploymentDescriptorParser.VERSION, DUMMY_VERSION); dummyDescriptorMap.put(DeploymentDescriptorParser.RESOURCES, Arrays.asList(resourceMap)); return handlerFactory.getDescriptorParser() .parseDeploymentDescriptor(dummyDescriptorMap); }
private void updateAppDigest(Map<String, String> newAppEnv, Map<String, String> existingAppEnv) { Object existingFileDigest = getExistingAppFileDigest(existingAppEnv); if (existingFileDigest == null) { return; } String newAppDeployAttributes = newAppEnv.get(com.sap.cloud.lm.sl.cf.core.Constants.ENV_DEPLOY_ATTRIBUTES); TreeMap<String, Object> newAppDeployAttributesMap = new TreeMap<>(JsonUtil.convertJsonToMap(newAppDeployAttributes)); newAppDeployAttributesMap.put(com.sap.cloud.lm.sl.cf.core.Constants.ATTR_APP_CONTENT_DIGEST, existingFileDigest); newAppEnv.put(com.sap.cloud.lm.sl.cf.core.Constants.ENV_DEPLOY_ATTRIBUTES, JsonUtil.toJson(newAppDeployAttributesMap, true)); }
public static List<Object> convertJsonToList(InputStream json) throws ParsingException { return convertJsonToList(json, new TypeToken<List<Object>>() { }.getType()); }
public static List<ConfigurationEntry> getPublishedEntries(DelegateExecution context) { ConfigurationEntry[] publishedEntriesArray = JsonUtil.fromBinaryJson((byte[]) context.getVariable(Constants.VAR_PUBLISHED_ENTRIES), ConfigurationEntry[].class); return Arrays.asList(publishedEntriesArray); }
static void setServiceKeysCredentialsToInject(DelegateExecution context, Map<String, Map<String, String>> serviceKeysCredentialsToInject) { byte[] serviceKeysToInjectByteArray = JsonUtil.toBinaryJson(serviceKeysCredentialsToInject); context.setVariable(Constants.VAR_SERVICE_KEYS_CREDENTIALS_TO_INJECT, serviceKeysToInjectByteArray); }
@Override public void writeTo(T t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { String json = JsonUtil.toJson(t); entityStream.write(json.getBytes(getCharset(mediaType))); }
private Object getExistingAppFileDigest(Map<String, String> envAsMap) { String applicationDeployAttributes = envAsMap.get(com.sap.cloud.lm.sl.cf.core.Constants.ENV_DEPLOY_ATTRIBUTES); Map<String, Object> deployAttributesMap = JsonUtil.convertJsonToMap(applicationDeployAttributes); return deployAttributesMap.get(com.sap.cloud.lm.sl.cf.core.Constants.ATTR_APP_CONTENT_DIGEST); }
@SuppressWarnings("unchecked") public static List<ModuleToDeploy> getIteratedModulesInParallel(DelegateExecution context) { List<String> modulesIteratedInParallel = (List<String>) context.getVariable(Constants.VAR_ITERATED_MODULES_IN_PARALLEL); if (modulesIteratedInParallel == null) { return Collections.emptyList(); } return modulesIteratedInParallel.stream() .map(module -> JsonUtil.<ModuleToDeploy> fromJson(module, ModuleToDeploy.class)) .collect(Collectors.toList()); }
private static List<String> parseServices(Map<String, String> appEnv) { String envValue = appEnv.get(Constants.ENV_MTA_SERVICES); if (envValue == null) { return null; } return JsonUtil.convertJsonToList(envValue, new TypeToken<List<String>>() { }.getType()); }
public static List<ConfigurationSubscription> getSubscriptionsToCreate(DelegateExecution context) { ConfigurationSubscription[] subscriptionsArray = JsonUtil .fromBinaryJson((byte[]) context.getVariable(Constants.VAR_SUBSCRIPTIONS_TO_CREATE), ConfigurationSubscription[].class); return Arrays.asList(subscriptionsArray); }
static void setServiceKeysCredentialsToInject(DelegateExecution context, Map<String, Map<String, String>> serviceKeysCredentialsToInject) { byte[] serviceKeysToInjectByteArray = JsonUtil.toBinaryJson(serviceKeysCredentialsToInject); context.setVariable(Constants.VAR_SERVICE_KEYS_CREDENTIALS_TO_INJECT, serviceKeysToInjectByteArray); }