Skip to content
This repository was archived by the owner on Jan 15, 2020. It is now read-only.

Commit 303e2a7

Browse files
author
Chiradeep Vittal
committed
Start of zonesfeature / mycloud/cloudkit
1 parent 76a30cc commit 303e2a7

155 files changed

Lines changed: 10514 additions & 3727 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.

agent/.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
88
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
99
<classpathentry combineaccessrules="false" kind="src" path="/deps"/>
10+
<classpathentry combineaccessrules="false" kind="src" path="/thirdparty"/>
1011
<classpathentry combineaccessrules="false" kind="src" path="/tools"/>
1112
<classpathentry kind="output" path="bin"/>
1213
</classpath>

agent/src/com/cloud/agent/AgentShell.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,14 @@ private void run(String[] args) {
533533
instance = "";
534534
} else {
535535
instance += ".";
536-
}
536+
}
537+
538+
String pidDir = getProperty(null, "piddir");
539+
540+
537541
final String run = "agent." + instance + "pid";
538542
s_logger.debug("Checking to see if " + run + "exists.");
539-
ProcessUtil.pidCheck(run);
543+
ProcessUtil.pidCheck(pidDir, run);
540544

541545
launchAgent();
542546

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Copyright (C) 2011 Cloud.com. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later
9+
version.
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
package com.cloud.agent.configuration;
20+
21+
import java.util.List;
22+
import java.util.Map;
23+
24+
import com.cloud.utils.component.Adapter;
25+
import com.cloud.utils.component.ComponentLibraryBase;
26+
import com.cloud.utils.component.ComponentLocator.ComponentInfo;
27+
import com.cloud.utils.component.Manager;
28+
import com.cloud.utils.component.SystemIntegrityChecker;
29+
import com.cloud.utils.db.GenericDao;
30+
31+
32+
public class AgentComponentLibraryBase extends ComponentLibraryBase {
33+
34+
@Override
35+
public List<SystemIntegrityChecker> getSystemIntegrityCheckers() {
36+
return null;
37+
}
38+
39+
@Override
40+
public Map<String, ComponentInfo<GenericDao<?, ?>>> getDaos() {
41+
return null;
42+
}
43+
44+
@Override
45+
public Map<String, ComponentInfo<Manager>> getManagers() {
46+
if (_managers.size() == 0) {
47+
populateManagers();
48+
}
49+
return _managers;
50+
}
51+
52+
@Override
53+
public Map<String, List<ComponentInfo<Adapter>>> getAdapters() {
54+
if (_adapters.size() == 0) {
55+
populateAdapters();
56+
}
57+
return _adapters;
58+
}
59+
60+
@Override
61+
public Map<Class<?>, Class<?>> getFactories() {
62+
return null;
63+
}
64+
65+
protected void populateManagers() {
66+
//addManager("StackMaidManager", StackMaidManagerImpl.class);
67+
}
68+
69+
protected void populateAdapters() {
70+
71+
}
72+
73+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
package com.cloud.agent.dhcp;
19+
20+
import java.net.InetAddress;
21+
import java.util.List;
22+
import java.util.Map;
23+
24+
import com.cloud.utils.Pair;
25+
import com.cloud.utils.component.Adapter;
26+
27+
public interface DhcpSnooper extends Adapter{
28+
29+
public InetAddress getIPAddr(String macAddr, String vmName);
30+
31+
public InetAddress getDhcpServerIP();
32+
33+
public void cleanup(String macAddr, String vmName);
34+
35+
public Map<String, InetAddress> syncIpAddr();
36+
37+
public boolean stop();
38+
39+
public void initializeMacTable(List<Pair<String, String>> macVmNameList);
40+
41+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package com.cloud.agent.dhcp;
2+
3+
import java.net.InetAddress;
4+
import java.net.UnknownHostException;
5+
6+
import java.util.HashMap;
7+
import java.util.Iterator;
8+
import java.util.List;
9+
import java.util.Map;
10+
import java.util.Queue;
11+
import java.util.concurrent.ConcurrentHashMap;
12+
import java.util.concurrent.ConcurrentLinkedQueue;
13+
14+
import javax.ejb.Local;
15+
import javax.naming.ConfigurationException;
16+
17+
import org.apache.log4j.Logger;
18+
19+
import com.cloud.agent.api.Answer;
20+
import com.cloud.agent.api.Command;
21+
import com.cloud.utils.Pair;
22+
import com.cloud.utils.net.NetUtils;
23+
24+
@Local(value = {DhcpSnooper.class})
25+
public class FakeDhcpSnooper implements DhcpSnooper {
26+
private static final Logger s_logger = Logger.getLogger(FakeDhcpSnooper.class);
27+
private Queue<String> _ipAddresses = new ConcurrentLinkedQueue<String>();
28+
private Map<String, String> _macIpMap = new ConcurrentHashMap<String, String>();
29+
private Map<String, InetAddress> _vmIpMap = new ConcurrentHashMap<String, InetAddress>();
30+
31+
@Override
32+
public boolean configure(String name, Map<String, Object> params)
33+
throws ConfigurationException {
34+
String guestIpRange = (String)params.get("guest.ip.range");
35+
if (guestIpRange != null) {
36+
String [] guestIps = guestIpRange.split("-");
37+
if (guestIps.length == 2) {
38+
long start = NetUtils.ip2Long(guestIps[0]);
39+
long end = NetUtils.ip2Long(guestIps[1]);
40+
while (start <= end) {
41+
_ipAddresses.offer(NetUtils.long2Ip(start++));
42+
}
43+
}
44+
}
45+
return true;
46+
}
47+
48+
@Override
49+
public boolean start() {
50+
return true;
51+
}
52+
53+
@Override
54+
public String getName() {
55+
return "FakeDhcpSnooper";
56+
}
57+
58+
@Override
59+
public InetAddress getIPAddr(String macAddr, String vmName) {
60+
String ipAddr = _ipAddresses.poll();
61+
if (ipAddr == null) {
62+
s_logger.warn("No ip addresses left in queue");
63+
return null;
64+
}
65+
try {
66+
InetAddress inetAddr = InetAddress.getByName(ipAddr);
67+
_macIpMap.put(macAddr.toLowerCase(), ipAddr);
68+
_vmIpMap.put(vmName, inetAddr);
69+
s_logger.info("Got ip address " + ipAddr + " for vm " + vmName + " mac=" + macAddr.toLowerCase());
70+
return inetAddr;
71+
} catch (UnknownHostException e) {
72+
s_logger.warn("Failed to get InetAddress for " + ipAddr);
73+
return null;
74+
}
75+
}
76+
77+
@Override
78+
public void cleanup(String macAddr, String vmName) {
79+
try {
80+
if (macAddr == null) {
81+
return;
82+
}
83+
InetAddress inetAddr = _vmIpMap.remove(vmName);
84+
String ipAddr = inetAddr.getHostName();
85+
for (Map.Entry<String, String> entry: _macIpMap.entrySet()) {
86+
if (entry.getValue().equalsIgnoreCase(ipAddr)){
87+
macAddr = entry.getKey();
88+
break;
89+
}
90+
}
91+
ipAddr = _macIpMap.remove(macAddr);
92+
93+
s_logger.info("Cleaning up for mac address: " + macAddr + " ip=" + ipAddr + " inetAddr=" + inetAddr);
94+
if (ipAddr != null) {
95+
_ipAddresses.offer(ipAddr);
96+
}
97+
} catch (Exception e) {
98+
s_logger.debug("Failed to cleanup: " + e.toString());
99+
}
100+
}
101+
102+
@Override
103+
public Map<String, InetAddress> syncIpAddr() {
104+
return _vmIpMap;
105+
}
106+
107+
@Override
108+
public boolean stop() {
109+
return false;
110+
}
111+
112+
@Override
113+
public void initializeMacTable(List<Pair<String, String>> macVmNameList) {
114+
115+
116+
}
117+
118+
@Override
119+
public InetAddress getDhcpServerIP() {
120+
// TODO Auto-generated method stub
121+
return null;
122+
}
123+
124+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
package com.cloud.agent.mockvm;
20+
21+
import com.cloud.vm.VirtualMachine.State;
22+
23+
// As storage is mapped from storage device, can virtually treat that VM here does
24+
// not need any local storage resource, therefore we don't have attribute here for storage
25+
public class MockVm {
26+
27+
private String vmName;
28+
private State state = State.Stopped;
29+
30+
private long ramSize; // unit of Mbytes
31+
private int cpuCount;
32+
private int utilization; // in percentage
33+
private int vncPort; // 0-based allocation, real port number needs to be applied with base
34+
35+
public MockVm() {
36+
}
37+
38+
public MockVm(String vmName, State state, long ramSize, int cpuCount, int utilization, int vncPort) {
39+
this.vmName = vmName;
40+
this.state = state;
41+
this.ramSize = ramSize;
42+
this.cpuCount = cpuCount;
43+
this.utilization = utilization;
44+
this.vncPort = vncPort;
45+
}
46+
47+
public String getName() {
48+
return vmName;
49+
}
50+
51+
public State getState() {
52+
return state;
53+
}
54+
55+
public void setState(State state) {
56+
this.state = state;
57+
}
58+
59+
public long getRamSize() {
60+
return ramSize;
61+
}
62+
63+
public int getCpuCount() {
64+
return cpuCount;
65+
}
66+
67+
public int getUtilization() {
68+
return utilization;
69+
}
70+
71+
public int getVncPort() {
72+
return vncPort;
73+
}
74+
}
75+

0 commit comments

Comments
 (0)