private VdcPreCheckResponse2 toVirtualDataCenterResponse2( VirtualDataCenter from, boolean hasData, SoftwareVersion softVer) { if (from == null) { return null; } VdcPreCheckResponse2 to = new VdcPreCheckResponse2(); to.setId(from.getId()); to.setCompatible(helper.isCompatibleVersion(softVer)); boolean clusterStable = isClusterStable(); to.setClusterStable(clusterStable); log.info("current cluster stable {}", clusterStable); return to; }
/** * Do more precheck For disconnecting a vdc, check if there is a VDC that is under disconnecting * If yes, return the VDC under disconnecting, otherwise set the VDC (given by parameter) status * to DISCONNECTING * * @param checkParam * @return VdcPreCheckResponse */ @POST @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Path("/precheck2") public VdcPreCheckResponse2 precheckVdcConfig(VdcPreCheckParam2 checkParam) { log.info("Start vdc config precheck2 for {} ...", checkParam.getConfigChangeType()); if (service.getId().endsWith("standalone")) { throw GeoException.fatals.remoteVDCWrongStandaloneInstall(); } VdcConfig.ConfigChangeType type = checkParam.getConfigChangeType(); VirtualDataCenter vdc = null; VdcPreCheckResponse2 resp2 = new VdcPreCheckResponse2(); resp2.setCompatible(true); // BZ // TODO Need to use a different method to update info on lock on a remote system. // Need to use a different field (not connection status of VDC object) as a locking mechanism) boolean precheckFailed = checkParam.isPrecheckFailed(); switch (type) { case DISCONNECT_VDC: log.info("Precheck2 for disconnect ops"); vdc = helper.getDisconnectingVdc(); if (checkParam.getIsAllNotReachable()) { URI targetVdcId = checkParam.getVdcIds().get(0); log.info("Precheck2 to check the disconnect vdc {} is reachable", targetVdcId); VirtualDataCenter targetVdc = dbClient.queryObject(VirtualDataCenter.class, targetVdcId); resp2.setIsAllNodesNotReachable( !helper.areNodesReachable( getLocalVdc().getShortId(), targetVdc.getHostIPv4AddressesMap(), targetVdc.getHostIPv6AddressesMap(), checkParam.getIsAllNotReachable())); break; } if (precheckFailed) { log.info("Precheck2 to update reconnect precheck fail status"); String vdcState = checkParam.getDefaultVdcState(); if (StringUtils.isNotEmpty(vdcState)) { vdc.setConnectionStatus(VirtualDataCenter.ConnectionStatus.valueOf(vdcState)); dbClient.updateAndReindexObject(vdc); } break; } if (vdc == null) { // no DISCONNECTING_VDC log.info("Precheck2: there is no disconnecting vdc"); URI srcVdcId = checkParam.getVdcIds().get(1); VirtualDataCenter srcVdc = dbClient.queryObject(VirtualDataCenter.class, srcVdcId); if (srcVdc.getConnectionStatus() == VirtualDataCenter.ConnectionStatus.DISCONNECTED) { resp2.setCompatible(false); break; } // BZ // TODO need to use a different field to set locks on concurrent VDC operation URI id = checkParam.getVdcIds().get(0); vdc = dbClient.queryObject(VirtualDataCenter.class, id); vdc.setConnectionStatus(VirtualDataCenter.ConnectionStatus.DISCONNECTING); dbClient.updateAndReindexObject(vdc); } else { resp2 = toVirtualDataCenterResponse2(vdc, true, null); } break; case RECONNECT_VDC: log.info("Precheck2 for reconnect ops checkParam={}", checkParam); List<String> blackList = checkParam.getBlackList(); List<String> whiteList = checkParam.getWhiteList(); log.info("Precheck2 to check if two vdc disconnect each other"); resp2.setCompatible(true); if (isDisconnectedEachOther(blackList, whiteList)) { log.info("Precheck2: two vdc have disconnected each other"); resp2.setCompatible(false); break; } if (precheckFailed) { log.info("Precheck2 to update reconnect precheck fail status"); URI targetVdcId = checkParam.getVdcIds().get(0); log.info("Precheck2 to check the disconnect vdc {} is reachable", targetVdcId); VirtualDataCenter targetVdc = dbClient.queryObject(VirtualDataCenter.class, targetVdcId); String vdcState = checkParam.getDefaultVdcState(); if (StringUtils.isNotEmpty(vdcState)) { targetVdc.setConnectionStatus(VirtualDataCenter.ConnectionStatus.valueOf(vdcState)); dbClient.updateAndReindexObject(targetVdc); } break; } break; } log.info("Precheck2 done, resp is {}", resp2.toString()); return resp2; }