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

Commit a0c3d28

Browse files
author
Edison Su
committed
merge to master
2 parents ed06541 + be98501 commit a0c3d28

397 files changed

Lines changed: 65988 additions & 2763 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/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
<artifactId>cloud-utils</artifactId>
3737
<version>${project.version}</version>
3838
</dependency>
39+
<dependency>
40+
<groupId>commons-daemon</groupId>
41+
<artifactId>commons-daemon</artifactId>
42+
<version>${cs.daemon.version}</version>
43+
</dependency>
3944
</dependencies>
4045
<build>
4146
<defaultGoal>install</defaultGoal>

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

Lines changed: 23 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.io.InputStream;
2525
import java.lang.reflect.Constructor;
2626
import java.lang.reflect.InvocationTargetException;
27-
import java.lang.reflect.Method;
2827
import java.net.HttpURLConnection;
2928
import java.util.ArrayList;
3029
import java.util.Collections;
@@ -38,6 +37,9 @@
3837

3938
import javax.naming.ConfigurationException;
4039

40+
import org.apache.commons.daemon.Daemon;
41+
import org.apache.commons.daemon.DaemonContext;
42+
import org.apache.commons.daemon.DaemonInitException;
4143
import org.apache.commons.httpclient.HttpClient;
4244
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
4345
import org.apache.commons.httpclient.methods.GetMethod;
@@ -47,7 +49,6 @@
4749
import com.cloud.agent.Agent.ExitStatus;
4850
import com.cloud.agent.dao.StorageComponent;
4951
import com.cloud.agent.dao.impl.PropertiesStorage;
50-
import com.cloud.host.Host;
5152
import com.cloud.resource.ServerResource;
5253
import com.cloud.utils.LogUtils;
5354
import com.cloud.utils.NumbersUtil;
@@ -58,7 +59,7 @@
5859
import com.cloud.utils.exception.CloudRuntimeException;
5960
import com.cloud.utils.script.Script;
6061

61-
public class AgentShell implements IAgentShell {
62+
public class AgentShell implements IAgentShell, Daemon {
6263
private static final Logger s_logger = Logger.getLogger(AgentShell.class
6364
.getName());
6465
private static final MultiThreadedHttpConnectionManager s_httpClientManager = new MultiThreadedHttpConnectionManager();
@@ -79,7 +80,6 @@ public class AgentShell implements IAgentShell {
7980
private int _nextAgentId = 1;
8081
private volatile boolean _exit = false;
8182
private int _pingRetries;
82-
private Thread _consoleProxyMain = null;
8383
private final List<Agent> _agents = new ArrayList<Agent>();
8484

8585
public AgentShell() {
@@ -376,7 +376,17 @@ protected boolean parseCommand(final String[] args)
376376

377377
return true;
378378
}
379-
379+
380+
@Override
381+
public void init(DaemonContext dc) throws DaemonInitException {
382+
s_logger.debug("Initializing AgentShell from JSVC");
383+
try {
384+
init(dc.getArguments());
385+
} catch (ConfigurationException ex) {
386+
throw new DaemonInitException("Initialization failed", ex);
387+
}
388+
}
389+
380390
public void init(String[] args) throws ConfigurationException {
381391

382392
// PropertiesUtil is used both in management server and agent packages,
@@ -402,11 +412,13 @@ public void init(String[] args) throws ConfigurationException {
402412
loadProperties();
403413
parseCommand(args);
404414

405-
List<String> properties = Collections.list((Enumeration<String>)_properties.propertyNames());
406-
for (String property:properties){
407-
s_logger.debug("Found property: " + property);
415+
if (s_logger.isDebugEnabled()) {
416+
List<String> properties = Collections.list((Enumeration<String>)_properties.propertyNames());
417+
for (String property:properties){
418+
s_logger.debug("Found property: " + property);
419+
}
408420
}
409-
421+
410422
s_logger.info("Defaulting to using properties file for storage");
411423
_storage = new PropertiesStorage();
412424
_storage.configure("Storage", new HashMap<String, Object>());
@@ -434,71 +446,6 @@ private void launchAgent() throws ConfigurationException {
434446
launchAgentFromTypeInfo();
435447
}
436448

437-
private boolean needConsoleProxy() {
438-
for (Agent agent : _agents) {
439-
if (agent.getResource().getType().equals(Host.Type.ConsoleProxy)
440-
|| agent.getResource().getType().equals(Host.Type.Routing))
441-
return true;
442-
}
443-
return false;
444-
}
445-
446-
private int getConsoleProxyPort() {
447-
int port = NumbersUtil.parseInt(
448-
getProperty(null, "consoleproxy.httpListenPort"), 443);
449-
return port;
450-
}
451-
452-
private void openPortWithIptables(int port) {
453-
// TODO
454-
}
455-
456-
private void launchConsoleProxy() throws ConfigurationException {
457-
if (!needConsoleProxy()) {
458-
if (s_logger.isInfoEnabled())
459-
s_logger.info("Storage only agent, no need to start console proxy on it");
460-
return;
461-
}
462-
463-
int port = getConsoleProxyPort();
464-
openPortWithIptables(port);
465-
466-
_consoleProxyMain = new Thread(new Runnable() {
467-
@Override
468-
public void run() {
469-
try {
470-
Class<?> consoleProxyClazz = Class.forName("com.cloud.consoleproxy.ConsoleProxy");
471-
472-
try {
473-
Method method = consoleProxyClazz.getMethod("start",
474-
Properties.class);
475-
method.invoke(null, _properties);
476-
} catch (SecurityException e) {
477-
s_logger.error("Unable to launch console proxy due to SecurityException");
478-
System.exit(ExitStatus.Error.value());
479-
} catch (NoSuchMethodException e) {
480-
s_logger.error("Unable to launch console proxy due to NoSuchMethodException");
481-
System.exit(ExitStatus.Error.value());
482-
} catch (IllegalArgumentException e) {
483-
s_logger.error("Unable to launch console proxy due to IllegalArgumentException");
484-
System.exit(ExitStatus.Error.value());
485-
} catch (IllegalAccessException e) {
486-
s_logger.error("Unable to launch console proxy due to IllegalAccessException");
487-
System.exit(ExitStatus.Error.value());
488-
} catch (InvocationTargetException e) {
489-
s_logger.error("Unable to launch console proxy due to InvocationTargetException");
490-
System.exit(ExitStatus.Error.value());
491-
}
492-
} catch (final ClassNotFoundException e) {
493-
s_logger.error("Unable to launch console proxy due to ClassNotFoundException");
494-
System.exit(ExitStatus.Error.value());
495-
}
496-
}
497-
}, "Console-Proxy-Main");
498-
_consoleProxyMain.setDaemon(true);
499-
_consoleProxyMain.start();
500-
}
501-
502449
private void launchAgentFromClassInfo(String resourceClassNames)
503450
throws ConfigurationException {
504451
String[] names = resourceClassNames.split("\\|");
@@ -591,14 +538,6 @@ public void start() {
591538

592539
launchAgent();
593540

594-
//
595-
// For both KVM & Xen-Server hypervisor, we have switched to
596-
// VM-based console proxy solution, disable launching
597-
// of console proxy here
598-
//
599-
// launchConsoleProxy();
600-
//
601-
602541
try {
603542
while (!_exit)
604543
Thread.sleep(1000);
@@ -618,9 +557,6 @@ public void start() {
618557

619558
public void stop() {
620559
_exit = true;
621-
if (_consoleProxyMain != null) {
622-
_consoleProxyMain.interrupt();
623-
}
624560
}
625561

626562
public void destroy() {
@@ -629,11 +565,13 @@ public void destroy() {
629565

630566
public static void main(String[] args) {
631567
try {
568+
s_logger.debug("Initializing AgentShell from main");
632569
AgentShell shell = new AgentShell();
633570
shell.init(args);
634571
shell.start();
635572
} catch (ConfigurationException e) {
636573
System.out.println(e.getMessage());
637574
}
638575
}
576+
639577
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.agent.api.to;
18+
19+
public class DnsmasqTO {
20+
String routerIp;
21+
String gateway;
22+
String netmask;
23+
24+
public DnsmasqTO(String routerIp, String gateway, String netmask) {
25+
this.routerIp = routerIp;
26+
this.gateway = gateway;
27+
this.netmask =netmask;
28+
}
29+
30+
public void setRouterIp(String routerIp){
31+
this.routerIp = routerIp;
32+
}
33+
34+
public void setGateway(String gateway) {
35+
this.gateway = gateway;
36+
}
37+
38+
public void setNetmask(String netmask) {
39+
this.netmask = netmask ;
40+
}
41+
42+
public String getRouterIp() {
43+
return routerIp;
44+
}
45+
46+
public String getGateway() {
47+
return gateway;
48+
}
49+
50+
public String getNetmask() {
51+
return netmask;
52+
}
53+
}

api/src/com/cloud/agent/api/to/NetworkACLTO.java

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import java.util.ArrayList;
2121
import java.util.List;
2222

23+
import com.cloud.network.vpc.NetworkACLItem;
24+
import com.cloud.network.vpc.NetworkACLItem.TrafficType;
2325
import org.apache.cloudstack.api.InternalIdentity;
2426

25-
import com.cloud.network.rules.FirewallRule;
26-
import com.cloud.network.rules.FirewallRule.TrafficType;
2727
import com.cloud.utils.net.NetUtils;
2828

2929

@@ -37,15 +37,16 @@ public class NetworkACLTO implements InternalIdentity {
3737
private List<String> cidrList;
3838
private Integer icmpType;
3939
private Integer icmpCode;
40-
private FirewallRule.TrafficType trafficType;
41-
40+
private TrafficType trafficType;
41+
String action;
42+
int number;
4243

4344
protected NetworkACLTO() {
4445
}
4546

4647

4748
public NetworkACLTO(long id,String vlanTag, String protocol, Integer portStart, Integer portEnd, boolean revoked,
48-
boolean alreadyAdded, List<String> cidrList, Integer icmpType,Integer icmpCode,TrafficType trafficType) {
49+
boolean alreadyAdded, List<String> cidrList, Integer icmpType,Integer icmpCode,TrafficType trafficType, boolean allow, int number) {
4950
this.vlanTag = vlanTag;
5051
this.protocol = protocol;
5152

@@ -70,20 +71,28 @@ public NetworkACLTO(long id,String vlanTag, String protocol, Integer portStart,
7071
this.icmpType = icmpType;
7172
this.icmpCode = icmpCode;
7273
this.trafficType = trafficType;
74+
75+
if(!allow){
76+
this.action = "DROP";
77+
} else {
78+
this.action = "ACCEPT";
79+
}
80+
81+
this.number = number;
7382
}
7483

75-
public NetworkACLTO(FirewallRule rule, String vlanTag, FirewallRule.TrafficType trafficType ) {
84+
public NetworkACLTO(NetworkACLItem rule, String vlanTag, NetworkACLItem.TrafficType trafficType ) {
7685
this(rule.getId(), vlanTag, rule.getProtocol(), rule.getSourcePortStart(), rule.getSourcePortEnd(),
77-
rule.getState() == FirewallRule.State.Revoke, rule.getState() == FirewallRule.State.Active,
78-
rule.getSourceCidrList() ,rule.getIcmpType(), rule.getIcmpCode(),trafficType);
86+
rule.getState() == NetworkACLItem.State.Revoke, rule.getState() == NetworkACLItem.State.Active,
87+
rule.getSourceCidrList() ,rule.getIcmpType(), rule.getIcmpCode(),trafficType, rule.getAction() == NetworkACLItem.Action.Allow, rule.getNumber());
7988
}
8089

8190
public long getId() {
8291
return id;
8392
}
8493

8594
public String getSrcVlanTag() {
86-
return vlanTag;
95+
return vlanTag;
8796
}
8897

8998
public String getProtocol() {
@@ -95,18 +104,18 @@ public int[] getSrcPortRange() {
95104
}
96105

97106
public Integer getIcmpType(){
98-
return icmpType;
107+
return icmpType;
99108
}
100109

101110
public Integer getIcmpCode(){
102-
return icmpCode;
111+
return icmpCode;
103112
}
104113

105114
public String getStringPortRange() {
106-
if (portRange == null || portRange.length < 2)
107-
return "0:0";
108-
else
109-
return NetUtils.portRangeToString(portRange);
115+
if (portRange == null || portRange.length < 2)
116+
return "0:0";
117+
else
118+
return NetUtils.portRangeToString(portRange);
110119
}
111120

112121
public boolean revoked() {
@@ -121,7 +130,15 @@ public boolean isAlreadyAdded() {
121130
return alreadyAdded;
122131
}
123132

124-
public FirewallRule.TrafficType getTrafficType() {
133+
public TrafficType getTrafficType() {
125134
return trafficType;
126135
}
136+
137+
public String getAction() {
138+
return action;
139+
}
140+
141+
public int getNumber(){
142+
return number;
143+
}
127144
}

api/src/com/cloud/async/AsyncJob.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public enum Type {
5050
AutoScaleVmProfile,
5151
AutoScaleVmGroup,
5252
GlobalLoadBalancerRule,
53+
LoadBalancerRule,
5354
AffinityGroup,
55+
InternalLbVm,
5456
DedicatedGuestVlanRange
5557
}
5658

0 commit comments

Comments
 (0)