Search in sources :

Example 1 with ProgressStatusDTO

use of org.glassfish.api.admin.progress.ProgressStatusDTO in project Payara by payara.

the class ProgressStatusDTOJsonProprietaryReader method readChildProgressStatus.

public static ChildProgressStatusDTO readChildProgressStatus(JsonParser jp) throws IOException {
    ProgressStatusDTO psd = new ProgressStatusDTO();
    int allocatedSteps = 0;
    while (jp.nextToken() != JsonToken.END_OBJECT) {
        String fieldname = jp.getCurrentName();
        // move to value
        jp.nextToken();
        if ("name".equals(fieldname)) {
            psd.setName(jp.getText());
        } else if ("id".equals(fieldname)) {
            psd.setId(jp.getText());
        } else if ("total-step-count".equals(fieldname)) {
            psd.setTotalStepCount(jp.getIntValue());
        } else if ("current-step-count".equals(fieldname)) {
            psd.setCurrentStepCount(jp.getIntValue());
        } else if ("complete".equals(fieldname)) {
            psd.setCompleted(jp.getBooleanValue());
        } else if ("allocated-steps".equals(fieldname)) {
            allocatedSteps = jp.getIntValue();
        } else if ("children".equals(fieldname)) {
            while (jp.nextToken() != JsonToken.END_ARRAY) {
                if (jp.getCurrentToken() == JsonToken.START_OBJECT) {
                    ProgressStatusDTO.ChildProgressStatusDTO child = readChildProgressStatus(jp);
                    psd.getChildren().add(child);
                }
            }
        }
    }
    return new ChildProgressStatusDTO(allocatedSteps, psd);
}
Also used : ChildProgressStatusDTO(org.glassfish.api.admin.progress.ProgressStatusDTO.ChildProgressStatusDTO) ChildProgressStatusDTO(org.glassfish.api.admin.progress.ProgressStatusDTO.ChildProgressStatusDTO) ProgressStatusDTO(org.glassfish.api.admin.progress.ProgressStatusDTO) ChildProgressStatusDTO(org.glassfish.api.admin.progress.ProgressStatusDTO.ChildProgressStatusDTO)

Example 2 with ProgressStatusDTO

use of org.glassfish.api.admin.progress.ProgressStatusDTO in project Payara by payara.

the class ProgressStatusPrinter method onAdminCommandEvent.

@Override
public synchronized void onAdminCommandEvent(String name, GfSseInboundEvent event) {
    try {
        if (CommandProgress.EVENT_PROGRESSSTATUS_STATE.equals(name)) {
            ProgressStatusDTO dto = event.getData(ProgressStatusDTO.class, CONTENT_TYPE);
            client.mirror(dto);
            commandProgress = (CommandProgress) client.getProgressStatus();
            if (StringUtils.ok(commandProgress.getName()) && !StringUtils.ok(commandProgress.getLastMessage())) {
                commandProgress.progress(strings.getString("progressstatus.message.starting", "Starting"));
            }
            printCommandProgress();
        } else if (CommandProgress.EVENT_PROGRESSSTATUS_CHANGE.equals(name)) {
            if (commandProgress == null) {
                logger.log(Level.WARNING, strings.get("progressstatus.event.applyerror", "Inapplicable progress status event"));
                return;
            }
            ProgressStatusEvent pse = event.getData(ProgressStatusEvent.class, CONTENT_TYPE);
            client.mirror(pse);
            printCommandProgress();
        } else if (AdminCommandEventBroker.EventBrokerUtils.USER_MESSAGE_NAME.equals(name)) {
            String msg = event.getData();
            printUserMessage(msg);
        }
    } catch (IOException ex) {
        logger.log(Level.SEVERE, strings.get("progressstatus.event.parseerror", "Can not parse progress status event"), ex);
    }
}
Also used : ProgressStatusEvent(org.glassfish.api.admin.progress.ProgressStatusEvent) IOException(java.io.IOException) ProgressStatusDTO(org.glassfish.api.admin.progress.ProgressStatusDTO)

Example 3 with ProgressStatusDTO

use of org.glassfish.api.admin.progress.ProgressStatusDTO in project Payara by payara.

the class ProgressStatusClient method mirror.

private void mirror(ProgressStatusDTO dto, ProgressStatus stat) {
    // TODO: copy-paste problem because of ProgressStatusDTO and ProgressStatusBase we have to create shared interface
    stat.setTotalStepCount(dto.getTotalStepCount());
    stat.setCurrentStepCount(dto.getCurrentStepCount());
    if (dto.isCompleted()) {
        stat.complete();
    }
    for (ProgressStatusDTO.ChildProgressStatusDTO chld : dto.getChildren()) {
        ProgressStatus dst = map.get(chld.getProgressStatus().getId());
        if (dst == null) {
            dst = stat.createChild(chld.getProgressStatus().getName(), chld.getAllocatedSteps());
            map.put(chld.getProgressStatus().getId(), dst);
        }
        mirror(chld.getProgressStatus(), dst);
    }
}
Also used : ProgressStatus(org.glassfish.api.admin.ProgressStatus) ProgressStatusDTO(org.glassfish.api.admin.progress.ProgressStatusDTO)

Aggregations

ProgressStatusDTO (org.glassfish.api.admin.progress.ProgressStatusDTO)3 IOException (java.io.IOException)1 ProgressStatus (org.glassfish.api.admin.ProgressStatus)1 ChildProgressStatusDTO (org.glassfish.api.admin.progress.ProgressStatusDTO.ChildProgressStatusDTO)1 ProgressStatusEvent (org.glassfish.api.admin.progress.ProgressStatusEvent)1