Search in sources :

Example 1 with SysClientException

use of com.emc.storageos.systemservices.exceptions.SysClientException in project coprhd-controller by CoprHD.

the class RecoveryManager method poweroff.

/**
 * Poweroff specific nodes
 *
 * @param nodeIds a list of node id (e.g. vipr1)
 */
public void poweroff(List<String> nodeIds) {
    for (String nodeId : nodeIds) {
        try {
            log.info("Try to power off {}", nodeId);
            String svcId = nodeId.replace("vipr", "syssvc-");
            URI nodeEndpoint = coordinator.getNodeEndpointForSvcId(svcId);
            if (nodeEndpoint == null) {
                continue;
            }
            SysClientFactory.getSysClient(coordinator.getNodeEndpointForSvcId(svcId)).post(SysClientFactory.URI_POWEROFF_NODE, null, null);
            log.info("Power off {} successfully", nodeId);
        } catch (SysClientException e) {
            log.error("Power off node({}) failed", nodeId, e.getMessage());
        }
    }
}
Also used : SysClientException(com.emc.storageos.systemservices.exceptions.SysClientException) URI(java.net.URI)

Example 2 with SysClientException

use of com.emc.storageos.systemservices.exceptions.SysClientException in project coprhd-controller by CoprHD.

the class ControlService method rebootNode.

/**
 * Reboot a virtual machine
 *
 * @brief Reboot a virtual machine
 * @param nodeId Virtual machine id (e.g. vipr1)
 * @param nodeName node name of Virtual machine
 * @prereq none
 */
@POST
@Path("node/reboot")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response rebootNode(@QueryParam("node_id") String nodeId, @QueryParam("node_name") String nodeName) {
    nodeId = determineNodeId(nodeId, nodeName);
    _log.info("Reboot node: " + nodeId);
    if (_coordinator.getMyNodeId().equals(nodeId)) {
        auditControl(OperationTypeEnum.REBOOT_NODE, AuditLogManager.AUDITLOG_SUCCESS, null, nodeId);
        return rebootNode();
    } else {
        // Otherwise get endpoint of node
        URI endpoint = _coordinator.getNodeEndpoint(nodeId);
        if (endpoint == null) {
            throw APIException.badRequests.parameterIsNotValid("node id");
        }
        try {
            SysClientFactory.getSysClient(endpoint).post(SysClientFactory.URI_REBOOT_NODE, null, null);
        } catch (SysClientException e) {
            throw APIException.internalServerErrors.sysClientError("reboot node");
        }
        auditControl(OperationTypeEnum.REBOOT_NODE, AuditLogManager.AUDITLOG_SUCCESS, null, nodeId);
        return Response.status(Response.Status.ACCEPTED).build();
    }
}
Also used : SysClientException(com.emc.storageos.systemservices.exceptions.SysClientException) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 3 with SysClientException

use of com.emc.storageos.systemservices.exceptions.SysClientException in project coprhd-controller by CoprHD.

the class ControlService method getDbRepairStatus.

/**
 * Get the db repair status.
 *
 * @brief Show db repair status
 * @prereq none
 * @return db repair status
 * @throws Exception
 */
@GET
@Path("cluster/dbrepair-status")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SECURITY_ADMIN, Role.SYSTEM_MONITOR })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public DbRepairStatus getDbRepairStatus() throws Exception {
    _log.info("Received a getting db repair status request");
    if (_coordinator.isMyDbSvcGood(Constants.DBSVC_NAME) && _coordinator.isMyDbSvcGood(Constants.GEODBSVC_NAME)) {
        return getDbRepairStatusFromLocalNode();
    } else {
        URI endpoint = _coordinator.getNodeEndpointWithGoodDbsvc();
        _log.info("Dbsvc/Geodbsvc on current node is not started yet, swith to another syssvc endpoint " + endpoint);
        if (endpoint == null) {
            throw APIException.internalServerErrors.sysClientError("No valid syssvc endpoint for db repair status check");
        }
        try {
            return SysClientFactory.getSysClient(endpoint).get(SysClientFactory.URI_GET_DBREPAIR_STATUS, DbRepairStatus.class, null);
        } catch (SysClientException e) {
            throw APIException.internalServerErrors.sysClientError("db repair status");
        }
    }
}
Also used : SysClientException(com.emc.storageos.systemservices.exceptions.SysClientException) URI(java.net.URI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 4 with SysClientException

use of com.emc.storageos.systemservices.exceptions.SysClientException in project coprhd-controller by CoprHD.

the class ControlService method restartService.

/**
 * Restart a service on a virtual machine
 *
 * @brief Restart a service on a virtual machine
 * @param nodeId Virtual machine id (e.g. vipr1)
 * @param nodeName node name of Virtual machine
 * @prereq none
 * @param name Service name
 */
@POST
@Path("service/restart")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response restartService(@QueryParam("node_id") String nodeId, @QueryParam("name") String name, @QueryParam("node_name") String nodeName) {
    nodeId = determineNodeId(nodeId, nodeName);
    List<String> controlNodeServiceNames = ServicesMetadata.getControlNodeServiceNames();
    if (_coordinator.getMyNodeId().equals(nodeId)) {
        if (!controlNodeServiceNames.contains(name)) {
            throw APIException.badRequests.parameterIsNotOneOfAllowedValues("service name", controlNodeServiceNames.toString());
        }
        auditControl(OperationTypeEnum.RESTART_SERVICE, AuditLogManager.AUDITLOG_SUCCESS, null, name, nodeId);
        return restartNodeService(name);
    } else {
        // get endpoint of node
        URI endpoint = _coordinator.getNodeEndpoint(nodeId);
        if (endpoint == null) {
            throw APIException.badRequests.parameterIsNotValid("node id");
        }
        // check available service name exists
        boolean isControlNode = CONTROL_NODE_ID_PATTERN.matcher(nodeId).matches();
        List<String> availableServices = isControlNode ? controlNodeServiceNames : ServicesMetadata.getExtraNodeServiceNames();
        if (!availableServices.contains(name)) {
            throw APIException.badRequests.parameterIsNotOneOfAllowedValues("service name", availableServices.toString());
        }
        try {
            SysClientFactory.getSysClient(endpoint).post(URI.create(SysClientFactory.URI_RESTART_SERVICE.getPath() + "?name=" + name), null, null);
        } catch (SysClientException e) {
            throw APIException.internalServerErrors.serviceRestartError(name, nodeId);
        }
        auditControl(OperationTypeEnum.RESTART_SERVICE, AuditLogManager.AUDITLOG_SUCCESS, null, name, nodeId);
        return Response.status(Response.Status.ACCEPTED).build();
    }
}
Also used : SysClientException(com.emc.storageos.systemservices.exceptions.SysClientException) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 5 with SysClientException

use of com.emc.storageos.systemservices.exceptions.SysClientException in project coprhd-controller by CoprHD.

the class RecoveryManager method initNodeListByCheckOfflineTime.

private void initNodeListByCheckOfflineTime() {
    aliveNodes.clear();
    corruptedNodes.clear();
    ArrayList<String> nodeList = coordinator.getAllNodeIds();
    for (String nodeId : nodeList) {
        try {
            DbOfflineStatus dbOfflineStatus = SysClientFactory.getSysClient(coordinator.getNodeEndpoint(nodeId)).get(SysClientFactory.URI_GET_DB_OFFLINE_STATUS, DbOfflineStatus.class, null);
            if (dbOfflineStatus.getOutageTimeExceeded()) {
                corruptedNodes.add(nodeId);
            } else {
                aliveNodes.add(nodeId);
            }
        } catch (SysClientException e) {
            log.warn("Internal error on clean up purge data: ", e.getMessage());
            throw e;
        }
    }
    log.info("Alive nodes:{}, corrupted nodes: {}", aliveNodes, corruptedNodes);
}
Also used : DbOfflineStatus(com.emc.vipr.model.sys.recovery.DbOfflineStatus) SysClientException(com.emc.storageos.systemservices.exceptions.SysClientException)

Aggregations

SysClientException (com.emc.storageos.systemservices.exceptions.SysClientException)10 URI (java.net.URI)5 Service (com.emc.storageos.coordinator.common.Service)3 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 NodeHardwareInfoRestRep (com.emc.vipr.model.sys.healthmonitor.NodeHardwareInfoRestRep)2 POST (javax.ws.rs.POST)2 DbOfflineStatus (com.emc.vipr.model.sys.recovery.DbOfflineStatus)1 GET (javax.ws.rs.GET)1