001/** 002 * Copyright (c) 2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: tao $' 006 * '$Date: 2010-06-03 16:45:10 -0700 (Thu, 03 Jun 2010) $' 007 * '$Revision: 24730 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029package org.kepler.workflowscheduler.gui; 030 031import javax.swing.JOptionPane; 032 033import org.apache.commons.logging.Log; 034import org.apache.commons.logging.LogFactory; 035 036import edu.ucsb.nceas.schedulerclient.WorkflowSchedulerClient; 037import edu.ucsb.nceas.workflowscheduler.scheduler.WorkflowSchedulerException; 038import ptolemy.actor.gui.TableauFrame; 039 040/** 041 * Represents an action to disable a schedule in a scheduler server. 042 * @author tao 043 * 044 */ 045public class DisableScheduleAction extends SchedulerAbstractAction 046{ 047 private static final Log log = LogFactory.getLog(DisableScheduleAction.class 048 .getName()); 049 050 /** 051 * Constructor 052 * @param parent the parent frame of this action 053 * @param scheduleChangeController the GUI controller to handle the schedule change. 054 */ 055 public DisableScheduleAction(TableauFrame parent, WorkflowSchedulerParentPanel schedulerParentPanel, 056 ScheduleChangeController scheduleChangeController) 057 { 058 super(parent, schedulerParentPanel, scheduleChangeController); 059 } 060 061 /** 062 *Disable a schedule in the scheduler server. 063 */ 064 protected void doAction() throws Exception 065 { 066 super.doAction(); 067 if(schedule != null) 068 { 069 String sessionID = null; 070 if(authenDomainForSourceKar != null) 071 { 072 sessionID = domainSessionHash.get(authenDomainForSourceKar); 073 } 074 //System.out.println("the domain name is =========== "+authenDomainForSourceKar); 075 //System.out.println("the authenticationServiceURl is =========== "+authenticationServiceURLForSourceKar); 076 //System.out.println("The session id is ========="+sessionID); 077 WorkflowSchedulerClient client = new WorkflowSchedulerClient(schedulerURL, sessionID, authenticationServiceURLForSourceKar); 078 try 079 { 080 //boolean success = client.unscheduleJob(schedule.getWorkflowJobName(),source.getAuthProtocol()+SLASHCONNECTOR+source.getRepository()+source.getAuthorizationPath()); 081 boolean success = client.unscheduleJob(schedule.getWorkflowJobName()); 082 if(!success) 083 { 084 JOptionPane.showMessageDialog(parent, "Failed to disable schedule.", ERROR, JOptionPane.ERROR_MESSAGE); 085 } 086 else 087 { 088 // make the display change after disabling a schedule 089 if(scheduleChangeController != null) 090 { 091 try 092 { 093 scheduleChangeController.disableSchedule(schedule); 094 } 095 catch(Exception e) 096 { 097 log.error(""+e.getMessage()); 098 } 099 100 } 101 JOptionPane.showMessageDialog(parent, "Successfully disabled schedule.", "Success", JOptionPane.CLOSED_OPTION); 102 } 103 } 104 catch(WorkflowSchedulerException e) 105 { 106 JOptionPane.showMessageDialog(parent, "Failed to disable schedule:\n"+e.getMessage(), ERROR, JOptionPane.ERROR_MESSAGE); 107 if(e != null && e.getMessage() != null && e.getMessage().indexOf("session" )!=-1 && e.getMessage().indexOf("is not valid")!=-1) 108 { 109 //sessionID = null; 110 domainSessionHash.remove(authenDomainForSourceKar); 111 JOptionPane.showMessageDialog(parent, "The login session id is invalid. Please click \"Disable\" menu item again to disable the schedule", "Info", JOptionPane.CLOSED_OPTION); 112 } 113 } 114 } 115 else 116 { 117 JOptionPane.showMessageDialog(parent, "Couldn't disable the schedule since the selected schedule object is null", ERROR, JOptionPane.ERROR_MESSAGE); 118 } 119 120 } 121}