protected void translateRancherToCompose( boolean forDockerCompose, Map<String, Object> rancherServiceData, Map<String, Object> composeServiceData, String cattleName, Service service) { ServiceDiscoveryConfigItem item = ServiceDiscoveryConfigItem.getServiceConfigItemByCattleName(cattleName, service); if (item != null && item.isDockerComposeProperty() == forDockerCompose) { Object value = rancherServiceData.get(cattleName); boolean export = false; if (value instanceof List) { if (!((List<?>) value).isEmpty()) { export = true; } } else if (value instanceof Map) { if (!((Map<?, ?>) value).isEmpty()) { export = true; } } else if (value instanceof Boolean) { if (((Boolean) value).booleanValue()) { export = true; } } else if (value != null) { export = true; } if (export) { // for every lookup, do transform Object formattedValue = null; for (RancherConfigToComposeFormatter formatter : formatters) { formattedValue = formatter.format(item, value); if (formattedValue != null) { break; } } if (formattedValue != null) { composeServiceData.put(item.getDockerName().toLowerCase(), formattedValue); } else { composeServiceData.put(item.getDockerName().toLowerCase(), value); } } } }
@Override @SuppressWarnings("unchecked") public Object format(ServiceDiscoveryConfigItem item, Object valueToTransform) { if (!item.getDockerName() .equalsIgnoreCase(ServiceDiscoveryConfigItem.RESTART.getDockerName())) { return null; } // transform object to string as thats how policy is defined in docker-compose Map<String, Object> map = (Map<String, Object>) valueToTransform; Object name = map.get("name"); Object maxRetryCount = map.get("maximumRetryCount"); if (maxRetryCount == null) { return name; } return name + ":" + maxRetryCount; }