Skip to content

Commit

Permalink
Add Job Target Restart button
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Mezzasalma <claudio.mezzasalma@eurotech.com>
  • Loading branch information
Claudio Mezzasalma committed Apr 14, 2020
1 parent 2bffe49 commit 5493cea
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 6 deletions.
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2019 Eurotech and/or its affiliates and others
* Copyright (c) 2017, 2020 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -41,6 +41,7 @@ public class JobTabTargetsToolbar extends EntityCRUDToolbar<GwtJobTarget> {
private GwtJob gwtSelectedJob;

private Button jobStartTargetButton;
private Button jobRestartTargetButton;
private Button exportButton;

public JobTabTargetsToolbar(GwtSession currentSession) {
Expand Down Expand Up @@ -85,6 +86,17 @@ public void componentSelected(ButtonEvent buttonEvent) {
jobStartTargetButton.disable();
addExtraButton(jobStartTargetButton);

jobRestartTargetButton = new Button(JOB_MSGS.jobRestartTargetButton(), new KapuaIcon(IconSet.REPEAT), new SelectionListener<ButtonEvent>() {

@Override
public void componentSelected(ButtonEvent buttonEvent) {
JobTargetRestartTargetDialog dialog = new JobTargetRestartTargetDialog(gwtSelectedJob, gridSelectionModel.getSelectedItem());
dialog.show();
}
});
jobRestartTargetButton.disable();
addExtraButton(jobRestartTargetButton);

exportButton = new Button(JOB_MSGS.exportToCSV(), new KapuaIcon(IconSet.FILE_TEXT_O),
new SelectionListener<ButtonEvent>() {

Expand Down Expand Up @@ -117,6 +129,7 @@ protected void updateButtonEnablement() {
super.updateButtonEnablement();

jobStartTargetButton.setEnabled(selectedEntity != null && currentSession.hasPermission(JobSessionPermission.execute()));
jobRestartTargetButton.setEnabled(selectedEntity != null && currentSession.hasPermission(JobSessionPermission.execute()));
addEntityButton.setEnabled(selectedEntity != null && currentSession.hasPermission(JobSessionPermission.write()));
deleteEntityButton
.setEnabled(selectedEntity != null && currentSession.hasPermission(JobSessionPermission.delete())
Expand Down Expand Up @@ -154,6 +167,9 @@ public void onSuccess(GwtJob result) {
if (jobStartTargetButton != null) {
jobStartTargetButton.setEnabled(gridSelectionModel != null && gridSelectionModel.getSelectedItem() != null && currentSession.hasPermission(JobSessionPermission.execute()));
}
if (jobRestartTargetButton != null) {
jobRestartTargetButton.setEnabled(gridSelectionModel != null && gridSelectionModel.getSelectedItem() != null && currentSession.hasPermission(JobSessionPermission.execute()));
}
}
});
} else {
Expand All @@ -166,6 +182,9 @@ public void onSuccess(GwtJob result) {
if (jobStartTargetButton != null) {
jobStartTargetButton.setEnabled(false);
}
if (jobRestartTargetButton != null) {
jobRestartTargetButton.setEnabled(false);
}
if (exportButton != null) {
exportButton.setEnabled(false);
}
Expand Down
@@ -0,0 +1,88 @@
/*******************************************************************************
* Copyright (c) 2020 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.app.console.module.job.client.targets;

import org.eclipse.kapua.app.console.module.api.client.resources.icons.IconSet;
import org.eclipse.kapua.app.console.module.api.client.resources.icons.KapuaIcon;
import org.eclipse.kapua.app.console.module.api.client.ui.dialog.SimpleDialog;
import org.eclipse.kapua.app.console.module.api.client.util.ConsoleInfo;
import org.eclipse.kapua.app.console.module.api.client.util.DialogUtils;
import org.eclipse.kapua.app.console.module.job.client.messages.ConsoleJobMessages;
import org.eclipse.kapua.app.console.module.job.shared.model.GwtJob;
import org.eclipse.kapua.app.console.module.job.shared.model.GwtJobTarget;
import org.eclipse.kapua.app.console.module.job.shared.service.GwtJobEngineService;
import org.eclipse.kapua.app.console.module.job.shared.service.GwtJobEngineServiceAsync;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class JobTargetRestartTargetDialog extends SimpleDialog {

private static final ConsoleJobMessages JOB_MSGS = GWT.create(ConsoleJobMessages.class);

private static final GwtJobEngineServiceAsync JOB_ENGINE_SERVICE = GWT.create(GwtJobEngineService.class);

private final GwtJob gwtJob;
private final GwtJobTarget gwtJobTarget;

public JobTargetRestartTargetDialog(GwtJob gwtJob, GwtJobTarget gwtJobTarget) {
this.gwtJob = gwtJob;
this.gwtJobTarget = gwtJobTarget;

DialogUtils.resizeDialog(this, 300, 135);
}

@Override
public void createBody() {
// No action needed
}

@Override
protected void addListeners() {
// No action needed
}

@Override
public void submit() {
JOB_ENGINE_SERVICE.restart(gwtJob.getScopeId(), gwtJob.getId(), gwtJobTarget.getId(), new AsyncCallback<Void>() {

@Override
public void onFailure(Throwable caught) {
ConsoleInfo.display(MSGS.popupError(), JOB_MSGS.jobStartTargetErrorMessage(caught.getLocalizedMessage()));
unmask();
hide();
}

@Override
public void onSuccess(Void result) {
ConsoleInfo.display(MSGS.popupInfo(), JOB_MSGS.jobStartTargetStartedMessage());
unmask();
hide();
}
});
}

@Override
public String getHeaderMessage() {
return JOB_MSGS.jobStartTargetDialogHeader(gwtJob.getJobName(), gwtJobTarget.getClientId());
}

@Override
public KapuaIcon getInfoIcon() {
return new KapuaIcon(IconSet.WARNING);
}

@Override
public String getInfoMessage() {
return JOB_MSGS.jobStartTargetDialogInfo();
}
}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2019 Eurotech and/or its affiliates and others
* Copyright (c) 2017, 2020 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -33,6 +33,7 @@
import org.eclipse.kapua.service.job.execution.JobExecutionService;

import java.util.ArrayList;
import java.util.Collections;

public class GwtJobEngineServiceImpl extends KapuaRemoteServiceServlet implements GwtJobEngineService {

Expand Down Expand Up @@ -114,11 +115,19 @@ public void stopExecution(String gwtScopeId, String gwtJobId, String gwtJobExecu

@Override
public void restart(String gwtScopeId, String gwtJobId) throws GwtKapuaException {
restart(gwtScopeId, gwtJobId, null);
}

@Override
public void restart(String gwtScopeId, String gwtJobId, String gwtJobTargetId) throws GwtKapuaException {
GwtJobStartOptions gwtJobStartOptions = new GwtJobStartOptions();
gwtJobStartOptions.setResetStepIndex(true);
gwtJobStartOptions.setFromStepIndex(0);
gwtJobStartOptions.setTargetIdSublist(new ArrayList<String>());

if (gwtJobTargetId == null) {
gwtJobStartOptions.setTargetIdSublist(new ArrayList<String>());
} else {
gwtJobStartOptions.setTargetIdSublist(Collections.singletonList(gwtJobTargetId));
}
start(gwtScopeId, gwtJobId, gwtJobStartOptions);
}
}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Eurotech and/or its affiliates and others
* Copyright (c) 2017, 2020 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -33,4 +33,7 @@ void stopExecution(String gwtScopeId, String gwtJobId, String gwtJobExecutionId)

void restart(String gwtScopeId, String gwtJobId)
throws GwtKapuaException;

void restart(String gwtScopeId, String gwtJobId, String gwtJobTargetId)
throws GwtKapuaException;
}
@@ -1,5 +1,5 @@
################################################################################
# Copyright (c) 2017, 2019 Eurotech and/or its affiliates and others
# Copyright (c) 2017, 2020 Eurotech and/or its affiliates and others
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -67,6 +67,12 @@ jobRestartDialogInfo=Restart the selected job?<br><br>Please note that restartin
jobRestartRestartedMessage=Job successfully restarted.
jobRestartErrorMessage=Error restarting job: {0}

jobRestartTargetButton=Restart
jobRestartTargetDialogHeader=Restart Job {0} for target {1}
jobRestartTargetDialogInfo=Restart the selected job for the selected target?<br><br>Please note that restarting the job, the target will restart the processing from the first step, regardless of its current step.
jobRestartTargetRestartedMessage=Job successfully restarted.
jobRestartTargetErrorMessage=Error restarting job: {0}

#
# Add dialog
dialogAddHeader=New Job
Expand Down

0 comments on commit 5493cea

Please sign in to comment.