1 | |
package com.aurea.maven.plugins.sonic.utils; |
2 | |
|
3 | |
import java.io.File; |
4 | |
import java.util.Iterator; |
5 | |
import java.util.List; |
6 | |
|
7 | |
import com.sonicsw.ma.mgmtapi.config.MgmtException; |
8 | |
import com.sonicsw.mf.mgmtapi.config.IContainerBean; |
9 | |
import com.sonicsw.mq.mgmtapi.config.IAcceptorTcpsBean; |
10 | |
import com.sonicsw.mq.mgmtapi.config.IAcceptorsBean; |
11 | |
import com.sonicsw.mq.mgmtapi.config.IBrokerBean; |
12 | |
import com.sonicsw.mq.mgmtapi.config.MQMgmtBeanFactory; |
13 | |
import com.sonicsw.mx.config.ConfigServiceException; |
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | 0 | public class OffLineDSConfigurator { |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
public static void main(final String[] _args) { |
26 | |
|
27 | |
|
28 | 0 | OffLineDSConfigurator oldsc = new OffLineDSConfigurator(); |
29 | 0 | oldsc.go(); |
30 | 0 | } |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public final void moveDomain(final String _from, final String _to) { |
39 | |
|
40 | 0 | File moveFile = null; |
41 | 0 | File destDir = new File(_to); |
42 | 0 | boolean dsSuccess = false; |
43 | |
|
44 | 0 | System.out.println("Moving DS"); |
45 | 0 | moveFile = new File(_from + File.separatorChar + "ds.xml"); |
46 | 0 | System.out.println("File to move = " + moveFile.getAbsolutePath()); |
47 | 0 | dsSuccess = moveFile.renameTo(new File(destDir, moveFile.getName())); |
48 | 0 | if (dsSuccess) { |
49 | 0 | System.out.println("Move of ds.xml completed"); |
50 | |
} |
51 | |
|
52 | |
|
53 | 0 | System.out.println("Moving Store"); |
54 | 0 | moveFile = new File(_from + File.separatorChar + "SonicMQStore"); |
55 | 0 | dsSuccess = moveFile.renameTo(new File(destDir, moveFile.getName())); |
56 | 0 | if (dsSuccess) { |
57 | 0 | System.out.println("Move of SonicMQStore completed"); |
58 | |
} |
59 | |
|
60 | |
|
61 | 0 | System.out.println("Moving Domain1"); |
62 | 0 | moveFile = new File(_from + File.separatorChar + "Domain1"); |
63 | 0 | dsSuccess = moveFile.renameTo(new File(destDir, moveFile.getName())); |
64 | 0 | if (dsSuccess) { |
65 | 0 | System.out.println("Move of Domain1 completed"); |
66 | |
} |
67 | |
|
68 | 0 | System.out.println("Moving log"); |
69 | 0 | moveFile = new File(_from + File.separatorChar + "log"); |
70 | 0 | dsSuccess = moveFile.renameTo(new File(destDir, moveFile.getName())); |
71 | 0 | if (dsSuccess) { |
72 | 0 | System.out.println("Move of log completed"); |
73 | |
} |
74 | 0 | } |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
@SuppressWarnings("unchecked") |
80 | |
public final void go() { |
81 | |
|
82 | 0 | System.out.println("Current Directory: " + System.getProperty("user.dir")); |
83 | 0 | MQMgmtBeanFactory domain = new MQMgmtBeanFactory(); |
84 | |
|
85 | |
try { |
86 | |
|
87 | |
|
88 | 0 | System.out.println("Connecting to the Domain"); |
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | 0 | domain.connect("Domain1", "localhost:3606", "Administrator", "Administrator"); |
96 | 0 | System.out.println("Domain name = " + domain.getDomain()); |
97 | 0 | List list = domain.getFolderNames("/"); |
98 | 0 | System.out.println("number of elements: " + list.size()); |
99 | 0 | Iterator it = list.iterator(); |
100 | 0 | System.out.println("Getting Names - Start"); |
101 | 0 | while (it.hasNext()) { |
102 | 0 | System.out.println("Names: " + it.next().toString()); |
103 | |
} |
104 | 0 | System.out.println("Getting Names - End"); |
105 | |
|
106 | 0 | list = domain.getBrokerBeanNames(); |
107 | 0 | System.out.println("number of elements: " + list.size()); |
108 | 0 | it = list.iterator(); |
109 | 0 | System.out.println("Getting BrokerNames - Start"); |
110 | 0 | while (it.hasNext()) { |
111 | 0 | System.out.println("Broker Names: " + it.next().toString()); |
112 | |
} |
113 | 0 | System.out.println("Getting Broker Names - End"); |
114 | 0 | System.out.println("Getting the Broker Bean for the Management Broker"); |
115 | 0 | IBrokerBean broker = domain.getBrokerBean("/Brokers/brManagement"); |
116 | 0 | System.out.println("Got the bean for: " + broker.getBrokerName()); |
117 | |
|
118 | 0 | System.out.println("Getting the Acceptor Bean"); |
119 | 0 | IAcceptorsBean.IAcceptorMapType acceptor = broker.getAcceptorsBean().getAcceptors(); |
120 | 0 | List names = acceptor.getKeyNames(); |
121 | 0 | Iterator accit = names.iterator(); |
122 | 0 | while (accit.hasNext()) { |
123 | 0 | String name = (String) accit.next(); |
124 | 0 | System.out.println("ACCLIST Attributes: " + name); |
125 | 0 | if (name.startsWith("TCP_ACCEPTOR")) { |
126 | 0 | IAcceptorTcpsBean acc = (IAcceptorTcpsBean) acceptor.getItem(name); |
127 | 0 | acc.setAcceptorUrl("tcp://localhost:3506"); |
128 | |
} |
129 | 0 | } |
130 | 0 | System.out.println("Acceptor port changed"); |
131 | 0 | System.out.println("Changing ConnectionURLs for the container"); |
132 | |
|
133 | 0 | List containers = domain.getContainerBeanNames(); |
134 | 0 | Iterator cont = containers.iterator(); |
135 | 0 | while (cont.hasNext()) { |
136 | 0 | String name = (String) cont.next(); |
137 | 0 | System.out.println("Container name: " + name); |
138 | 0 | if (name.toUpperCase().endsWith("CTMANAGEMENT")) { |
139 | 0 | IContainerBean container = domain.getContainerBean(name); |
140 | 0 | IContainerBean.IConnectionType connection = container.getConnection(); |
141 | 0 | connection.setConnectionURLs("tcp://localhost:3506"); |
142 | 0 | domain.saveContainerBean(container); |
143 | |
} |
144 | 0 | } |
145 | |
|
146 | |
|
147 | 0 | System.out.println("Disconnecting from the Domain"); |
148 | |
|
149 | 0 | domain.commit(); |
150 | 0 | domain.flush(); |
151 | 0 | domain.disconnect(); |
152 | 0 | domain = null; |
153 | 0 | System.gc(); |
154 | |
try { |
155 | 0 | Thread.sleep(1000); |
156 | 0 | } catch (InterruptedException e) { |
157 | |
|
158 | 0 | e.printStackTrace(); |
159 | 0 | } |
160 | 0 | } catch (MgmtException e) { |
161 | |
|
162 | 0 | e.printStackTrace(); |
163 | 0 | } catch (ConfigServiceException e) { |
164 | |
|
165 | 0 | e.printStackTrace(); |
166 | 0 | } finally { |
167 | |
|
168 | |
|
169 | 0 | } |
170 | 0 | } |
171 | |
} |