Skip to content

Commit 3e28747

Browse files
committed
Merge remote-tracking branch 'sbp/refactor/citrix_resource_base-REBASE'
This closes apache#137 Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2 parents c6416cb + 57d0931 commit 3e28747

93 files changed

Lines changed: 12267 additions & 7697 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/src/com/cloud/agent/api/Answer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ protected Answer() {
2626
this(null);
2727
}
2828

29-
public Answer(Command command) {
29+
public Answer(final Command command) {
3030
this(command, true, null);
3131
}
3232

33-
public Answer(Command command, boolean success, String details) {
33+
public Answer(final Command command, final boolean success, final String details) {
3434
result = success;
3535
this.details = details;
3636
}
3737

38-
public Answer(Command command, Exception e) {
38+
public Answer(final Command command, final Exception e) {
3939
this(command, false, ExceptionUtil.toString(e));
4040
}
4141

@@ -52,11 +52,11 @@ public boolean executeInSequence() {
5252
return false;
5353
}
5454

55-
public static UnsupportedAnswer createUnsupportedCommandAnswer(Command cmd) {
56-
return new UnsupportedAnswer(cmd, "Unsupported command issued:" + cmd.toString() + ". Are you sure you got the right type of server?");
55+
public static UnsupportedAnswer createUnsupportedCommandAnswer(final Command cmd) {
56+
return new UnsupportedAnswer(cmd, "Unsupported command issued: " + cmd.toString() + ". Are you sure you got the right type of server?");
5757
}
5858

59-
public static UnsupportedAnswer createUnsupportedVersionAnswer(Command cmd) {
59+
public static UnsupportedAnswer createUnsupportedVersionAnswer(final Command cmd) {
6060
return new UnsupportedAnswer(cmd, "Unsuppored Version.");
6161
}
62-
}
62+
}

core/src/com/cloud/agent/api/storage/AbstractDownloadCommand.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public abstract class AbstractDownloadCommand extends SsCommand {
3131
protected AbstractDownloadCommand() {
3232
}
3333

34-
protected AbstractDownloadCommand(String name, String url, ImageFormat format, Long accountId) {
35-
assert (url != null);
34+
protected AbstractDownloadCommand(final String name, String url, final ImageFormat format, final Long accountId) {
35+
assert url != null;
3636
url = url.replace('\\', '/');
3737

3838
this.url = url;
@@ -41,14 +41,14 @@ protected AbstractDownloadCommand(String name, String url, ImageFormat format, L
4141
this.name = name;
4242
}
4343

44-
protected AbstractDownloadCommand(AbstractDownloadCommand that) {
44+
protected AbstractDownloadCommand(final AbstractDownloadCommand that) {
4545
super(that);
46-
assert (that.url != null);
46+
assert that.url != null;
4747

48-
this.url = that.url.replace('\\', '/');
49-
this.format = that.format;
50-
this.accountId = that.accountId;
51-
this.name = that.name;
48+
url = that.url.replace('\\', '/');
49+
format = that.format;
50+
accountId = that.accountId;
51+
name = that.name;
5252
}
5353

5454
public String getUrl() {
@@ -73,7 +73,7 @@ public boolean executeInSequence() {
7373
}
7474

7575
public void setUrl(String url) {
76-
assert (url != null);
76+
assert url != null;
7777
url = url.replace('\\', '/');
7878
this.url = url;
7979
}

core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadCommand.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,13 @@ public class PrimaryStorageDownloadCommand extends AbstractDownloadCommand {
3737
String primaryStorageUrl;
3838

3939
protected PrimaryStorageDownloadCommand() {
40-
41-
}
42-
43-
public PrimaryStorageDownloadCommand(String url, StoragePool pool, int wait) {
44-
super(null, url, null, null);
45-
this.poolId = pool.getId();
46-
this.poolUuid = pool.getUuid();
47-
this.primaryPool = new StorageFilerTO(pool);
48-
setWait(wait);
4940
}
5041

51-
public PrimaryStorageDownloadCommand(String name, String url, ImageFormat format, long accountId, StoragePool pool, int wait) {
42+
public PrimaryStorageDownloadCommand(final String name, final String url, final ImageFormat format, final long accountId, final StoragePool pool, final int wait) {
5243
super(name, url, format, accountId);
53-
this.poolId = pool.getId();
54-
this.poolUuid = pool.getUuid();
55-
this.primaryPool = new StorageFilerTO(pool);
44+
poolId = pool.getId();
45+
poolUuid = pool.getUuid();
46+
primaryPool = new StorageFilerTO(pool);
5647
setWait(wait);
5748
}
5849

@@ -68,23 +59,23 @@ public StorageFilerTO getPool() {
6859
return primaryPool;
6960
}
7061

71-
public void setLocalPath(String path) {
72-
this.localPath = path;
62+
public void setLocalPath(final String path) {
63+
localPath = path;
7364
}
7465

7566
public String getLocalPath() {
7667
return localPath;
7768
}
7869

79-
public void setSecondaryStorageUrl(String url) {
70+
public void setSecondaryStorageUrl(final String url) {
8071
secondaryStorageUrl = url;
8172
}
8273

8374
public String getSecondaryStorageUrl() {
8475
return secondaryStorageUrl;
8576
}
8677

87-
public void setPrimaryStorageUrl(String url) {
78+
public void setPrimaryStorageUrl(final String url) {
8879
primaryStorageUrl = url;
8980
}
9081

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.resource;
21+
22+
import java.io.BufferedReader;
23+
import java.io.IOException;
24+
import java.io.InputStream;
25+
import java.io.InputStreamReader;
26+
import java.net.URL;
27+
import java.net.URLConnection;
28+
29+
import org.apache.log4j.Logger;
30+
31+
import com.cloud.agent.api.Answer;
32+
import com.cloud.agent.api.Command;
33+
import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;
34+
35+
36+
public abstract class CommandWrapper<T extends Command, A extends Answer, R extends ServerResource> {
37+
38+
private static final Logger s_logger = Logger.getLogger(CommandWrapper.class);
39+
40+
/**
41+
* @param T is the command to be used.
42+
* @param R is the resource base to be used.
43+
* @return A and the Answer from the command.
44+
*/
45+
public abstract A execute(T command, R serverResource);
46+
47+
/**
48+
* Common method so we added it here.
49+
*
50+
* @param cmd
51+
* @param proxyVmId
52+
* @param proxyVmName
53+
* @param proxyManagementIp
54+
* @param cmdPort
55+
* @return
56+
*/
57+
protected Answer executeProxyLoadScan(final Command cmd, final long proxyVmId, final String proxyVmName, final String proxyManagementIp, final int cmdPort) {
58+
String result = null;
59+
60+
final StringBuffer sb = new StringBuffer();
61+
sb.append("http://").append(proxyManagementIp).append(":" + cmdPort).append("/cmd/getstatus");
62+
63+
boolean success = true;
64+
try {
65+
final URL url = new URL(sb.toString());
66+
final URLConnection conn = url.openConnection();
67+
68+
// setting TIMEOUTs to avoid possible waiting until death situations
69+
conn.setConnectTimeout(5000);
70+
conn.setReadTimeout(5000);
71+
72+
final InputStream is = conn.getInputStream();
73+
final BufferedReader reader = new BufferedReader(new InputStreamReader(is));
74+
final StringBuilder sb2 = new StringBuilder();
75+
String line = null;
76+
try {
77+
while ((line = reader.readLine()) != null) {
78+
sb2.append(line + "\n");
79+
}
80+
result = sb2.toString();
81+
} catch (final IOException e) {
82+
success = false;
83+
} finally {
84+
try {
85+
is.close();
86+
} catch (final IOException e) {
87+
s_logger.warn("Exception when closing , console proxy address : " + proxyManagementIp);
88+
success = false;
89+
}
90+
}
91+
} catch (final IOException e) {
92+
s_logger.warn("Unable to open console proxy command port url, console proxy address : " + proxyManagementIp);
93+
success = false;
94+
}
95+
96+
return new ConsoleProxyLoadAnswer(cmd, proxyVmId, proxyVmName, success, result);
97+
}
98+
}

plugins/hypervisors/xenserver/test/com/cloud/ha/XenServerFencerTest.java renamed to core/src/com/cloud/resource/RequestWrapper.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//
12
// Licensed to the Apache Software Foundation (ASF) under one
23
// or more contributor license agreements. See the NOTICE file
34
// distributed with this work for additional information
@@ -14,26 +15,18 @@
1415
// KIND, either express or implied. See the License for the
1516
// specific language governing permissions and limitations
1617
// under the License.
18+
//
1719

18-
package com.cloud.ha;
19-
20-
import static org.junit.Assert.assertEquals;
21-
22-
import org.junit.Test;
23-
24-
25-
public class XenServerFencerTest {
26-
27-
@Test
28-
public void testSetAndGetName() throws Exception {
29-
XenServerFencer xenServerFencer = new XenServerFencer();
30-
String name = "name";
31-
32-
xenServerFencer.setName(name);
33-
String actual = xenServerFencer.getName();
20+
package com.cloud.resource;
3421

35-
assertEquals(name, actual);
22+
import com.cloud.agent.api.Answer;
23+
import com.cloud.agent.api.Command;
3624

37-
}
25+
public abstract class RequestWrapper {
3826

39-
}
27+
/**
28+
* @param command to be executed.
29+
* @return an Answer for the executed command.
30+
*/
31+
public abstract Answer execute(Command command, ServerResource serverResource);
32+
}

core/test/org/apache/cloudstack/api/agent/test/AnswerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ public class AnswerTest {
3434

3535
@Test
3636
public void testExecuteInSequence() {
37-
boolean b = a.executeInSequence();
37+
final boolean b = a.executeInSequence();
3838
assertFalse(b);
3939
}
4040

4141
@Test
4242
public void testGetResult() {
43-
boolean b = a.getResult();
43+
final boolean b = a.getResult();
4444
assertTrue(b);
4545
}
4646

4747
@Test
4848
public void testGetDetails() {
49-
String d = a.getDetails();
49+
final String d = a.getDetails();
5050
assertTrue(d.equals("details"));
5151
}
5252

@@ -60,7 +60,7 @@ public void testCreateUnsupportedCommandAnswer() {
6060
assertFalse(b);
6161

6262
String d = usa.getDetails();
63-
assertTrue(d.equals("Unsupported command issued:" + acc.toString() + ". Are you sure you got the right type of server?"));
63+
assertTrue(d.contains("Unsupported command issued: " + acc.toString() + ". Are you sure you got the right type of server?"));
6464

6565
usa = Answer.createUnsupportedVersionAnswer(acc);
6666
b = usa.executeInSequence();

plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixHelper.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,22 @@
1616
// under the License.
1717
package com.cloud.hypervisor.xenserver.resource;
1818

19-
import java.util.ArrayList;
2019
import java.util.HashMap;
2120

22-
import org.apache.log4j.Logger;
23-
2421
import com.xensource.xenapi.Host;
2522

2623
/**
2724
* Reduce bloat inside CitrixResourceBase
2825
*
2926
*/
3027
public class CitrixHelper {
31-
private static final Logger s_logger = Logger.getLogger(CitrixHelper.class);
32-
33-
3428
private static final HashMap<String, MemoryValues> XenServerGuestOsMemoryMap = new HashMap<String, MemoryValues>(70);
35-
private static final ArrayList<String> GuestOsList = new ArrayList<String>(70);
36-
3729

3830
public static class MemoryValues {
3931
long max;
4032
long min;
4133

42-
public MemoryValues(long min, long max) {
34+
public MemoryValues(final long min, final long max) {
4335
this.min = min * 1024 * 1024;
4436
this.max = max * 1024 * 1024;
4537
}
@@ -53,8 +45,6 @@ public long getMin() {
5345
}
5446
}
5547

56-
57-
5848
static {
5949
XenServerGuestOsMemoryMap.put("CentOS 4.5 (32-bit)", new MemoryValues(256l, 16 * 1024l));
6050
XenServerGuestOsMemoryMap.put("CentOS 4.6 (32-bit)", new MemoryValues(256l, 16 * 1024l));
@@ -207,37 +197,37 @@ public long getMin() {
207197
XenServerGuestOsMemoryMap.put("Windows XP SP3 (32-bit)", new MemoryValues(256l, 4 * 1024l));
208198
XenServerGuestOsMemoryMap.put("Ubuntu 10.04 (32-bit)", new MemoryValues(128l, 512l));
209199
XenServerGuestOsMemoryMap.put("Ubuntu 10.04 (64-bit)", new MemoryValues(128l, 32 * 1024l));
210-
XenServerGuestOsMemoryMap.put("Ubuntu 10.10 (32-bit)", new MemoryValues(512l, 16*1024l));
211-
XenServerGuestOsMemoryMap.put("Ubuntu 10.10 (64-bit)", new MemoryValues(512l, 16*1024l));
200+
XenServerGuestOsMemoryMap.put("Ubuntu 10.10 (32-bit)", new MemoryValues(512l, 16 * 1024l));
201+
XenServerGuestOsMemoryMap.put("Ubuntu 10.10 (64-bit)", new MemoryValues(512l, 16 * 1024l));
212202
XenServerGuestOsMemoryMap.put("Ubuntu 12.04 (32-bit)", new MemoryValues(512l, 32 * 1024l));
213203
XenServerGuestOsMemoryMap.put("Ubuntu 12.04 (64-bit)", new MemoryValues(512l, 128 * 1024l));
214204
XenServerGuestOsMemoryMap.put("Ubuntu 14.04 (32-bit)", new MemoryValues(512l, 32 * 1024l));
215205
XenServerGuestOsMemoryMap.put("Ubuntu 14.04 (64-bit)", new MemoryValues(512l, 128 * 1024l));
216206
}
217207

218-
public static long getXenServerStaticMax(String stdType, boolean bootFromCD) {
219-
MemoryValues recommendedMaxMinMemory = XenServerGuestOsMemoryMap.get(stdType);
208+
public static long getXenServerStaticMax(final String stdType, final boolean bootFromCD) {
209+
final MemoryValues recommendedMaxMinMemory = XenServerGuestOsMemoryMap.get(stdType);
220210
if (recommendedMaxMinMemory == null) {
221211
return 0l;
222212
}
223213
return recommendedMaxMinMemory.getMax();
224214
}
225215

226-
public static long getXenServerStaticMin(String stdType, boolean bootFromCD) {
227-
MemoryValues recommendedMaxMinMemory = XenServerGuestOsMemoryMap.get(stdType);
216+
public static long getXenServerStaticMin(final String stdType, final boolean bootFromCD) {
217+
final MemoryValues recommendedMaxMinMemory = XenServerGuestOsMemoryMap.get(stdType);
228218
if (recommendedMaxMinMemory == null) {
229219
return 0l;
230220
}
231221
return recommendedMaxMinMemory.getMin();
232222
}
233223

234-
public static String getProductVersion(Host.Record record) {
224+
public static String getProductVersion(final Host.Record record) {
235225
String prodVersion = record.softwareVersion.get("product_version");
236226
if (prodVersion == null) {
237227
prodVersion = record.softwareVersion.get("platform_version").trim();
238228
} else {
239229
prodVersion = prodVersion.trim();
240-
String[] items = prodVersion.split("\\.");
230+
final String[] items = prodVersion.split("\\.");
241231
if (Integer.parseInt(items[0]) > 6) {
242232
prodVersion = "6.5.0";
243233
} else if (Integer.parseInt(items[0]) == 6 && Integer.parseInt(items[1]) >= 4) {

0 commit comments

Comments
 (0)