@SuppressWarnings("unchecked") protected Map<String, Object> populateLaunchConfigData(Map<String, Object> deployParams) { Map<String, Object> launchConfigData = ServiceDiscoveryUtil.buildServiceInstanceLaunchData(service, deployParams, launchConfigName, context.allocationHelper); launchConfigData.put("name", this.instanceName); launchConfigData.remove(ServiceDiscoveryConfigItem.RESTART.getCattleName()); Object labels = launchConfigData.get(InstanceConstants.FIELD_LABELS); if (labels != null) { String overrideHostName = ((Map<String, String>) labels) .get(ServiceConstants.LABEL_OVERRIDE_HOSTNAME); if (StringUtils.equalsIgnoreCase(overrideHostName, "container_name")) { String domainName = (String) launchConfigData.get(DockerInstanceConstants.FIELD_DOMAIN_NAME); String overrideName = getOverrideHostName(domainName, this.instanceName); launchConfigData.put(InstanceConstants.FIELD_HOSTNAME, overrideName); } } launchConfigData.put(InstanceConstants.FIELD_SERVICE_INSTANCE_SERVICE_INDEX_ID, this.serviceIndex.getId()); launchConfigData.put(InstanceConstants.FIELD_SERVICE_INSTANCE_SERVICE_INDEX, this.serviceIndex.getServiceIndex()); launchConfigData.put(InstanceConstants.FIELD_ALLOCATED_IP_ADDRESS, serviceIndex.getAddress()); return launchConfigData; }
@Override protected void populatedData(Account system, List<Object> toCreate) { List<Instance> instances = objectManager .find(Instance.class, INSTANCE.REMOVED, new Condition(ConditionType.NULL)); List<ServiceIndex> serviceIndexes = objectManager .find(ServiceIndex.class, SERVICE_INDEX.REMOVED, new Condition(ConditionType.NULL)); Map<Long, ServiceIndex> serviceIndexIdsToIndexes = new HashMap<>(); for (ServiceIndex index : serviceIndexes) { serviceIndexIdsToIndexes.put(index.getId(), index); } for (Instance instance : instances) { Long indexId = instance.getServiceIndexId(); if (indexId == null) { continue; } ServiceIndex index = serviceIndexIdsToIndexes.get(indexId); if (index == null) { continue; } Map<String, Object> data = new HashMap<>(); data.put(InstanceConstants.FIELD_SERVICE_INSTANCE_SERVICE_INDEX, index.getServiceIndex()); objectManager.setFields(instance, data); } } }
/** * {@inheritDoc} */ @Override public void from(io.cattle.platform.core.model.ServiceIndex from) { setId(from.getId()); setName(from.getName()); setAccountId(from.getAccountId()); setKind(from.getKind()); setUuid(from.getUuid()); setDescription(from.getDescription()); setState(from.getState()); setCreated(from.getCreated()); setRemoved(from.getRemoved()); setRemoveTime(from.getRemoveTime()); setData(from.getData()); setServiceIndex(from.getServiceIndex()); setLaunchConfigName(from.getLaunchConfigName()); setServiceId(from.getServiceId()); setAddress(from.getAddress()); }