Search in sources :

Example 1 with ServiceType

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

the class ClusterServiceModel method filterServices.

private void filterServices() {
    VDS selectedVds = hostList.getSelectedItem();
    ServiceType serviceType = serviceTypeList.getSelectedItem();
    ArrayList<EntityModel<GlusterServerService>> list = new ArrayList<>();
    List<GlusterServerService> serviceList = new ArrayList<>(getActualServiceList());
    Collections.sort(serviceList, Comparator.comparing(GlusterServerService::getHostName).thenComparing(g -> g.getServiceType().toString()));
    for (GlusterServerService service : serviceList) {
        if ((selectedVds == null || service.getHostName().equals(selectedVds.getHostName())) && (serviceType == null || service.getServiceType() == serviceType)) {
            list.add(new EntityModel<>(service));
        }
    }
    getServiceList().setItems(list);
}
Also used : ServiceType(org.ovirt.engine.core.common.businessentities.gluster.ServiceType) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) List(java.util.List) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) Comparator(java.util.Comparator) Collections(java.util.Collections) VDS(org.ovirt.engine.core.common.businessentities.VDS) GlusterServerService(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerService) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) VDS(org.ovirt.engine.core.common.businessentities.VDS) GlusterServerService(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerService) ServiceType(org.ovirt.engine.core.common.businessentities.gluster.ServiceType) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ArrayList(java.util.ArrayList)

Example 2 with ServiceType

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

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

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

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

the class GlusterServiceSyncJob method refreshGlusterServices.

@OnTimerMethodAnnotation("refreshGlusterServices")
public void refreshGlusterServices() {
    if (getServiceNameMap().isEmpty()) {
        // Lazy loading. Keeping this out of the constructor/getInstance
        // helps in writing the JUnit test as well.
        populateServiceMap();
    }
    List<Cluster> clusters = clusterDao.getAll();
    for (Cluster cluster : clusters) {
        if (supportsGlusterServicesFeature(cluster)) {
            try {
                List<VDS> serversList = glusterUtil.getAllUpServers(cluster.getId());
                // If there are no servers in the cluster, set the status as unknown
                if (serversList.isEmpty()) {
                    Map<ServiceType, GlusterServiceStatus> statusMap = new HashMap<>();
                    for (ServiceType type : getClusterServiceMap(cluster).keySet()) {
                        statusMap.put(type, GlusterServiceStatus.UNKNOWN);
                    }
                    addOrUpdateClusterServices(cluster, statusMap);
                } else {
                    List<Callable<Map<String, GlusterServiceStatus>>> taskList = createTaskList(serversList);
                    if (taskList != null && taskList.size() > 0) {
                        refreshClusterServices(cluster, ThreadPoolUtil.invokeAll(taskList));
                    }
                }
            } catch (Exception e) {
                log.error("Error while refreshing service statuses of cluster '{}': {}", cluster.getName(), e.getMessage());
                log.debug("Exception", e);
            }
        }
    }
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) GlusterServiceStatus(org.ovirt.engine.core.common.businessentities.gluster.GlusterServiceStatus) HashMap(java.util.HashMap) ServiceType(org.ovirt.engine.core.common.businessentities.gluster.ServiceType) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Callable(java.util.concurrent.Callable) OnTimerMethodAnnotation(org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation)

Aggregations

ServiceType (org.ovirt.engine.core.common.businessentities.gluster.ServiceType)6 GlusterServiceStatus (org.ovirt.engine.core.common.businessentities.gluster.GlusterServiceStatus)4 HashMap (java.util.HashMap)3 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)2 VDS (org.ovirt.engine.core.common.businessentities.VDS)2 GlusterClusterService (org.ovirt.engine.core.common.businessentities.gluster.GlusterClusterService)2 GlusterServerService (org.ovirt.engine.core.common.businessentities.gluster.GlusterServerService)2 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)2 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 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)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