001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.geronimo.console.jmsmanager.wizard;
018
019 import java.io.BufferedOutputStream;
020 import java.io.ByteArrayOutputStream;
021 import java.io.File;
022 import java.io.FileOutputStream;
023 import java.io.IOException;
024 import java.util.ArrayList;
025 import java.util.Iterator;
026 import java.util.List;
027 import java.util.Map;
028 import java.util.Properties;
029 import javax.enterprise.deploy.model.DDBean;
030 import javax.enterprise.deploy.model.DDBeanRoot;
031 import javax.enterprise.deploy.spi.DeploymentConfiguration;
032 import javax.enterprise.deploy.spi.DeploymentManager;
033 import javax.enterprise.deploy.spi.Target;
034 import javax.enterprise.deploy.spi.TargetModuleID;
035 import javax.enterprise.deploy.spi.status.ProgressObject;
036 import javax.portlet.ActionResponse;
037 import javax.portlet.PortletRequest;
038 import javax.portlet.PortletSession;
039 import org.apache.commons.logging.Log;
040 import org.apache.commons.logging.LogFactory;
041 import org.apache.geronimo.connector.deployment.jsr88.AdminObjectDCB;
042 import org.apache.geronimo.connector.deployment.jsr88.AdminObjectInstance;
043 import org.apache.geronimo.connector.deployment.jsr88.ConnectionDefinition;
044 import org.apache.geronimo.connector.deployment.jsr88.ConnectionDefinitionInstance;
045 import org.apache.geronimo.connector.deployment.jsr88.Connector15DCBRoot;
046 import org.apache.geronimo.connector.deployment.jsr88.ConnectorDCB;
047 import org.apache.geronimo.connector.deployment.jsr88.ResourceAdapter;
048 import org.apache.geronimo.connector.deployment.jsr88.ResourceAdapterInstance;
049 import org.apache.geronimo.connector.deployment.jsr88.SinglePool;
050 import org.apache.geronimo.console.MultiPageAbstractHandler;
051 import org.apache.geronimo.console.MultiPageModel;
052 import org.apache.geronimo.console.util.PortletManager;
053 import org.apache.geronimo.deployment.service.jsr88.EnvironmentData;
054 import org.apache.geronimo.deployment.tools.loader.ConnectorDeployable;
055 import org.apache.geronimo.kernel.repository.Artifact;
056 import org.apache.geronimo.naming.deployment.jsr88.GBeanLocator;
057
058 /**
059 * Base class for portlet helpers
060 *
061 * @version $Rev: 476061 $ $Date: 2006-11-17 01:36:50 -0500 (Fri, 17 Nov 2006) $
062 */
063 public abstract class AbstractHandler extends MultiPageAbstractHandler {
064 private final static Log log = LogFactory.getLog(AbstractHandler.class);
065 // ********** This part specific to JMS portlets **********
066
067 protected final static String LIST_MODE="list";
068 protected final static String SELECT_PROVIDER_MODE="provider";
069 protected final static String CONFIGURE_RA_MODE="ra";
070 protected final static String ADD_FACTORY_MODE="factory";
071 protected final static String SELECT_FACTORY_TYPE_MODE="factoryType";
072 protected final static String ADD_DESTINATION_MODE="destination";
073 protected final static String SELECT_DESTINATION_TYPE_MODE="destinationType";
074 protected final static String REVIEW_MODE="review";
075 protected final static String SHOW_PLAN_MODE="plan";
076 protected final static String DEPLOY_MODE="deploy";
077
078 protected final static String PROVIDER_PARAMETER="provider";
079 protected final static String RAR_FILE_PARAMETER="rar";
080 protected final static String DEPENDENCY_PARAMETER="dependency";
081 protected final static String INSTANCE_NAME_PARAMETER="instanceName";
082 protected final static String NAME_PARAMETER="name";
083 protected final static String CURRENT_FACTORY_PARAMETER="currentFactoryID";
084 protected final static String CURRENT_DEST_PARAMETER="currentDestinationID";
085 protected final static String FACTORY_TYPE_PARAMETER="factoryType";
086 protected final static String DEST_TYPE_PARAMETER="destinationType";
087 protected final static String TRANSACTION_PARAMETER="transaction";
088 protected final static String XA_TRANSACTION_PARAMETER="xaTransaction";
089 protected final static String XA_THREAD_PARAMETER="xaThread";
090 protected final static String MIN_SIZE_PARAMETER="poolMinSize";
091 protected final static String MAX_SIZE_PARAMETER="poolMaxSize";
092 protected final static String IDLE_TIME_PARAMETER="poolIdleTimeout";
093 protected final static String BLOCK_TIME_PARAMETER="poolBlockingTimeout";
094
095 public AbstractHandler(String mode, String viewName) {
096 super(mode, viewName);
097 }
098
099 public static class JMSResourceData implements MultiPageModel {
100 private String rarURI;
101 private String dependency;
102 private String instanceName;
103 private Properties instanceProps = new Properties();
104 private String workManager;
105 private int currentFactory = -1;
106 private int currentDestination = -1;
107 private int factoryType = -1;
108 private int destinationType = -1;
109 private List connectionFactories = new ArrayList();
110 private List adminObjects = new ArrayList();
111 // Used for editing an existing resource
112 private String objectName;
113
114 public JMSResourceData(PortletRequest request) {
115 Map map = request.getParameterMap();
116 rarURI = request.getParameter(RAR_FILE_PARAMETER);
117 dependency = request.getParameter(DEPENDENCY_PARAMETER);
118 instanceName = request.getParameter(INSTANCE_NAME_PARAMETER);
119 factoryType = isEmpty(request.getParameter(FACTORY_TYPE_PARAMETER)) ? -1 : Integer.parseInt(request.getParameter(FACTORY_TYPE_PARAMETER));
120 currentFactory = isEmpty(request.getParameter(CURRENT_FACTORY_PARAMETER)) ? -1 : Integer.parseInt(request.getParameter(CURRENT_FACTORY_PARAMETER));
121 destinationType = isEmpty(request.getParameter(DEST_TYPE_PARAMETER)) ? -1 : Integer.parseInt(request.getParameter(DEST_TYPE_PARAMETER));
122 currentDestination = isEmpty(request.getParameter(CURRENT_DEST_PARAMETER)) ? -1 : Integer.parseInt(request.getParameter(CURRENT_DEST_PARAMETER));
123 for(int i=0; i<20; i++) {
124 String key = "instance-config-" + i;
125 if(map.containsKey(key)) {
126 instanceProps.setProperty(key, request.getParameter(key));
127 }
128 }
129 workManager = "DefaultWorkManager"; //todo
130 int index = 0;
131 while(true) {
132 String key = "factory."+(index++)+".";
133 if(!map.containsKey(key+FACTORY_TYPE_PARAMETER)) {
134 break;
135 }
136 JMSConnectionFactoryData data = new JMSConnectionFactoryData();
137 data.load(request, key);
138 connectionFactories.add(data);
139 }
140 index = 0;
141 while(true) {
142 String key = "destination."+(index++)+".";
143 if(!map.containsKey(key+DEST_TYPE_PARAMETER)) {
144 break;
145 }
146 JMSAdminObjectData data = new JMSAdminObjectData();
147 data.load(request, key);
148 adminObjects.add(data);
149 }
150 createIfNecessary();
151 }
152
153 public void createIfNecessary() {
154 while(currentFactory >= connectionFactories.size()) {
155 connectionFactories.add(new JMSConnectionFactoryData());
156 }
157 while(currentDestination >= adminObjects.size()) {
158 adminObjects.add(new JMSAdminObjectData());
159 }
160 }
161
162 public void save(ActionResponse response, PortletSession session) {
163 if(!isEmpty(rarURI)) response.setRenderParameter(RAR_FILE_PARAMETER, rarURI);
164 if(!isEmpty(dependency)) response.setRenderParameter(DEPENDENCY_PARAMETER, dependency);
165 if(!isEmpty(instanceName)) response.setRenderParameter(INSTANCE_NAME_PARAMETER, instanceName);
166 for (Iterator it = instanceProps.entrySet().iterator(); it.hasNext();) {
167 Map.Entry entry = (Map.Entry) it.next();
168 if(!isEmpty((String)entry.getValue())) {
169 response.setRenderParameter((String)entry.getKey(), (String)entry.getValue());
170 }
171 }
172 if(!isEmpty(workManager)) response.setRenderParameter("workManager", workManager);
173 response.setRenderParameter(FACTORY_TYPE_PARAMETER, Integer.toString(factoryType));
174 response.setRenderParameter(DEST_TYPE_PARAMETER, Integer.toString(destinationType));
175 response.setRenderParameter(CURRENT_DEST_PARAMETER, Integer.toString(currentDestination));
176 response.setRenderParameter(CURRENT_FACTORY_PARAMETER, Integer.toString(currentFactory));
177 for (int i = 0; i < connectionFactories.size(); i++) {
178 JMSConnectionFactoryData data = (JMSConnectionFactoryData) connectionFactories.get(i);
179 String key = "factory."+i+".";
180 data.save(response, key);
181 }
182 for (int i = 0; i < adminObjects.size(); i++) {
183 JMSAdminObjectData data = (JMSAdminObjectData) adminObjects.get(i);
184 String key = "destination."+i+".";
185 data.save(response, key);
186 }
187 }
188
189 public int getFactoryType() {
190 return factoryType;
191 }
192
193 public void setFactoryType(int factoryType) {
194 this.factoryType = factoryType;
195 }
196
197 public int getDestinationType() {
198 return destinationType;
199 }
200
201 public void setDestinationType(int destinationType) {
202 this.destinationType = destinationType;
203 }
204
205 public int getCurrentFactoryID() {
206 return currentFactory;
207 }
208
209 public void setCurrentFactoryID(int id) {
210 currentFactory = id;
211 }
212
213 public int getCurrentDestinationID() {
214 return currentDestination;
215 }
216
217 public void setCurrentDestinationID(int id) {
218 currentDestination = id;
219 }
220
221 public String getRarURI() {
222 return rarURI;
223 }
224
225 public void setRarURI(String rarURI) {
226 this.rarURI = rarURI;
227 }
228
229 public String getDependency() {
230 return dependency;
231 }
232
233 public void setDependency(String dependency) {
234 this.dependency = dependency;
235 }
236
237 public String getInstanceName() {
238 return instanceName;
239 }
240
241 public void setInstanceName(String instanceName) {
242 this.instanceName = instanceName;
243 }
244
245 public String getWorkManager() {
246 return workManager;
247 }
248
249 public void setWorkManager(String workManager) {
250 this.workManager = workManager;
251 }
252
253 public Properties getInstanceProps() {
254 return instanceProps;
255 }
256
257 public List getConnectionFactories() {
258 return connectionFactories;
259 }
260
261 public List getAdminObjects() {
262 return adminObjects;
263 }
264
265 public JMSConnectionFactoryData getCurrentFactory() {
266 return (JMSConnectionFactoryData) connectionFactories.get(currentFactory);
267 }
268
269 public JMSAdminObjectData getCurrentDestination() {
270 return (JMSAdminObjectData) adminObjects.get(currentDestination);
271 }
272
273 public int getConnectionFactoryCount() {
274 return connectionFactories.size();
275 }
276
277 public int getDestinationCount() {
278 return adminObjects.size();
279 }
280 }
281
282 public static class JMSConnectionFactoryData {
283 private int factoryType;
284 private String instanceName;
285 private String transaction; //none, local, xa
286 private boolean xaTransactionCaching;
287 private boolean xaThreadCaching;
288 private Integer poolMinSize;
289 private Integer poolMaxSize;
290 private Integer poolBlockingTimeout;
291 private Integer poolIdleTimeout;
292 private Properties instanceProps = new Properties();
293
294 public void load(PortletRequest request, String prefix) {
295 factoryType = isEmpty(request.getParameter(prefix+FACTORY_TYPE_PARAMETER)) ? -1 : Integer.parseInt(request.getParameter(prefix+FACTORY_TYPE_PARAMETER));
296 instanceName = request.getParameter(prefix+INSTANCE_NAME_PARAMETER);
297 transaction = request.getParameter(prefix+TRANSACTION_PARAMETER);
298 xaThreadCaching = !isEmpty(request.getParameter(prefix+XA_THREAD_PARAMETER)) && request.getParameter(prefix+XA_THREAD_PARAMETER).equals("true");
299 xaTransactionCaching = isEmpty(request.getParameter(prefix+XA_TRANSACTION_PARAMETER)) || request.getParameter(prefix+XA_TRANSACTION_PARAMETER).equals("true");
300 poolMinSize = isEmpty(request.getParameter(prefix+MIN_SIZE_PARAMETER)) ? null : new Integer(request.getParameter(prefix+MIN_SIZE_PARAMETER));
301 poolMaxSize = isEmpty(request.getParameter(prefix+MAX_SIZE_PARAMETER)) ? null : new Integer(request.getParameter(prefix+MAX_SIZE_PARAMETER));
302 poolIdleTimeout = isEmpty(request.getParameter(prefix+IDLE_TIME_PARAMETER)) ? null : new Integer(request.getParameter(prefix+IDLE_TIME_PARAMETER));
303 poolBlockingTimeout = isEmpty(request.getParameter(prefix+BLOCK_TIME_PARAMETER)) ? null : new Integer(request.getParameter(prefix+BLOCK_TIME_PARAMETER));
304 Map map = request.getParameterMap();
305 for(int i=0; i<20; i++) {
306 String key = prefix+"instance-config-" + i;
307 if(map.containsKey(key)) {
308 instanceProps.setProperty(key.substring(prefix.length()), request.getParameter(key));
309 }
310 }
311 }
312
313 public void save(ActionResponse response, String prefix) {
314 if(factoryType > -1) response.setRenderParameter(prefix+FACTORY_TYPE_PARAMETER, Integer.toString(factoryType));
315 if(!isEmpty(instanceName)) response.setRenderParameter(prefix+INSTANCE_NAME_PARAMETER, instanceName);
316 if(!isEmpty(transaction)) response.setRenderParameter(prefix+TRANSACTION_PARAMETER, transaction);
317 response.setRenderParameter(prefix+XA_THREAD_PARAMETER, Boolean.toString(xaThreadCaching));
318 response.setRenderParameter(prefix+XA_TRANSACTION_PARAMETER, Boolean.toString(xaTransactionCaching));
319 if(poolMinSize != null) response.setRenderParameter(prefix+MIN_SIZE_PARAMETER, poolMinSize.toString());
320 if(poolMaxSize != null) response.setRenderParameter(prefix+MAX_SIZE_PARAMETER, poolMaxSize.toString());
321 if(poolBlockingTimeout != null) response.setRenderParameter(prefix+BLOCK_TIME_PARAMETER, poolBlockingTimeout.toString());
322 if(poolIdleTimeout != null) response.setRenderParameter(prefix+IDLE_TIME_PARAMETER, poolIdleTimeout.toString());
323 for (Iterator it = instanceProps.entrySet().iterator(); it.hasNext();) {
324 Map.Entry entry = (Map.Entry) it.next();
325 if(!isEmpty((String)entry.getValue())) {
326 response.setRenderParameter(prefix+entry.getKey(), (String)entry.getValue());
327 }
328 }
329 }
330
331 public int getFactoryType() {
332 return factoryType;
333 }
334
335 public void setFactoryType(int factoryType) {
336 this.factoryType = factoryType;
337 }
338
339 public String getInstanceName() {
340 return instanceName;
341 }
342
343 public void setInstanceName(String instanceName) {
344 this.instanceName = instanceName;
345 }
346
347 public String getTransaction() {
348 return transaction;
349 }
350
351 public void setTransaction(String transaction) {
352 this.transaction = transaction;
353 }
354
355 public boolean isXaTransactionCaching() {
356 return xaTransactionCaching;
357 }
358
359 public void setXaTransactionCaching(boolean xaTransactionCaching) {
360 this.xaTransactionCaching = xaTransactionCaching;
361 }
362
363 public boolean isXaThreadCaching() {
364 return xaThreadCaching;
365 }
366
367 public void setXaThreadCaching(boolean xaThreadCaching) {
368 this.xaThreadCaching = xaThreadCaching;
369 }
370
371 public Integer getPoolMinSize() {
372 return poolMinSize;
373 }
374
375 public void setPoolMinSize(Integer poolMinSize) {
376 this.poolMinSize = poolMinSize;
377 }
378
379 public Integer getPoolMaxSize() {
380 return poolMaxSize;
381 }
382
383 public void setPoolMaxSize(Integer poolMaxSize) {
384 this.poolMaxSize = poolMaxSize;
385 }
386
387 public Integer getPoolBlockingTimeout() {
388 return poolBlockingTimeout;
389 }
390
391 public void setPoolBlockingTimeout(Integer poolBlockingTimeout) {
392 this.poolBlockingTimeout = poolBlockingTimeout;
393 }
394
395 public Integer getPoolIdleTimeout() {
396 return poolIdleTimeout;
397 }
398
399 public void setPoolIdleTimeout(Integer poolIdleTimeout) {
400 this.poolIdleTimeout = poolIdleTimeout;
401 }
402
403 public Properties getInstanceProps() {
404 return instanceProps;
405 }
406 }
407
408 public static class JMSAdminObjectData {
409 private int destinationType;
410 private String name;
411 private Properties instanceProps = new Properties();
412
413 public void load(PortletRequest request, String prefix) {
414 destinationType = isEmpty(request.getParameter(prefix+DEST_TYPE_PARAMETER)) ? -1 : Integer.parseInt(request.getParameter(prefix+DEST_TYPE_PARAMETER));
415 name = request.getParameter(prefix+NAME_PARAMETER);
416 Map map = request.getParameterMap();
417 for(int i=0; i<20; i++) {
418 String key = prefix+"instance-config-" + i;
419 if(map.containsKey(key)) {
420 instanceProps.setProperty(key.substring(prefix.length()), request.getParameter(key));
421 }
422 }
423 }
424
425 public void save(ActionResponse response, String prefix) {
426 if(destinationType > -1) response.setRenderParameter(prefix+DEST_TYPE_PARAMETER, Integer.toString(destinationType));
427 if(!isEmpty(name)) response.setRenderParameter(prefix+NAME_PARAMETER, name);
428 for (Iterator it = instanceProps.entrySet().iterator(); it.hasNext();) {
429 Map.Entry entry = (Map.Entry) it.next();
430 if(!isEmpty((String)entry.getValue())) {
431 response.setRenderParameter(prefix+entry.getKey(), (String)entry.getValue());
432 }
433 }
434 }
435
436 public int getDestinationType() {
437 return destinationType;
438 }
439
440 public void setDestinationType(int destinationType) {
441 this.destinationType = destinationType;
442 }
443
444 public String getName() {
445 return name;
446 }
447
448 public void setName(String name) {
449 this.name = name;
450 }
451
452 public Properties getInstanceProps() {
453 return instanceProps;
454 }
455 }
456
457 private static String getPropertyName(String propertyKey, JMSProviderData.ConfigPropertyData[] configs) {
458 int pos = propertyKey.lastIndexOf('-');
459 String num = propertyKey.substring(pos+1);
460 return configs[Integer.parseInt(num)].getName();
461 }
462
463 protected static String save(PortletRequest request, ActionResponse response, JMSResourceData data, boolean planOnly) throws IOException {
464 JMSProviderData provider = JMSProviderData.getProviderData(data.rarURI, request);
465 if(data.objectName == null || data.objectName.equals("")) { // we're creating a new pool
466 //data.instanceName = data.instanceName.replaceAll("\\s", "");
467 DeploymentManager mgr = PortletManager.getDeploymentManager(request);
468 try {
469 File rarFile = PortletManager.getRepositoryEntry(request, data.getRarURI());
470 ConnectorDeployable deployable = new ConnectorDeployable(rarFile.toURL());
471 DeploymentConfiguration config = mgr.createConfiguration(deployable);
472 final DDBeanRoot ddBeanRoot = deployable.getDDBeanRoot();
473 Connector15DCBRoot root = (Connector15DCBRoot) config.getDConfigBeanRoot(ddBeanRoot);
474 ConnectorDCB connector = (ConnectorDCB) root.getDConfigBean(ddBeanRoot.getChildBean(root.getXpaths()[0])[0]);
475
476 EnvironmentData environment = new EnvironmentData();
477 connector.setEnvironment(environment);
478 org.apache.geronimo.deployment.service.jsr88.Artifact configId = new org.apache.geronimo.deployment.service.jsr88.Artifact();
479 environment.setConfigId(configId);
480 configId.setGroupId("console.jms");
481 configId.setArtifactId(data.instanceName);
482 configId.setVersion("1.0");
483 configId.setType("rar");
484 if(data.dependency != null && !data.dependency.trim().equals("")) {
485 Artifact artifact = Artifact.create(data.dependency.trim());
486 org.apache.geronimo.deployment.service.jsr88.Artifact dep = new org.apache.geronimo.deployment.service.jsr88.Artifact();
487 environment.setDependencies(new org.apache.geronimo.deployment.service.jsr88.Artifact[]{dep});
488 dep.setArtifactId(artifact.getArtifactId());
489 if(artifact.getGroupId() != null) {
490 dep.setGroupId(artifact.getGroupId());
491 }
492 if(artifact.getGroupId() != null) {
493 dep.setType(artifact.getType());
494 }
495 if(artifact.getVersion() != null) {
496 dep.setVersion(artifact.getVersion().toString());
497 }
498 }
499
500 // Basic settings on RA plan and RA instance
501 ResourceAdapter ra;
502 if(connector.getResourceAdapter().length > 0) {
503 ra = connector.getResourceAdapter(0);
504 } else {
505 ra = new ResourceAdapter();
506 connector.setResourceAdapter(new ResourceAdapter[]{ra});
507 }
508 ResourceAdapterInstance raInstance = new ResourceAdapterInstance();
509 ra.setResourceAdapterInstance(raInstance);
510 raInstance.setResourceAdapterName(data.instanceName);
511 for (Iterator it = data.instanceProps.entrySet().iterator(); it.hasNext();) {
512 Map.Entry entry = (Map.Entry) it.next();
513 String name = getPropertyName((String)entry.getKey(), provider.getInstanceConfigProperties());
514 for(int i=0; i<raInstance.getConfigPropertySetting().length; i++) {
515 if(raInstance.getConfigPropertySetting(i).getName().equals(name)) {
516 raInstance.getConfigPropertySetting(i).setValue((String)entry.getValue());
517 break;
518 }
519 }
520 }
521 GBeanLocator workManager = new GBeanLocator();
522 raInstance.setWorkManager(workManager);
523 workManager.setGBeanLink(data.workManager); //todo
524 // Connection Factories
525 if(data.getConnectionFactoryCount() > 0) {
526 ConnectionDefinition[] defs = new ConnectionDefinition[data.getConnectionFactoryCount()];
527 for (int i = 0; i < defs.length; i++) {
528 defs[i] = new ConnectionDefinition();
529 }
530 ra.setConnectionDefinition(defs);
531 for (int i = 0; i < data.getConnectionFactories().size(); i++) {
532 JMSConnectionFactoryData factoryData = (JMSConnectionFactoryData) data.getConnectionFactories().get(i);
533 JMSProviderData.ConnectionDefinition providerData = provider.getConnectionDefinitions()[factoryData.getFactoryType()];
534 ConnectionDefinition def = defs[i];
535 def.setConnectionFactoryInterface(providerData.getConnectionFactoryInterface());
536 ConnectionDefinitionInstance instance = new ConnectionDefinitionInstance();
537 def.setConnectionInstance(new ConnectionDefinitionInstance[]{instance});
538 if(providerData.getConnectionFactoryInterface().equals("javax.jms.ConnectionFactory")) {
539 instance.setImplementedInterface(new String[]{"javax.jms.QueueConnectionFactory","javax.jms.TopicConnectionFactory"});
540 }
541 instance.setName(factoryData.getInstanceName());
542 SinglePool pool = new SinglePool();
543 instance.getConnectionManager().setPoolSingle(pool);
544 pool.setMatchOne(true);
545 pool.setMaxSize(factoryData.getPoolMaxSize());
546 pool.setMinSize(factoryData.getPoolMinSize());
547 pool.setBlockingTimeoutMillis(factoryData.getPoolBlockingTimeout());
548 pool.setIdleTimeoutMinutes(factoryData.getPoolIdleTimeout());
549 if(factoryData.getTransaction().equals("none")) {
550 instance.getConnectionManager().setTransactionNone(true);
551 } else if(factoryData.getTransaction().equals("local")) {
552 instance.getConnectionManager().setTransactionLocal(true);
553 } else if(factoryData.getTransaction().equals("xa")) {
554 instance.getConnectionManager().setTransactionXA(true);
555 instance.getConnectionManager().setTransactionXACachingThread(factoryData.isXaThreadCaching());
556 instance.getConnectionManager().setTransactionXACachingTransaction(factoryData.isXaTransactionCaching());
557 }
558 for (Iterator it = factoryData.instanceProps.entrySet().iterator(); it.hasNext();) {
559 Map.Entry entry = (Map.Entry) it.next();
560 String name = getPropertyName((String)entry.getKey(), providerData.getConfigProperties());
561 for(int j=0; j<instance.getConfigPropertySetting().length; j++) {
562 if(instance.getConfigPropertySetting(j).getName().equals(name)) {
563 instance.getConfigPropertySetting(j).setValue((String)entry.getValue());
564 break;
565 }
566 }
567 }
568 }
569 }
570
571 // Destinations
572 DDBean[] ddBeans = connector.getDDBean().getChildBean(connector.getXpaths()[0]);
573 AdminObjectDCB[] adminDCBs = new AdminObjectDCB[ddBeans.length];
574 for (int i = 0; i < adminDCBs.length; i++) {
575 adminDCBs[i] = (AdminObjectDCB) connector.getDConfigBean(ddBeans[i]);
576 }
577 for (int i = 0; i < data.getAdminObjects().size(); i++) {
578 JMSAdminObjectData admin = (JMSAdminObjectData) data.getAdminObjects().get(i);
579 JMSProviderData.AdminObjectDefinition providerData = provider.getAdminObjectDefinitions()[admin.getDestinationType()];
580 for (int j = 0; j < adminDCBs.length; j++) {
581 AdminObjectDCB adminDCB = adminDCBs[j];
582 if(adminDCB.getAdminObjectInterface().equals(providerData.getAdminObjectInterface())) {
583 AdminObjectInstance[] before = adminDCB.getAdminObjectInstance();
584 AdminObjectInstance[] after = new AdminObjectInstance[before.length+1];
585 System.arraycopy(before, 0, after, 0, before.length);
586 AdminObjectInstance instance = new AdminObjectInstance();
587 after[before.length] = instance;
588 adminDCB.setAdminObjectInstance(after);
589 instance.setMessageDestinationName(admin.getName());
590 for (Iterator it = admin.instanceProps.entrySet().iterator(); it.hasNext();) {
591 Map.Entry entry = (Map.Entry) it.next();
592 String name = getPropertyName((String)entry.getKey(), providerData.getConfigProperties());
593 for(int k=0; k<instance.getConfigPropertySetting().length; k++) {
594 if(instance.getConfigPropertySetting(k).getName().equals(name)) {
595 instance.getConfigPropertySetting(k).setValue((String)entry.getValue());
596 break;
597 }
598 }
599 }
600 break;
601 }
602 }
603 }
604
605 // Save
606 if(planOnly) {
607 ByteArrayOutputStream out = new ByteArrayOutputStream();
608 config.save(out);
609 out.close();
610 return new String(out.toByteArray(), "US-ASCII");
611 } else {
612 File tempFile = File.createTempFile("console-deployment",".xml");
613 tempFile.deleteOnExit();
614 log.debug("Writing JMS Resource deployment plan to "+tempFile.getAbsolutePath());
615 BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tempFile));
616 config.save(out);
617 out.flush();
618 out.close();
619 Target[] targets = mgr.getTargets();
620 ProgressObject po = mgr.distribute(targets, rarFile, tempFile);
621 waitForProgress(po);
622 if(po.getDeploymentStatus().isCompleted()) {
623 TargetModuleID[] ids = po.getResultTargetModuleIDs();
624 po = mgr.start(ids);
625 waitForProgress(po);
626 if(po.getDeploymentStatus().isCompleted()) {
627 ids = po.getResultTargetModuleIDs();
628 log.info("Deployment completed successfully!");
629 }
630 }
631 }
632 } catch (Exception e) {
633 log.error("Unable to save connection pool", e);
634 } finally {
635 if(mgr != null) mgr.release();
636 }
637 } else { // We're saving updates to an existing pool
638 if(planOnly) {
639 throw new UnsupportedOperationException("Can't update a plan for an existing deployment");
640 }
641 throw new UnsupportedOperationException("Can't edit existing configurations yet");
642 }
643 return null;
644 }
645 }
646