Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature job delete forced #2626

Merged
merged 2 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

import org.eclipse.kapua.app.console.module.api.client.messages.ConsoleMessages;
import org.eclipse.kapua.app.console.module.api.client.ui.grid.CreatedByNameCellRenderer;
import org.eclipse.kapua.app.console.module.api.client.ui.grid.EntityGrid;
Expand Down Expand Up @@ -75,6 +74,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()));
((JobGridToolbar) getToolbar()).getRestartJobButton().setEnabled(selectedItem != null && currentSession.hasPermission(JobSessionPermission.execute()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class JobGridToolbar extends EntityCRUDToolbar<GwtJob> {
private Button startJobButton;
private Button stopJobButton;
private Button restartJobButton;
private Button deleteForcedJobButton;

public JobGridToolbar(GwtSession currentSession) {
super(currentSession);
Expand All @@ -50,6 +51,10 @@ public Button getRestartJobButton() {
return restartJobButton;
}

public Button getDeleteForcedJobButton() {
return deleteForcedJobButton;
}

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

Expand Down Expand Up @@ -89,6 +94,20 @@ public void componentSelected(ButtonEvent buttonEvent) {
restartJobButton.disable();
addExtraButton(restartJobButton);

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
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class GwtJobServiceImpl extends KapuaRemoteServiceServlet implements GwtJ
private static final UserFactory USER_FACTORY = LOCATOR.getFactory(UserFactory.class);

@Override
public PagingLoadResult<GwtJob> query(PagingLoadConfig loadConfig, final GwtJobQuery gwtJobQuery) throws GwtKapuaException {
public PagingLoadResult<GwtJob> query(PagingLoadConfig loadConfig, GwtJobQuery gwtJobQuery) throws GwtKapuaException {
//
// Do query
int totalLength = 0;
Expand Down Expand Up @@ -192,15 +192,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 {
String gwtJobId) throws GwtKapuaException {
List<GwtGroupedNVPair> gwtJobDescription = new ArrayList<GwtGroupedNVPair>();
try {
final KapuaId scopeId = KapuaEid.parseCompactId(gwtScopeId);
KapuaId scopeId = KapuaEid.parseCompactId(gwtScopeId);
KapuaId jobId = KapuaEid.parseCompactId(gwtJobId);

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

UserListResult userListResult = KapuaSecurityUtils.doPrivileged(new Callable<UserListResult>() {

Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ gridJobSchedulesColumnHeaderEndsOnFormatted=Ends on
gridJobSchedulesColumnHeaderTriggerDefinitionName=Schedule Type
gridJobSchedulesColumnHeaderValue=Value

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
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ public void cleanJobData(KapuaId scopeId, KapuaId jobId) throws KapuaException {
if (JbatchDriver.isRunningJob(scopeId, jobId)) {
throw new JobRunningException(scopeId, jobId);
}

try {
JbatchDriver.cleanJobData(scopeId, jobId);
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,24 @@ public void afterJob() throws Exception {

KapuaId kapuaExecutionId = jobContextWrapper.getKapuaExecutionId();
if (kapuaExecutionId == null) {
String msg = String.format("Cannot update job execution (internal reference [%d]). Cannot find 'executionId' in JobContext", jobContextWrapper.getExecutionId());
LOG.error(msg);
LOG.error("Cannot update job execution (internal reference [{}]). Cannot find 'executionId' in JobContext", jobContextWrapper.getExecutionId());
// Don't send any exception to prevent the job engine to set the job exit status as failed!
} else {
JobExecution jobExecution = KapuaSecurityUtils.doPrivileged(() -> JOB_EXECUTION_SERVICE.find(jobContextWrapper.getScopeId(), kapuaExecutionId));

jobExecution.setLog(jobLogger.flush());
jobExecution.setEndedOn(new Date());
if (jobExecution != null) {
jobExecution.setLog(jobLogger.flush());
jobExecution.setEndedOn(new Date());

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

checkQueuedJobExecutions(
jobContextWrapper.getScopeId(),
jobContextWrapper.getJobId(),
jobContextWrapper.getKapuaExecutionId());
checkQueuedJobExecutions(
jobContextWrapper.getScopeId(),
jobContextWrapper.getJobId(),
jobContextWrapper.getKapuaExecutionId());
} else {
LOG.warn("Cannot find job execution with id: {}. This is likely to happen with the Job has been forcibly deleted.", kapuaExecutionId);
}
}
jobLogger.info("Running after job... DONE!");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Eurotech and/or its affiliates and others
* 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
Expand All @@ -12,6 +12,7 @@
package org.eclipse.kapua.service.job;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.model.query.KapuaQuery;
import org.eclipse.kapua.service.KapuaEntityService;
import org.eclipse.kapua.service.KapuaUpdatableEntityService;
Expand All @@ -37,6 +38,16 @@ public interface JobService extends KapuaEntityService<Job, JobCreator>,
* @since 1.0.0
*/
@Override
JobListResult query(KapuaQuery<Job> query)
throws KapuaException;
JobListResult query(KapuaQuery<Job> query) throws KapuaException;

/**
* Forcibly deletes a {@link Job} and all of its related data without checking for {@link org.eclipse.kapua.service.job.execution.JobExecution}s.
*
* @param scopeId The {@link KapuaId} scopeId of the {@link Job}.
* @param jobId The {@link KapuaId} of the {@link Job}.
* @throws KapuaException
* @since 1.1.0
*/
void deleteForced(KapuaId scopeId, KapuaId jobId) throws KapuaException;

}
Loading