private void deleteClusterNodes(ChunkContext chunkContext, String clusterName) { ClusterEntity cluster = getClusterEntityMgr().findByName(clusterName); AuAssert.check(cluster != null); releaseIp(cluster); lockClusterEntityMgr.getLock(clusterName).lock(); putIntoJobExecutionContext(chunkContext, JobConstants.CLUSTER_EXCLUSIVE_WRITE_LOCKED, true); getClusterEntityMgr().delete(cluster); }
@RequestMapping(value = "/networks", method = RequestMethod.POST, consumes = "application/json") @ResponseStatus(HttpStatus.OK) public void addNetworks(@RequestBody final NetworkAdd na) { if (na.getName() == null || na.getName().isEmpty()) { throw BddException.INVALID_PARAMETER("name", na.getName()); } if (na.getPortGroup() == null || na.getPortGroup().isEmpty()) { throw BddException.INVALID_PARAMETER("port group", na.getPortGroup()); } if (na.isDhcp()) { networkManager.addDhcpNetwork(na.getName(), na.getPortGroup()); } else { if (!IpAddressUtil.isValidNetmask(na.getNetmask())) { throw BddException.INVALID_PARAMETER("netmask", na.getNetmask()); } long netmask = IpAddressUtil.getAddressAsLong(na.getNetmask()); if (!IpAddressUtil.isValidIp(netmask, IpAddressUtil.getAddressAsLong(na.getGateway()))) { throw BddException.INVALID_PARAMETER("gateway", na.getGateway()); } if (na.getDns1() != null && !IpAddressUtil.isValidIp(na.getDns1())) { throw BddException.INVALID_PARAMETER("primary dns", na.getDns1()); } if (na.getDns2() != null && !IpAddressUtil.isValidIp(na.getDns2())) { throw BddException.INVALID_PARAMETER("secondary dns", na.getDns2()); } AuAssert.check(na.getIp() != null, "Spring should guarantee this"); for (IpBlock blk : na.getIp()) { Long begin = IpAddressUtil.getAddressAsLong(blk.getBeginIp()); Long end = IpAddressUtil.getAddressAsLong(blk.getEndIp()); if (begin == null || end == null || begin > end || !IpAddressUtil.isValidIp(netmask, begin) || !IpAddressUtil.isValidIp(netmask, end)) { throw BddException.INVALID_PARAMETER( "IP block", "[" + blk.getBeginIp() + ", " + blk.getEndIp() + "]"); } } networkManager.addIpPoolNetwork( na.getName(), na.getPortGroup(), na.getNetmask(), na.getGateway(), na.getDns1(), na.getDns2(), na.getIp()); } }