Search in sources :

Example 1 with AvailabilityStatusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AvailabilityStatusType in project midpoint by Evolveum.

the class ResourceDetailsTabPanel method createLastAvailabilityStatusInfo.

private InfoBoxPanel createLastAvailabilityStatusInfo(ResourceType resource) {
    String messageKey = "PageResource.resource.availabilityUnknown";
    String backgroundColor = "bg-gray";
    String icon = "fa-question";
    OperationalStateType operationalState = resource.getOperationalState();
    if (operationalState != null) {
        AvailabilityStatusType lastAvailabilityStatus = operationalState.getLastAvailabilityStatus();
        if (lastAvailabilityStatus != null) {
            if (lastAvailabilityStatus == AvailabilityStatusType.UP) {
                messageKey = "PageResource.resource.up";
                backgroundColor = "bg-green";
                icon = "fa-power-off";
            } else if (lastAvailabilityStatus == AvailabilityStatusType.DOWN) {
                backgroundColor = "bg-red";
                messageKey = "PageResource.resource.down";
                icon = "fa-ban";
            } else if (lastAvailabilityStatus == AvailabilityStatusType.BROKEN) {
                backgroundColor = "bg-yellow";
                messageKey = "PageResource.resource.broken";
                icon = "fa-warning";
            }
        }
    }
    InfoBoxType infoBoxType = new InfoBoxType(backgroundColor, icon, parentPage.getString(messageKey));
    ConnectorType connectorType = resource.getConnector();
    if (connectorType == null) {
        // Connector not found. Probably bad connectorRef reference.
        infoBoxType.setNumber("--");
        infoBoxType.setDescription("--");
    } else {
        String connectorName = StringUtils.substringAfterLast(WebComponentUtil.getEffectiveName(connectorType, ConnectorType.F_CONNECTOR_TYPE), ".");
        String connectorVersion = connectorType.getConnectorVersion();
        infoBoxType.setNumber(connectorName);
        infoBoxType.setDescription(connectorVersion);
    }
    Model<InfoBoxType> boxModel = new Model<InfoBoxType>(infoBoxType);
    InfoBoxPanel lastAvailabilityStatus = new InfoBoxPanel(ID_LAST_AVAILABILITY_STATUS, boxModel);
    lastAvailabilityStatus.setOutputMarkupId(true);
    return lastAvailabilityStatus;
}
Also used : InfoBoxType(com.evolveum.midpoint.web.component.box.InfoBoxType) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) OperationalStateType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationalStateType) IModel(org.apache.wicket.model.IModel) ListModel(org.apache.wicket.model.util.ListModel) Model(org.apache.wicket.model.Model) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) AvailabilityStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.AvailabilityStatusType) InfoBoxPanel(com.evolveum.midpoint.web.component.box.InfoBoxPanel)

Example 2 with AvailabilityStatusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AvailabilityStatusType in project midpoint by Evolveum.

the class ResourceManager method modifyResourceAvailabilityStatus.

public void modifyResourceAvailabilityStatus(PrismObject<ResourceType> resource, AvailabilityStatusType status, OperationResult result) {
    ResourceType resourceType = resource.asObjectable();
    synchronized (resource) {
        if (resourceType.getOperationalState() == null || resourceType.getOperationalState().getLastAvailabilityStatus() == null || resourceType.getOperationalState().getLastAvailabilityStatus() != status) {
            List<PropertyDelta<?>> modifications = new ArrayList<PropertyDelta<?>>();
            PropertyDelta<?> statusDelta = createResourceAvailabilityStatusDelta(resource, status);
            modifications.add(statusDelta);
            try {
                repositoryService.modifyObject(ResourceType.class, resourceType.getOid(), modifications, result);
            } catch (SchemaException ex) {
                throw new SystemException(ex);
            } catch (ObjectAlreadyExistsException ex) {
                throw new SystemException(ex);
            } catch (ObjectNotFoundException ex) {
                throw new SystemException(ex);
            }
        }
        // ugly hack: change object even if it's immutable
        boolean immutable = resource.isImmutable();
        if (immutable) {
            resource.setImmutable(false);
        }
        if (resourceType.getOperationalState() == null) {
            OperationalStateType operationalState = new OperationalStateType();
            operationalState.setLastAvailabilityStatus(status);
            resourceType.setOperationalState(operationalState);
        } else {
            resourceType.getOperationalState().setLastAvailabilityStatus(status);
        }
        if (immutable) {
            resource.setImmutable(true);
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationalStateType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationalStateType) ArrayList(java.util.ArrayList) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Aggregations

OperationalStateType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationalStateType)2 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)1 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)1 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 InfoBoxPanel (com.evolveum.midpoint.web.component.box.InfoBoxPanel)1 InfoBoxType (com.evolveum.midpoint.web.component.box.InfoBoxType)1 AvailabilityStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.AvailabilityStatusType)1 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)1 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)1 ArrayList (java.util.ArrayList)1 IModel (org.apache.wicket.model.IModel)1 Model (org.apache.wicket.model.Model)1 ListModel (org.apache.wicket.model.util.ListModel)1