KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > client > ApplicationReferenceAction


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployment.client;
25
26 import java.util.*;
27 import java.io.IOException JavaDoc;
28
29 import com.sun.enterprise.deployment.backend.DeploymentStatus;
30 import com.sun.enterprise.deployment.util.DeploymentProperties;
31 import com.sun.enterprise.util.i18n.StringManager;
32
33 import javax.enterprise.deploy.spi.Target JavaDoc;
34 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
35 import javax.enterprise.deploy.shared.CommandType JavaDoc;
36 import javax.enterprise.deploy.shared.StateType JavaDoc;
37
38 import com.sun.enterprise.deployapi.SunTarget;
39 import com.sun.enterprise.deployapi.ProgressObjectImpl;
40 import com.sun.enterprise.deployapi.SunTargetModuleID;
41
42 import com.sun.appserv.management.client.ConnectionSource;
43 import com.sun.appserv.management.client.AppserverConnectionSource;
44
45 public class ApplicationReferenceAction extends ProgressObjectImpl {
46     
47     private static StringManager localStrings = StringManager.getManager(ApplicationReferenceAction.class);
48
49     public ApplicationReferenceAction(SunTarget[] targets) {
50         super(targets);
51     }
52
53     private void handleAppRefActionForLifeCycleModules(ConnectionSource dasConnection, SunTarget[] targetList,
54                                             String JavaDoc id, CommandType JavaDoc cmd, Map options) {
55         String JavaDoc action = (CommandType.DISTRIBUTE.equals(cmd)) ? "Creation" : "Removal";
56
57
58         try {
59             for(int i=0; i<targetList.length; i++) {
60                 DeploymentStatus stat = null;
61                 if(CommandType.DISTRIBUTE.equals(cmd)) {
62                     stat = DeploymentClientUtils.createLifecycleModuleReference(
63                         dasConnection.getExistingMBeanServerConnection(), id, targetList[i].getName(), options);
64                 } else {
65                     stat = DeploymentClientUtils.removeLifecycleModuleReference(
66                         dasConnection.getExistingMBeanServerConnection(), id, targetList[i].getName());
67                 }
68                 if(!checkStatusAndAddStage(targetList[i], null, localStrings.getString("enterprise.deployment.client.change_reference", action, targetList[i].getName()), dasConnection, stat)) {
69                     return;
70                 }
71             }
72             setupForNormalExit(localStrings.getString("enterprise.deployment.client.change_reference_lifemodule", action), targetList[0]);
73         } catch(Throwable JavaDoc ioex) {
74             finalDeploymentStatus.setStageException(ioex);
75             setupForAbnormalExit(localStrings.getString("enterprise.deployment.client.change_reference_lifemodule_failed", action, ioex.getMessage()), targetList[0]);
76         }
77         return;
78     }
79     
80     public void run() {
81         ConnectionSource dasConnection= (ConnectionSource) args[0];
82         SunTarget[] targetList = (SunTarget[]) args[1];
83         String JavaDoc moduleID = (String JavaDoc) args[2];
84         CommandType JavaDoc cmd = (CommandType JavaDoc) args[3];
85         Map deployOptions = (Map) args[4];
86             
87         String JavaDoc action = (CommandType.DISTRIBUTE.equals(cmd)) ? "Creation" : "Removal";
88         try {
89             // Handle app-ref-creation/app-ref-removal for life-cycle-module as a special case
90
if(DeploymentClientUtils.isLifecycleModule(dasConnection.getExistingMBeanServerConnection(), moduleID)) {
91                 handleAppRefActionForLifeCycleModules(dasConnection, targetList, moduleID, cmd, deployOptions);
92                 return;
93             }
94         
95             // the target module ids in which the operation was successful
96
ArrayList resultTargetModuleIDs = new ArrayList();
97
98             RollBackAction rollback;
99             if(CommandType.DISTRIBUTE.equals(cmd)) {
100                 rollback = new RollBackAction(RollBackAction.CREATE_APP_REF_OPERATION, moduleID, deployOptions);
101             } else{
102                 rollback = new RollBackAction(RollBackAction.DELETE_APP_REF_OPERATION, moduleID, deployOptions);
103             }
104
105             for(int i=0; i<targetList.length; i++) {
106                 if(CommandType.DISTRIBUTE.equals(cmd)) {
107                     DeploymentStatus stat =
108                         DeploymentClientUtils.createApplicationReference(
109                             dasConnection.getExistingMBeanServerConnection(),
110                             moduleID, targetList[i], deployOptions);
111                     if(!checkStatusAndAddStage(targetList[i], rollback,
112                                     localStrings.getString("enterprise.deployment.client.create_reference", targetList[i].getName()), dasConnection, stat)) {
113                         return;
114                     }
115                     rollback.addTarget(targetList[i], RollBackAction.APP_REF_CREATED);
116                     
117                     /*
118                       XXX Start the application regardless the value of "enable"
119                       Otherwise no DeployEvent would be sent to the listeners on
120                       a remote instance, which would in turn synchronize the app
121                       bits. Note that the synchronization is only called during
122                       applicationDeployed, not applicationEnabled. To make sure
123                       the deployment code can work with both the new and the old
124                       mbeans, we will call the start for now (as the old mbeans
125                       would do). The backend listeners are already enhanced to
126                       make sure the apps are not actually loaded unless the enable
127                       attributes are true for both the application and
128                       application-ref elements.
129                     */

130                     DeploymentClientUtils.setResourceOptions(
131                         deployOptions,
132                         DeploymentProperties.RES_CREATE_REF,
133                         targetList[i].getName());
134                     stat = DeploymentClientUtils.startApplication(
135                             dasConnection.getExistingMBeanServerConnection(),
136                             moduleID, targetList[i], deployOptions);
137                     
138                     // We dont rollback for start failure because start failure may be because of server being down
139
// We just add DeploymentStatus of this phase to the complete DeploymentStatus
140

141                     checkStatusAndAddStage(targetList[i], null,
142                         localStrings.getString("enterprise.deployment.client.reference_start", targetList[i].getName()), dasConnection, stat, true);
143
144                 } else {
145                     deployOptions.put(DeploymentProperties.DEPLOY_OPTION_FORCE_KEY, "false");
146                     
147                     // We dont rollback for stop failure because the failure may be because of server being down
148
// We just add DeploymentStatus of this phase to the complete DeploymentStatus
149

150                     DeploymentClientUtils.setResourceOptions(
151                         deployOptions,
152                         DeploymentProperties.RES_DELETE_REF,
153                         targetList[i].getName());
154                     DeploymentStatus stat =
155                         DeploymentClientUtils.stopApplication(
156                             dasConnection.getExistingMBeanServerConnection(),
157                             moduleID, targetList[i], deployOptions);
158                     checkStatusAndAddStage(targetList[i], null,
159                                   localStrings.getString("enterprise.deployment.client.reference_stop", targetList[i].getName()), dasConnection, stat);
160                     
161                     stat = DeploymentClientUtils.deleteApplicationReference(
162                             dasConnection.getExistingMBeanServerConnection(),
163                             moduleID, targetList[i], deployOptions);
164                     if(!checkStatusAndAddStage(targetList[i], rollback,
165                        localStrings.getString("enterprise.deployment.client.remove_reference", targetList[i].getName()), dasConnection, stat)) {
166                         return;
167                     }
168                     rollback.addTarget(targetList[i], RollBackAction.APP_REF_DELETED);
169                 }
170                 resultTargetModuleIDs.add(new SunTargetModuleID(moduleID, targetList[i]));
171             }
172             
173             // initialize the instance variable targetModuleIDs using
174
// the successful module ids
175
this.targetModuleIDs = new TargetModuleID JavaDoc[resultTargetModuleIDs.size()];
176             this.targetModuleIDs =
177                 (TargetModuleID JavaDoc[])resultTargetModuleIDs.toArray(this.targetModuleIDs);
178             
179             setupForNormalExit(localStrings.getString("enterprise.deployment.client.change_reference_application", action), targetList[0]);
180         } catch (Throwable JavaDoc ioex) {
181             finalDeploymentStatus.setStageException(ioex);
182             setupForAbnormalExit(localStrings.getString("enterprise.deployment.client.change_reference_application_failed", action, ioex.getMessage()), targetList[0]);
183             return;
184         }
185     }
186 }
187
Popular Tags