@Override protected List<Object> map(List<Object> input) { result.put(((Nic) input.get(0)).getId(), (IpAddress) input.get(1)); return input; } };
protected Set<Long> createNicsFromIds(Instance instance, List<Nic> nics, Map<String, Object> data, List<Long> networkIds) { Set<Long> nicIds = new TreeSet<Long>(); int deviceId = 0; if (networkIds != null) { for (int i = 0; i < networkIds.size(); i++) { Number createId = networkIds.get(i); if (createId == null) { deviceId++; continue; } Nic newNic = null; for (Nic nic : nics) { if (nic.getNetworkId() == createId.longValue()) { newNic = nic; break; } } if (newNic == null) { newNic = objectManager.create(Nic.class, NIC.ACCOUNT_ID, instance.getAccountId(), NIC.NETWORK_ID, createId, NIC.INSTANCE_ID, instance .getId(), NIC.DEVICE_NUMBER, deviceId); } deviceId++; processManager.executeStandardProcess(StandardProcess.CREATE, newNic, data); nicIds.add(newNic.getId()); } } return nicIds; }
@Override public IpAddress mapNewIpAddress(Nic nic, Object key, Object... values) { if ( nic.getNetworkId() == null ) { throw new IllegalStateException("Can not map new IP to nic with no network assigned to nic"); } Map<Object,Object> inputProperties = key == null ? Collections.emptyMap() : CollectionUtils.asMap(key, values); Map<Object,Object> properties = CollectionUtils.asMap((Object)IP_ADDRESS.ACCOUNT_ID, nic.getAccountId()); properties.putAll(inputProperties); IpAddress ipAddress = objectManager.create(IpAddress.class, objectManager.convertToPropertiesFor(IpAddress.class, properties)); objectManager.create(IpAddressNicMap.class, IP_ADDRESS_NIC_MAP.IP_ADDRESS_ID, ipAddress.getId(), IP_ADDRESS_NIC_MAP.NIC_ID, nic.getId()); return ipAddress; }
@Override public HandlerResult handle(ProcessState state, ProcessInstance process) { /* Release requested IPs on delete, not on purge */ Nic nic = (Nic) state.getResource(); for (IpAddressNicMap map : mapDao.findToRemove(IpAddressNicMap.class, Nic.class, nic.getId())) { IpAddress ipAddress = getObjectManager().loadResource(IpAddress.class, map.getIpAddressId()); if (DockerIpAddressConstants.KIND_DOCKER.equals(ipAddress.getKind())) { /* Deactivate Docker IPs on stop */ deactivate(ipAddress, state.getData()); } } return null; }
@Override public HandlerResult handle(ProcessState state, ProcessInstance process) { /* Release requested IPs on delete, not on purge */ Nic nic = (Nic) state.getResource(); for (IpAddressNicMap map : mapDao.findToRemove(IpAddressNicMap.class, Nic.class, nic.getId())) { IpAddress ipAddress = getObjectManager().loadResource(IpAddress.class, map.getIpAddressId()); /* Deactivate to release the IP address */ deactivate(ipAddress, state.getData()); } return null; }
@Override public IpAddress getPrimaryIpAddress(Nic nic) { List<? extends IpAddress> ipAddresses = create() .select(IP_ADDRESS.fields()) .from(IP_ADDRESS) .join(IP_ADDRESS_NIC_MAP) .on(IP_ADDRESS_NIC_MAP.IP_ADDRESS_ID.eq(IP_ADDRESS.ID) .and(IP_ADDRESS_NIC_MAP.NIC_ID.eq(nic.getId()))) .where(IP_ADDRESS_NIC_MAP.REMOVED.isNull()) .fetchInto(IpAddressRecord.class); if (ipAddresses.size() == 1) { return ipAddresses.get(0); } for (IpAddress ipAddress : ipAddresses) { if (IpAddressConstants.ROLE_PRIMARY.equals(ipAddress.getRole())) { return ipAddress; } } return null; }
protected IpAddress getIpAddress(Nic nic, Network network) { IpAddress ipAddress = ipAddressDao.getPrimaryIpAddress(nic); if (ipAddress == null && networkService.shouldAssignIpAddress(network)) { ipAddress = ipAddressDao.mapNewIpAddress(nic, IP_ADDRESS.ROLE, IpAddressConstants.ROLE_PRIMARY, IP_ADDRESS.NETWORK_ID, nic.getNetworkId()); } for (IpAddressNicMap map : mapDao.findNonRemoved(IpAddressNicMap.class, Nic.class, nic.getId())) { getObjectProcessManager().executeStandardProcess(StandardProcess.CREATE, map, null); } if (ipAddress != null) { getObjectProcessManager().executeStandardProcess(StandardProcess.CREATE, ipAddress, null); } return ipAddress; }
@Override public HandlerResult handle(ProcessState state, ProcessInstance process) { Nic nic = (Nic) state.getResource(); Network network = loadResource(Network.class, nic.getNetworkId()); for (IpAddressNicMap map : mapDao.findToRemove(IpAddressNicMap.class, Nic.class, nic.getId())) { IpAddress ipAddress = getObjectManager().loadResource(IpAddress.class, map.getIpAddressId()); deactivateThenRemove(ipAddress, state.getData()); } if (network != null) { poolManager.releaseResource(network, nic, new PooledResourceOptions().withQualifier(ResourcePoolConstants.MAC)); } return new HandlerResult(NIC.MAC_ADDRESS, new Object[] { null }).withShouldContinue(true); }
/** * {@inheritDoc} */ @Override public void from(io.cattle.platform.core.model.Nic 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()); setInstanceId(from.getInstanceId()); setNetworkId(from.getNetworkId()); setDeviceNumber(from.getDeviceNumber()); setMacAddress(from.getMacAddress()); }