use of com.emc.vipr.model.sys.ClusterInfo in project coprhd-controller by CoprHD.
the class CoordinatorClientExt method getClusterInfo.
public ClusterInfo getClusterInfo(String siteIdParam) {
try {
String siteId = siteIdParam == null ? _coordinator.getSiteId() : siteIdParam;
// get target repository and configVersion
final RepositoryInfo targetRepository = _coordinator.getTargetInfo(RepositoryInfo.class);
final PropertyInfoExt targetProperty = _coordinator.getTargetInfo(PropertyInfoExt.class);
// get control nodes' repository and configVersion info
final Map<Service, RepositoryInfo> controlNodesInfo = getAllNodeInfos(RepositoryInfo.class, CONTROL_NODE_SYSSVC_ID_PATTERN, siteId);
final Map<Service, ConfigVersion> controlNodesConfigVersions = getAllNodeInfos(ConfigVersion.class, CONTROL_NODE_SYSSVC_ID_PATTERN, siteId);
ClusterInfo.ClusterState controlNodesState = _coordinator.getControlNodesState(siteId);
// rotating ipsec key. We should report upgrade in progress on UI
if (backCompatPreYoda && ClusterInfo.ClusterState.STABLE.equals(controlNodesState)) {
if (!drUtil.isMultivdc()) {
_log.info("Back compat flag for preyoda is true. ");
controlNodesState = ClusterInfo.ClusterState.UPDATING;
}
}
// cluster state is determined both by control nodes' state and extra nodes
return toClusterInfo(controlNodesState, controlNodesInfo, controlNodesConfigVersions, targetRepository, targetProperty);
} catch (Exception e) {
_log.info("Fail to get the cluster information ", e);
return null;
}
}
use of com.emc.vipr.model.sys.ClusterInfo in project coprhd-controller by CoprHD.
the class CoordinatorClientExt method isActiveSiteStable.
public boolean isActiveSiteStable(Site activeSite) {
// check if cluster state is stable
String vip = activeSite.getVipEndPoint();
int port = _svc.getEndpoint().getPort();
String baseNodeURL = String.format(SysClientFactory.BASE_URL_FORMAT, vip, port);
try {
SysClient client = SysClientFactory.getSysClient(URI.create(baseNodeURL), CHECK_ACTIVE_SITE_STABLE_READ_TIMEOUT_MS, CHECK_ACTIVE_SITE_STABLE_CONNECT_TIMEOUT_MS);
ClusterInfo clusterInfo = client.get(URI.create(URI_INTERNAL_GET_CLUSTER_INFO), ClusterInfo.class, null);
_log.info("Get cluster info from active site {}", clusterInfo.getCurrentState());
if (ClusterState.STABLE.equals(ClusterState.valueOf(clusterInfo.getCurrentState()))) {
return true;
}
} catch (Exception ex) {
_log.warn("Encounter error when call Sys API on active site{} ", ex.toString());
}
return false;
}
use of com.emc.vipr.model.sys.ClusterInfo in project coprhd-controller by CoprHD.
the class ClusterInfoMapper method toClusterInfo.
public static ClusterInfo toClusterInfo(final ClusterState controlNodesState, final Map<Service, RepositoryInfo> controlNodesInfo, final Map<Service, ConfigVersion> controlNodesConfigVersions, final RepositoryInfo targetRepository, final PropertyInfoExt targetProperty) {
ClusterInfo toClusterInfo = new ClusterInfo();
toClusterInfo.setCurrentState((controlNodesState != ClusterState.STABLE) ? controlNodesState.toString() : ClusterState.STABLE.toString());
if (!controlNodesInfo.isEmpty()) {
toClusterInfo.setControlNodes(new HashMap<String, NodeState>());
for (Map.Entry<Service, RepositoryInfo> entry : controlNodesInfo.entrySet()) {
addControlNodeInfo(toClusterInfo, entry.getKey().getNodeId(), entry.getValue(), controlNodesConfigVersions != null ? controlNodesConfigVersions.get(entry.getKey()) : null);
}
}
if (targetRepository != null) {
addTargetInfo(toClusterInfo, targetRepository, targetProperty);
}
return toClusterInfo;
}
use of com.emc.vipr.model.sys.ClusterInfo in project coprhd-controller by CoprHD.
the class ClusterInfoMapper method toClusterInfoWithSelfLink.
public static ClusterInfo toClusterInfoWithSelfLink(ClusterInfo from) {
ClusterInfo copyTo = new ClusterInfo();
copyTo.setCurrentState(from.getCurrentState());
copyTo.setSelfLink(new RestLinkRep());
copyTo.getSelfLink().setLinkName("self");
try {
copyTo.getSelfLink().setLinkRef(new URI(ClusterInfo.CLUSTER_URI));
} catch (URISyntaxException e) {
throw APIException.badRequests.parameterIsNotValidURI(ClusterInfo.CLUSTER_URI);
}
return copyTo;
}
use of com.emc.vipr.model.sys.ClusterInfo in project coprhd-controller by CoprHD.
the class UpgradeService method uploadImage.
/**
* Upload the image file given.
* Consumes MediaType.APPLICATION_OCTET_STREAM.
* This is an asynchronous operation.
*
* @brief Upload the specified image file
* @prereq Cluster state should be STABLE
* @return Cluster information.
*/
@POST
@Path("image/upload")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
@Consumes({ MediaType.APPLICATION_OCTET_STREAM })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response uploadImage(@Context HttpServletRequest request) {
File file = null;
String svcId = _coordinator.getMySvcId();
_log.info("uploadImage to {} start", svcId);
// validate
if (!_coordinator.isClusterUpgradable()) {
throw APIException.serviceUnavailable.clusterStateNotStable();
}
// maximal install number check
RepositoryInfo targetInfo = null;
try {
targetInfo = _coordinator.getTargetInfo(RepositoryInfo.class);
} catch (Exception e) {
throw APIException.internalServerErrors.getObjectFromError("target repository info", "coordinator", e);
}
if (targetInfo.getVersions().size() > SyncInfoBuilder.MAX_SOFTWARE_VERSIONS) {
throw APIException.badRequests.numberOfInstalledExceedsMax();
}
// length check
String contentLength = request.getHeader("Content-Length");
if (Long.parseLong(contentLength) <= 0 || Long.parseLong(contentLength) > MAX_UPLOAD_SIZE) {
throw APIException.badRequests.fileSizeExceedsLimit(MAX_UPLOAD_SIZE);
}
try {
// remove previous and upload to a temp file
UpgradeImageUploader uploader = UpgradeImageUploader.getInstance(_upgradeManager);
uploader.cleanUploadFiles();
long versionSize = Long.valueOf(contentLength);
_log.info("The size of the image is:" + versionSize);
String version = VIPR_UNKNOWN_IMAGE_VERSION;
initializeDownloadProgress(version, versionSize);
file = uploader.startUpload(request.getInputStream(), version);
// install image
if (file == null || file != null && !file.exists()) {
throw APIException.internalServerErrors.targetIsNullOrEmpty("Uploaded file");
}
version = _upgradeManager.getLocalRepository().installImage(file);
// set target
List<SoftwareVersion> newList = new ArrayList<SoftwareVersion>(targetInfo.getVersions());
SoftwareVersion newVersion = new SoftwareVersion(version);
if (newList.contains(newVersion)) {
_log.info("Version has already been installed");
} else {
newList.add(newVersion);
_coordinator.setTargetInfo(new RepositoryInfo(targetInfo.getCurrentVersion(), newList));
DownloadingInfo temp = _coordinator.getNodeGlobalScopeInfo(DownloadingInfo.class, DOWNLOADINFO_KIND, svcId);
_coordinator.setNodeGlobalScopeInfo(new DownloadingInfo(version, versionSize, versionSize, DownloadStatus.COMPLETED, temp._errorCounter), DOWNLOADINFO_KIND, svcId);
_coordinator.setTargetInfo(new DownloadingInfo(version, versionSize), false);
}
_log.info("uploadImage to {} end", svcId);
auditUpgrade(OperationTypeEnum.UPLOAD_IMAGE, AuditLogManager.AUDITLOG_SUCCESS, null, targetInfo.getCurrentVersion().toString(), svcId);
// return cluster status
ClusterInfo clusterInfo = _coordinator.getClusterInfo();
if (clusterInfo == null) {
throw APIException.internalServerErrors.targetIsNullOrEmpty("Cluster info");
}
return toClusterResponse(clusterInfo);
} catch (APIException ae) {
throw ae;
} catch (Exception e) {
throw APIException.internalServerErrors.uploadInstallError(e);
} finally {
if (file != null && file.exists()) {
file.delete();
}
}
}
Aggregations