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/** 042 * Represents an action to enable a schedule in a scheduler server. 043 * @author tao 044 * 045 */ 046public class EnableScheduleAction extends SchedulerAbstractAction 047{ 048 private static final Log log = LogFactory.getLog(EnableScheduleAction.class 049 .getName()); 050 051 /** 052 * Constructor 053 * @param parent the parent frame of this action 054 * @param scheduleChangeController the GUI controller to handle the schedule change. 055 */ 056 public EnableScheduleAction(TableauFrame parent, WorkflowSchedulerParentPanel schedulerParentPanel, 057 ScheduleChangeController scheduleChangeController) 058 { 059 super(parent, schedulerParentPanel, scheduleChangeController); 060 } 061 062 /** 063 *Enable a schedule in the scheduler server. 064 */ 065 protected void doAction() throws Exception 066 { 067 super.doAction(); 068 if(schedule != null) 069 { 070 String sessionID = null; 071 if(authenDomainForSourceKar != null) 072 { 073 sessionID = domainSessionHash.get(authenDomainForSourceKar); 074 } 075 //System.out.println("the domain name is =========== "+authenDomainForSourceKar); 076 //System.out.println("the authenticationServiceURl is =========== "+authenticationServiceURLForSourceKar); 077 //System.out.println("The session id is ========="+sessionID); 078 WorkflowSchedulerClient client = new WorkflowSchedulerClient(schedulerURL, sessionID, authenticationServiceURLForSourceKar); 079 try 080 { 081 //boolean success = client.rescheduleJob(schedule.getWorkflowJobName(), source.getAuthProtocol()+SLASHCONNECTOR+source.getRepository()+source.getAuthorizationPath()); 082 boolean success = client.rescheduleJob(schedule.getWorkflowJobName()); 083 if(!success) 084 { 085 JOptionPane.showMessageDialog(parent, "Failed to enable schedule.", ERROR, JOptionPane.ERROR_MESSAGE); 086 } 087 else 088 { 089 // make the display change after enabling a schedule 090 if(scheduleChangeController != null) 091 { 092 try 093 { 094 scheduleChangeController.enableSchedule(schedule); 095 } 096 catch(Exception e) 097 { 098 log.error(""+e.getMessage()); 099 } 100 101 } 102 JOptionPane.showMessageDialog(parent, "Successfully enabled schedule.", "Success", JOptionPane.CLOSED_OPTION); 103 } 104 } 105 catch(WorkflowSchedulerException e) 106 { 107 JOptionPane.showMessageDialog(parent, "Failed enabling the schedule:\n"+e.getMessage(), ERROR, JOptionPane.ERROR_MESSAGE); 108 if(e != null && e.getMessage() != null && e.getMessage().indexOf("session" )!=-1 && e.getMessage().indexOf("is not valid")!=-1) 109 { 110 //sessionID = null; 111 domainSessionHash.remove(authenDomainForSourceKar); 112 JOptionPane.showMessageDialog(parent, "The login session id is invalid. Please click \"Enable\" menu item again to enable the schedule", "Info", JOptionPane.CLOSED_OPTION); 113 } 114 } 115 } 116 else 117 { 118 JOptionPane.showMessageDialog(parent, "Couldn't enable the schedule since the selected schedule object is null", ERROR, JOptionPane.ERROR_MESSAGE); 119 } 120 121 } 122}