@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void process(Object obj, String type, Map<String, Object> data) { if (!(obj instanceof Instance)) return; Instance instance = (Instance) obj; if (!InstanceConstants.CONTAINER_LIKE.contains(instance.getKind())) return; List volumesFromContainerIds = DataAccessor.fields(instance).withKey(DockerInstanceConstants.FIELD_VOLUMES_FROM).as(jsonMapper, List.class); List<Instance> containers = null; if (volumesFromContainerIds != null && !volumesFromContainerIds.isEmpty()) { Condition condition = new Condition(ConditionType.IN, volumesFromContainerIds); containers = objectManager.find(Instance.class, INSTANCE.ID, condition); } if (containers == null) containers = new ArrayList<Instance>(); data.put(DockerInstanceConstants.EVENT_FIELD_VOLUMES_FROM, containers); List<Volume>volumes = InstanceHelpers.extractVolumesFromMounts(instance, objectManager); data.put(DockerInstanceConstants.EVENT_FIELD_VOLUMES_FROM_DVM, volumes); }
protected void setDns(Instance instance, Map<String, Object> labels, Map<Object, Object> data) { if (!InstanceConstants.KIND_CONTAINER.equals(instance.getKind())) { return;
protected void processPorts(Instance instance) { Set<String> portSpecs = new HashSet<>(); for (Port port : objectManager.children(instance, Port.class)) { if (port.getRemoved() != null) { continue; } portSpecs.add(new PortSpec(port).toSpec()); } objectManager.setFields(instance, InstanceConstants.FIELD_PORTS, new ArrayList<>(portSpecs)); Event event = EventVO.newEvent(IaasEvents.INVALIDATE_INSTANCE_DATA_CACHE) .withResourceType(instance.getKind()) .withResourceId(instance.getId().toString()); eventService.publish(event); }
public HandlerResult handle(ProcessState state, ProcessInstance process) { Instance instance = (Instance)state.getResource(); if (!InstanceConstants.CONTAINER_LIKE.contains(instance.getKind())) { return null;
private void updateInstanceWithNewPorts(Instance instance) { List<Port> toUpdate = objectManager.find(Port.class, PORT.INSTANCE_ID, instance.getId(), PORT.REMOVED, null); List<String> toUpdatePortDefs = new ArrayList<>(); for (Port port : toUpdate) { PortSpec portSpec = new PortSpec(port); toUpdatePortDefs.add(portSpec.toSpec()); } instance = objectManager.setFields(instance, InstanceConstants.FIELD_PORTS, toUpdatePortDefs); // trigger instance/metadata update Event event = EventVO.newEvent(IaasEvents.INVALIDATE_INSTANCE_DATA_CACHE) .withResourceType(instance.getKind()) .withResourceId(instance.getId().toString()); eventService.publish(event); return; }
@Override public HandlerResult handle(ProcessState state, ProcessInstance process) { Instance instance = (Instance)state.getResource(); if (!InstanceConstants.CONTAINER_LIKE.contains(instance.getKind())) { return null; } Image image = objectManager.loadResource(Image.class, instance.getImageId()); if (image == null) { return null; } DockerBuild build = DataAccessor.field(instance, DockerInstanceConstants.FIELD_BUILD, jsonMapper, DockerBuild.class); if (build == null) { return null; } String imageUuid = DataAccessor.fieldString(instance, InstanceConstants.FIELD_IMAGE_UUID); if (imageUuid != null) { String tag = StringUtils.removeStart(imageUuid, "docker:"); build.setTag(tag); } objectManager.setFields(image, DockerInstanceConstants.FIELD_BUILD, build); return null; } }
@Override public HandlerResult handle(ProcessState state, ProcessInstance process) { Instance instance = (Instance)state.getResource(); if (!InstanceConstants.CONTAINER_LIKE.contains(instance.getKind())) { return null;
@Override public HandlerResult handle(ProcessState state, ProcessInstance process) { Instance instance = (Instance)state.getResource(); if (!InstanceConstants.KIND_VIRTUAL_MACHINE.equals(instance.getKind())) { return null;
hostStats = true; containerStats = true; } else if (original instanceof Instance && InstanceConstants.CONTAINER_LIKE.contains(((Instance) original).getKind())) { containerStats = true; add = true;
@Override public HandlerResult handle(ProcessState state, ProcessInstance process) { Instance instance = (Instance)state.getResource(); if (!InstanceConstants.CONTAINER_LIKE.contains(instance.getKind())) { return null; } Map<String, Object> labels = DataAccessor.fieldMap(instance, InstanceConstants.FIELD_LABELS); Account account = objectManager.loadResource(Account.class, instance.getAccountId()); Map<Object, Object> data = new HashMap<>(); setAgentVolumes(instance, labels, data); setName(instance, labels, data); setDns(instance, labels, data); setLogConfig(instance, data); setSecrets(instance, data); setSystemLabel(instance, labels); setEnvironmentLabel(labels, account); if (!data.isEmpty()) { return new HandlerResult(data); } return null; }
@SuppressWarnings("unchecked") @Override public HandlerResult handle(ProcessState state, ProcessInstance process) { InstanceHostMap map = (InstanceHostMap)state.getResource(); Instance instance = getObjectManager().loadResource(Instance.class, map.getInstanceId()); Host host = getObjectManager().loadResource(Host.class, map.getHostId()); String dockerIp = DockerProcessUtils.getDockerIp(instance); Nic nic = nicDao.getPrimaryNic(instance); IpAddress hostIpAddress = hostDao.getIpAddressForHost(host.getId()); IpAddress primaryIp = ipAddressDao.getInstancePrimaryIp(instance); List<String> ports = DataAccessor.fields(instance).withKey(DockerInstanceConstants.FIELD_DOCKER_PORTS).as(jsonMapper, List.class); if (dockerIp != null) { primaryIp = processDockerIp(instance, nic, primaryIp, dockerIp); } if (hostIpAddress != null && ports != null) { processPorts(primaryIp, hostIpAddress, ports, instance, nic, host); } processVolumes(instance, host, state); processLabels(instance); nativeDockerBackPopulate(instance); Event event = EventVO.newEvent(IaasEvents.INVALIDATE_INSTANCE_DATA_CACHE) .withResourceType(instance.getKind()) .withResourceId(instance.getId().toString()); eventService.publish(event); return null; }
setName(from.getName()); setAccountId(from.getAccountId()); setKind(from.getKind()); setUuid(from.getUuid()); setDescription(from.getDescription());