Skip to content

Commit

Permalink
Added 'Force Delete' in console
Browse files Browse the repository at this point in the history
Signed-off-by: coduz <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Jul 12, 2019
1 parent 50c742b commit f803bf7
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 19 deletions.
@@ -0,0 +1,74 @@
/*******************************************************************************
* Copyright (c) 2017, 2019 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;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
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.entity.EntityDeleteDialog;
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.service.GwtJobService;
import org.eclipse.kapua.app.console.module.job.shared.service.GwtJobServiceAsync;

public class JobDeleteForcedDialog extends EntityDeleteDialog {

private final GwtJob selectedJob;

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

public JobDeleteForcedDialog(GwtJob selectedJob) {
this.selectedJob = selectedJob;
DialogUtils.resizeDialog(this, 300, 135);
// setDisabledFormPanelEvents(true);
}

@Override
public void submit() {
GWT_JOB_SERVICE.deleteForced(xsrfToken, selectedJob.getScopeId(), selectedJob.getId(), new AsyncCallback<Void>() {

@Override
public void onSuccess(Void arg0) {
exitStatus = true;
exitMessage = JOB_MSGS.dialogDeleteForcedStoppedMessage();
hide();
}

@Override
public void onFailure(Throwable cause) {
exitStatus = false;
// if (!isPermissionErrorMessage(cause)) {
exitMessage = JOB_MSGS.dialogDeleteForcedErrorMessage();
// }
hide();
}
});
}

@Override
public String getHeaderMessage() {
return JOB_MSGS.dialogDeleteForcedDialogHeader(selectedJob.getJobName());
}

@Override
public String getInfoMessage() {
return JOB_MSGS.dialogDeleteForcedDialogInfo();
}

@Override
public KapuaIcon getInfoIcon() {
return new KapuaIcon(IconSet.EXCLAMATION_TRIANGLE);
}
}
Expand Up @@ -70,6 +70,7 @@ protected void selectionChangedEvent(GwtJob selectedItem) {
getToolbar().getEditEntityButton().setEnabled(selectedItem != null && currentSession.hasPermission(JobSessionPermission.write()));
getToolbar().getDeleteEntityButton().setEnabled(selectedItem != null && currentSession.hasPermission(JobSessionPermission.delete()));

((JobGridToolbar) getToolbar()).getDeleteForcedJobButton().setEnabled(selectedItem != null && currentSession.hasPermission(JobSessionPermission.deleteAll()));
((JobGridToolbar) getToolbar()).getStartJobButton().setEnabled(selectedItem != null && currentSession.hasPermission(JobSessionPermission.execute()));
((JobGridToolbar) getToolbar()).getStopJobButton().setEnabled(selectedItem != null && currentSession.hasPermission(JobSessionPermission.execute()));
}
Expand Down
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.kapua.app.console.module.job.client;

import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Element;
Expand All @@ -31,6 +32,7 @@ public class JobGridToolbar extends EntityCRUDToolbar<GwtJob> {

private Button startJobButton;
private Button stopJobButton;
private Button deleteForcedJobButton;

public JobGridToolbar(GwtSession currentSession) {
super(currentSession);
Expand All @@ -44,6 +46,10 @@ public Button getStopJobButton() {
return stopJobButton;
}

public Button getDeleteForcedJobButton() {
return deleteForcedJobButton;
}

@Override
protected void onRender(Element target, int index) {

Expand All @@ -69,6 +75,20 @@ public void componentSelected(ButtonEvent buttonEvent) {
stopJobButton.disable();
addExtraButton(stopJobButton);

deleteForcedJobButton = new Button(JOB_MSGS.jobDeleteForcedButton(), new KapuaIcon(IconSet.EXCLAMATION_TRIANGLE), new SelectionListener<ButtonEvent>() {

@Override
public void componentSelected(ButtonEvent buttonEvent) {
JobDeleteForcedDialog dialog = new JobDeleteForcedDialog(gridSelectionModel.getSelectedItem());
dialog.addListener(Events.Hide, getHideDialogListener());
dialog.show();
}
});
deleteForcedJobButton.disable();
if (currentSession.hasPermission(JobSessionPermission.deleteAll())) {
addExtraButton(deleteForcedJobButton);
}

super.onRender(target, index);

getEditEntityButton().disable();
Expand Down
Expand Up @@ -68,7 +68,7 @@ public PagingLoadResult<GwtJob> query(PagingLoadConfig loadConfig, GwtJobQuery g
try {

// Convert from GWT entity
JobQuery jobQuery = GwtKapuaJobModelConverter.convertJobQuery(gwtJobQuery, loadConfig);
final JobQuery jobQuery = GwtKapuaJobModelConverter.convertJobQuery(gwtJobQuery, loadConfig);

// query
JobListResult jobs = JOB_SERVICE.query(jobQuery);
Expand All @@ -80,7 +80,7 @@ public PagingLoadResult<GwtJob> query(PagingLoadConfig loadConfig, GwtJobQuery g

@Override
public UserListResult call() throws Exception {
return USER_SERVICE.query(USER_FACTORY.newQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtJobQuery.getScopeId())));
return USER_SERVICE.query(USER_FACTORY.newQuery(jobQuery.getScopeId()));
}
});
Map<String, String> usernameMap = new HashMap<String, String>();
Expand Down Expand Up @@ -191,15 +191,29 @@ public void delete(GwtXSRFToken xsrfToken, String gwtScopeId, String gwtJobId) t
}
}

@Override
public void deleteForced(GwtXSRFToken xsrfToken, String gwtScopeId, String gwtJobId) throws GwtKapuaException {
checkXSRFToken(xsrfToken);

try {
KapuaId scopeId = GwtKapuaCommonsModelConverter.convertKapuaId(gwtScopeId);
KapuaId jobId = GwtKapuaCommonsModelConverter.convertKapuaId(gwtJobId);

JOB_SERVICE.deleteForced(scopeId, jobId);
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
}

@Override
public ListLoadResult<GwtGroupedNVPair> findJobDescription(String gwtScopeId,
String gwtJobId) throws GwtKapuaException {
List<GwtGroupedNVPair> gwtJobDescription = new ArrayList<GwtGroupedNVPair>();
try {
KapuaId scopeId = KapuaEid.parseCompactId(gwtScopeId);
final KapuaId scopeId = KapuaEid.parseCompactId(gwtScopeId);
KapuaId jobId = KapuaEid.parseCompactId(gwtJobId);

Job job = JOB_SERVICE.find(scopeId, jobId);
final Job job = JOB_SERVICE.find(scopeId, jobId);

final User createdUser = KapuaSecurityUtils.doPrivileged(new Callable<User>() {

Expand Down
Expand Up @@ -22,7 +22,11 @@ protected JobSessionPermission() {
}

private JobSessionPermission(GwtSessionPermissionAction action) {
super("job", action, GwtSessionPermissionScope.SELF);
this(action, GwtSessionPermissionScope.SELF);
}

private JobSessionPermission(GwtSessionPermissionAction action, GwtSessionPermissionScope scope) {
super("job", action, scope);
}

public static JobSessionPermission read() {
Expand All @@ -37,6 +41,10 @@ public static JobSessionPermission delete() {
return new JobSessionPermission(GwtSessionPermissionAction.delete);
}

public static JobSessionPermission deleteAll() {
return new JobSessionPermission(GwtSessionPermissionAction.delete, GwtSessionPermissionScope.ALL);
}

public static JobSessionPermission execute() {
return new JobSessionPermission(GwtSessionPermissionAction.execute);
}
Expand Down
Expand Up @@ -36,8 +36,7 @@ PagingLoadResult<GwtJob> query(PagingLoadConfig loadConfig, GwtJobQuery gwtJobQu
* @return
* @throws GwtKapuaException
*/
GwtJob create(GwtXSRFToken xsrfToken, GwtJobCreator gwtJobCreator)
throws GwtKapuaException;
GwtJob create(GwtXSRFToken xsrfToken, GwtJobCreator gwtJobCreator) throws GwtKapuaException;

/**
* Returns a Job by its Id or null if a job with such Id does not exist.
Expand All @@ -46,8 +45,7 @@ GwtJob create(GwtXSRFToken xsrfToken, GwtJobCreator gwtJobCreator)
* @return
* @throws GwtKapuaException
*/
GwtJob find(String accountId, String jobId)
throws GwtKapuaException;
GwtJob find(String accountId, String jobId) throws GwtKapuaException;

/**
* Updates a Job in the database and returns the refreshed/reloaded entity instance.
Expand All @@ -56,18 +54,24 @@ GwtJob find(String accountId, String jobId)
* @return
* @throws GwtKapuaException
*/
GwtJob update(GwtXSRFToken xsrfToken, GwtJob gwtJob)
throws GwtKapuaException;
GwtJob update(GwtXSRFToken xsrfToken, GwtJob gwtJob) throws GwtKapuaException;

/**
* Delete the supplied Job.
*
* @param gwtJobId
* @throws GwtKapuaException
*/
void delete(GwtXSRFToken xsfrToken, String accountId, String gwtJobId)
throws GwtKapuaException;
void delete(GwtXSRFToken xsfrToken, String accountId, String gwtJobId) throws GwtKapuaException;

ListLoadResult<GwtGroupedNVPair> findJobDescription(String gwtScopeId, String gwtJobId)
throws GwtKapuaException;
/**
* Delete the supplied Job forcibly.
*
* @param gwtJobId
* @throws GwtKapuaException
*/
void deleteForced(GwtXSRFToken xsfrToken, String accountId, String gwtJobId) throws GwtKapuaException;


ListLoadResult<GwtGroupedNVPair> findJobDescription(String gwtScopeId, String gwtJobId) throws GwtKapuaException;
}
Expand Up @@ -37,6 +37,12 @@ gridJobSchedulesColumnHeaderEndsOnFormatted=Ends on
gridJobSchedulesColumnHeaderCronScheduling=Cron scheduling
gridJobSchedulesColumnHeaderRetryInterval=Retry interval

jobDeleteForcedButton=Force Delete
dialogDeleteForcedDialogHeader=Delete Job: {0}
dialogDeleteForcedDialogInfo=Delete the selected job forcibly? This can lead to errors in the Job Engine and related components. Use only on critical situations.
dialogDeleteForcedStoppedMessage=Job successfully deleted.
dialogDeleteForcedErrorMessage=Selected job could not be deleted! Please check console log for errors.

jobStartButton=Start
jobStartDialogHeader=Start job: {0}
jobStartDialogInfo=Start the selected job?
Expand Down
Expand Up @@ -66,7 +66,7 @@ public void beforeJob() throws Exception {
List<Long> runningExecutionsIds = BatchRuntime.getJobOperator().getRunningExecutions(jobContextWrapper.getJobName());
if (runningExecutionsIds != null && runningExecutionsIds.size() > 1) {
throw new KapuaIllegalStateException(String.format("Cannot start job [%s]. Another instance of this job is running.", jobContextWrapper.getJobName()));
}
}

LOG.info("JOB {} - {} - Running before job... DONE!", jobContextWrapper.getJobId(), jobContextWrapper.getJobName());
}
Expand All @@ -84,11 +84,11 @@ public void afterJob() throws Exception {
LOG.error(msg);
// TODO will send service events when the feature will be implemented
}
JobExecution jobExecution = KapuaSecurityUtils.doPrivileged(() -> JOB_EXECUTION_SERVICE.find(jobContextWrapper.getScopeId(), kapuaExecutionId));
JobExecution jobExecution = KapuaSecurityUtils.doPrivileged(() -> JOB_EXECUTION_SERVICE.find(jobContextWrapper.getScopeId(), kapuaExecutionId));

jobExecution.setEndedOn(new Date());
jobExecution.setEndedOn(new Date());

KapuaSecurityUtils.doPrivileged(() -> JOB_EXECUTION_SERVICE.update(jobExecution));
KapuaSecurityUtils.doPrivileged(() -> JOB_EXECUTION_SERVICE.update(jobExecution));

LOG.info("JOB {} - {} - Running after job... DONE!", jobContextWrapper.getJobId(), jobContextWrapper.getJobName());
}
Expand Down

0 comments on commit f803bf7

Please sign in to comment.