Search in sources :

Example 1 with GlusterServiceStatus

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterServiceStatus in project ovirt-engine by oVirt.

the class ManageGlusterSwiftPopupView method initEditors.

private void initEditors() {
    swiftStatusEditor = new EntityModelLabelEditor<>(new EnumRenderer<GlusterServiceStatus>());
    // $NON-NLS-1$
    startSwift = new EntityModelRadioButtonEditor("swift_action", Align.RIGHT);
    // $NON-NLS-1$
    stopSwift = new EntityModelRadioButtonEditor("swift_action", Align.RIGHT);
    // $NON-NLS-1$
    restartSwift = new EntityModelRadioButtonEditor("swift_action", Align.RIGHT);
    manageSwiftServerLevel = new EntityModelCheckBoxEditor(Align.RIGHT);
    hostServicesTable = new EntityModelCellTable<>(false, true);
    hostServicesTable.addColumn(new AbstractEntityModelTextColumn<GlusterServerService>() {

        @Override
        public String getText(GlusterServerService entity) {
            return entity.getHostName();
        }
    }, constants.hostGlusterSwift());
    hostServicesTable.addColumn(new AbstractEnumColumn<EntityModel, ServiceType>() {

        @Override
        protected ServiceType getRawValue(EntityModel object) {
            return ((GlusterSwiftServiceModel) object).getEntity().getServiceType();
        }
    }, constants.serviceNameGlusterSwift());
    hostServicesTable.addColumn(new AbstractEnumColumn<EntityModel, GlusterServiceStatus>() {

        @Override
        protected GlusterServiceStatus getRawValue(EntityModel object) {
            return ((GlusterSwiftServiceModel) object).getEntity().getStatus();
        }
    }, constants.serviceStatusGlusterSwift());
    Column<EntityModel, Boolean> startSwiftColumn = new Column<EntityModel, Boolean>(new RadioboxCell(false, true)) {

        @Override
        public Boolean getValue(EntityModel object) {
            GlusterSwiftServiceModel swiftServiceModel = (GlusterSwiftServiceModel) object;
            return swiftServiceModel.getStartSwift().getEntity();
        }

        @Override
        public void render(Context context, EntityModel object, SafeHtmlBuilder sb) {
            GlusterSwiftServiceModel swiftServiceModel = (GlusterSwiftServiceModel) object;
            if (swiftServiceModel.getStartSwift().getIsChangable()) {
                super.render(context, object, sb);
            }
        }
    };
    startSwiftColumn.setFieldUpdater((index, object, value) -> {
        GlusterSwiftServiceModel swiftModel = (GlusterSwiftServiceModel) object;
        swiftModel.getStartSwift().setEntity(value);
        if (value) {
            swiftModel.getStopSwift().setEntity(false);
            swiftModel.getRestartSwift().setEntity(false);
            hostServicesTable.redraw();
        }
    });
    hostServicesTable.addColumn(startSwiftColumn, constants.startGlusterSwift());
    Column<EntityModel, Boolean> stopSwiftColumn = new Column<EntityModel, Boolean>(new RadioboxCell(false, true)) {

        @Override
        public Boolean getValue(EntityModel object) {
            GlusterSwiftServiceModel swiftServiceModel = (GlusterSwiftServiceModel) object;
            return swiftServiceModel.getStopSwift().getEntity();
        }

        @Override
        public void render(Context context, EntityModel object, SafeHtmlBuilder sb) {
            GlusterSwiftServiceModel swiftServiceModel = (GlusterSwiftServiceModel) object;
            if (swiftServiceModel.getStopSwift().getIsChangable()) {
                super.render(context, object, sb);
            }
        }
    };
    stopSwiftColumn.setFieldUpdater((index, object, value) -> {
        GlusterSwiftServiceModel swiftModel = (GlusterSwiftServiceModel) object;
        if (swiftModel.getStopSwift().getIsChangable()) {
            swiftModel.getStopSwift().setEntity(value);
            if (value) {
                swiftModel.getStartSwift().setEntity(false);
                swiftModel.getRestartSwift().setEntity(false);
                hostServicesTable.redraw();
            }
        }
    });
    hostServicesTable.addColumn(stopSwiftColumn, constants.stopGlusterSwift());
    Column<EntityModel, Boolean> restartSwiftColumn = new Column<EntityModel, Boolean>(new RadioboxCell(false, true)) {

        @Override
        public Boolean getValue(EntityModel object) {
            GlusterSwiftServiceModel swiftServiceModel = (GlusterSwiftServiceModel) object;
            return swiftServiceModel.getRestartSwift().getEntity();
        }

        @Override
        public void render(Context context, EntityModel object, SafeHtmlBuilder sb) {
            GlusterSwiftServiceModel swiftServiceModel = (GlusterSwiftServiceModel) object;
            if (swiftServiceModel.getRestartSwift().getIsChangable()) {
                super.render(context, object, sb);
            }
        }
    };
    restartSwiftColumn.setFieldUpdater((index, object, value) -> {
        GlusterSwiftServiceModel swiftModel = (GlusterSwiftServiceModel) object;
        swiftModel.getRestartSwift().setEntity(value);
        if (value) {
            swiftModel.getStartSwift().setEntity(false);
            swiftModel.getStopSwift().setEntity(false);
            hostServicesTable.redraw();
        }
    });
    hostServicesTable.addColumn(restartSwiftColumn, constants.restartGlusterSwift());
}
Also used : Context(com.google.gwt.cell.client.Cell.Context) GlusterServerService(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerService) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) RadioboxCell(org.ovirt.engine.ui.common.widget.table.cell.RadioboxCell) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) EnumRenderer(org.ovirt.engine.ui.common.widget.renderer.EnumRenderer) GlusterServiceStatus(org.ovirt.engine.core.common.businessentities.gluster.GlusterServiceStatus) AbstractEntityModelTextColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractEntityModelTextColumn) AbstractEnumColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractEnumColumn) Column(com.google.gwt.user.cellview.client.Column) ServiceType(org.ovirt.engine.core.common.businessentities.gluster.ServiceType) EntityModelCheckBoxEditor(org.ovirt.engine.ui.common.widget.editor.generic.EntityModelCheckBoxEditor) GlusterSwiftServiceModel(org.ovirt.engine.ui.uicommonweb.models.clusters.GlusterSwiftServiceModel) EntityModelRadioButtonEditor(org.ovirt.engine.ui.common.widget.editor.generic.EntityModelRadioButtonEditor)

Example 2 with GlusterServiceStatus

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterServiceStatus in project ovirt-engine by oVirt.

the class GlusterServiceSyncJob method updateStatusToUnknown.

private Map<String, GlusterServiceStatus> updateStatusToUnknown(Collection<GlusterServerService> existingServices) {
    Map<String, GlusterServiceStatus> serviceStatusMap = new HashMap<>();
    for (GlusterServerService existingService : existingServices) {
        existingService.setStatus(GlusterServiceStatus.UNKNOWN);
        serviceStatusMap.put(existingService.getServiceName(), existingService.getStatus());
    }
    serverServiceDao.updateAll(existingServices);
    return serviceStatusMap;
}
Also used : GlusterServiceStatus(org.ovirt.engine.core.common.businessentities.gluster.GlusterServiceStatus) HashMap(java.util.HashMap) GlusterServerService(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerService)

Example 3 with GlusterServiceStatus

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterServiceStatus in project ovirt-engine by oVirt.

the class GlusterServiceSyncJob method addOrUpdateClusterServices.

private void addOrUpdateClusterServices(Cluster cluster, Map<ServiceType, GlusterServiceStatus> fetchedClusterServiceStatusMap) {
    Map<ServiceType, GlusterClusterService> existingClusterServiceMap = getClusterServiceMap(cluster);
    for (Entry<ServiceType, GlusterServiceStatus> entry : fetchedClusterServiceStatusMap.entrySet()) {
        ServiceType type = entry.getKey();
        GlusterServiceStatus status = entry.getValue();
        GlusterClusterService existingClusterService = existingClusterServiceMap.get(type);
        if (existingClusterService == null) {
            existingClusterServiceMap.put(type, addClusterServiceToDb(cluster, type, status));
        } else if (existingClusterService.getStatus() != status) {
            updateClusterServiceStatus(existingClusterService, status);
        }
    }
}
Also used : GlusterClusterService(org.ovirt.engine.core.common.businessentities.gluster.GlusterClusterService) GlusterServiceStatus(org.ovirt.engine.core.common.businessentities.gluster.GlusterServiceStatus) ServiceType(org.ovirt.engine.core.common.businessentities.gluster.ServiceType)

Example 4 with GlusterServiceStatus

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterServiceStatus in project ovirt-engine by oVirt.

the class GlusterServiceSyncJob method createServiceTypeStatusMap.

private Map<ServiceType, GlusterServiceStatus> createServiceTypeStatusMap(List<Map<String, GlusterServiceStatus>> serviceStatusMaps) {
    Map<ServiceType, GlusterServiceStatus> fetchedServiceTypeStatusMap = new HashMap<>();
    for (Entry<String, GlusterServiceStatus> entry : mergeServiceStatusMaps(serviceStatusMaps).entrySet()) {
        String serviceName = entry.getKey();
        GlusterServiceStatus status = entry.getValue();
        ServiceType type = getServiceNameMap().get(serviceName).getServiceType();
        GlusterServiceStatus foundStatus = fetchedServiceTypeStatusMap.get(type);
        if (foundStatus == null) {
            fetchedServiceTypeStatusMap.put(type, status);
        } else if (foundStatus != status) {
            GlusterServiceStatus finalStatus = getFinalStatus(status, foundStatus);
            fetchedServiceTypeStatusMap.put(type, finalStatus);
        }
    }
    return fetchedServiceTypeStatusMap;
}
Also used : GlusterServiceStatus(org.ovirt.engine.core.common.businessentities.gluster.GlusterServiceStatus) HashMap(java.util.HashMap) ServiceType(org.ovirt.engine.core.common.businessentities.gluster.ServiceType)

Example 5 with GlusterServiceStatus

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterServiceStatus 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

GlusterServiceStatus (org.ovirt.engine.core.common.businessentities.gluster.GlusterServiceStatus)9 HashMap (java.util.HashMap)7 GlusterServerService (org.ovirt.engine.core.common.businessentities.gluster.GlusterServerService)4 ServiceType (org.ovirt.engine.core.common.businessentities.gluster.ServiceType)4 Context (com.google.gwt.cell.client.Cell.Context)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 Column (com.google.gwt.user.cellview.client.Column)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)1 VDS (org.ovirt.engine.core.common.businessentities.VDS)1 GlusterClusterService (org.ovirt.engine.core.common.businessentities.gluster.GlusterClusterService)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 OnTimerMethodAnnotation (org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation)1 EntityModelCheckBoxEditor (org.ovirt.engine.ui.common.widget.editor.generic.EntityModelCheckBoxEditor)1 EntityModelRadioButtonEditor (org.ovirt.engine.ui.common.widget.editor.generic.EntityModelRadioButtonEditor)1 EnumRenderer (org.ovirt.engine.ui.common.widget.renderer.EnumRenderer)1