Search in sources :

Example 1 with GlusterServicesListVDSParameters

use of org.ovirt.engine.core.common.vdscommands.gluster.GlusterServicesListVDSParameters in project ovirt-engine by oVirt.

the class GlusterServiceSyncJob method refreshServerServices.

/**
 * Refreshes statuses of services on given server, and returns a map of service name to it's status
 *
 * @param server
 *            The server whose services statuses are to be refreshed
 * @return map of service name to it's status
 */
@SuppressWarnings({ "unchecked", "serial" })
private Map<String, GlusterServiceStatus> refreshServerServices(final VDS server) {
    Map<String, GlusterServiceStatus> serviceStatusMap = new HashMap<>();
    if (server.getStatus() != VDSStatus.Up) {
        // Update the status of all the services of stopped server in single transaction
        TransactionSupport.executeInScope(TransactionScopeOption.Required, () -> updateGlusterServicesStatusForStoppedServer(server));
    } else {
        acquireLock(server.getId());
        try {
            Map<Guid, GlusterServerService> existingServicesMap = getExistingServicesMap(server);
            List<GlusterServerService> servicesToUpdate = new ArrayList<>();
            VDSReturnValue returnValue = runVdsCommand(VDSCommandType.GlusterServicesList, new GlusterServicesListVDSParameters(server.getId(), getServiceNameMap().keySet()));
            if (!returnValue.getSucceeded()) {
                log.error("Couldn't fetch services statuses from server '{}', error: {}! " + "Updating statuses of all services on this server to UNKNOWN.", server.getHostName(), returnValue.getVdsError().getMessage());
                logUtil.logServerMessage(server, AuditLogType.GLUSTER_SERVICES_LIST_FAILED);
                return updateStatusToUnknown(existingServicesMap.values());
            }
            for (final GlusterServerService fetchedService : (List<GlusterServerService>) returnValue.getReturnValue()) {
                serviceStatusMap.put(fetchedService.getServiceName(), fetchedService.getStatus());
                GlusterServerService existingService = existingServicesMap.get(fetchedService.getServiceId());
                if (existingService == null) {
                    insertServerService(server, fetchedService);
                } else {
                    final GlusterServiceStatus oldStatus = existingService.getStatus();
                    final GlusterServiceStatus newStatus = fetchedService.getStatus();
                    if (oldStatus != newStatus) {
                        log.info("Status of service '{}' on server '{}' changed from '{}' to '{}'. Updating in engine now.", fetchedService.getServiceName(), server.getHostName(), oldStatus.name(), newStatus.name());
                        Map<String, String> customValues = new HashMap<>();
                        customValues.put(GlusterConstants.SERVICE_NAME, fetchedService.getServiceName());
                        customValues.put(GlusterConstants.OLD_STATUS, oldStatus.getStatusMsg());
                        customValues.put(GlusterConstants.NEW_STATUS, newStatus.getStatusMsg());
                        logUtil.logAuditMessage(server.getClusterId(), server.getClusterName(), null, server, AuditLogType.GLUSTER_SERVER_SERVICE_STATUS_CHANGED, customValues);
                        existingService.setStatus(fetchedService.getStatus());
                        servicesToUpdate.add(existingService);
                    }
                }
            }
            if (servicesToUpdate.size() > 0) {
                serverServiceDao.updateAll(servicesToUpdate);
            }
        } finally {
            releaseLock(server.getId());
        }
    }
    return serviceStatusMap;
}
Also used : HashMap(java.util.HashMap) GlusterServerService(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerService) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) GlusterServiceStatus(org.ovirt.engine.core.common.businessentities.gluster.GlusterServiceStatus) ArrayList(java.util.ArrayList) List(java.util.List) GlusterServicesListVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.GlusterServicesListVDSParameters)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 GlusterServerService (org.ovirt.engine.core.common.businessentities.gluster.GlusterServerService)1 GlusterServiceStatus (org.ovirt.engine.core.common.businessentities.gluster.GlusterServiceStatus)1 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)1 GlusterServicesListVDSParameters (org.ovirt.engine.core.common.vdscommands.gluster.GlusterServicesListVDSParameters)1 Guid (org.ovirt.engine.core.compat.Guid)1