Skip to content

Commit 1e44925

Browse files
author
Alex Huang
committed
api refactoring
1 parent 3efae81 commit 1e44925

350 files changed

Lines changed: 6109 additions & 4390 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/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
import com.cloud.network.Networks.BroadcastDomainType;
179179
import com.cloud.network.Networks.TrafficType;
180180
import com.cloud.network.NetworkEnums.RouterPrivateIpStrategy;
181+
import com.cloud.network.router.VirtualRouter;
181182
import com.cloud.resource.ServerResource;
182183
import com.cloud.resource.ServerResourceBase;
183184
import com.cloud.storage.Storage;
@@ -203,7 +204,6 @@
203204
import com.cloud.utils.script.Script;
204205
import com.cloud.vm.ConsoleProxyVO;
205206
import com.cloud.vm.DiskProfile;
206-
import com.cloud.vm.DomainRouter;
207207
import com.cloud.vm.SecondaryStorageVmVO;
208208
import com.cloud.vm.State;
209209
import com.cloud.vm.VirtualMachine;
@@ -869,7 +869,7 @@ boolean isDirectAttachedNetwork(String type) {
869869
}
870870

871871
protected synchronized String startDomainRouter(StartRouterCommand cmd) {
872-
DomainRouter router = cmd.getRouter();
872+
VirtualRouter router = cmd.getRouter();
873873
List<InterfaceDef> nics = null;
874874
try {
875875
nics = createRouterVMNetworks(cmd);
@@ -2087,7 +2087,7 @@ protected static List<VolumeVO> findVolumes(final List<VolumeVO> volumes, final
20872087

20882088
private Answer execute(StartRouterCommand cmd) {
20892089

2090-
final DomainRouter router = cmd.getRouter();
2090+
final VirtualRouter router = cmd.getRouter();
20912091

20922092
String result = null;
20932093

@@ -3649,7 +3649,7 @@ private List<InterfaceDef> createUserVMNetworks(StartCommand cmd) throws Interna
36493649

36503650
private List<InterfaceDef> createRouterVMNetworks(StartRouterCommand cmd) throws InternalErrorException {
36513651
List<InterfaceDef> nics = new ArrayList<InterfaceDef>();
3652-
DomainRouter router = cmd.getRouter();
3652+
VirtualRouter router = cmd.getRouter();
36533653
String guestMac = router.getGuestMacAddress();
36543654
String privateMac = router.getPrivateMacAddress();
36553655
String pubMac = router.getPublicMacAddress();

api/.classpath

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
<classpathentry kind="src" path="src"/>
44
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
55
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
6+
<classpathentry kind="lib" path="/thirdparty/log4j-1.2.15.jar"/>
7+
<classpathentry kind="lib" path="/thirdparty/gson.jar"/>
68
<classpathentry kind="output" path="bin"/>
79
</classpath>

api/src/com/cloud/alert/Alert.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
package com.cloud.alert;
19+
20+
import java.util.Date;
21+
22+
/**
23+
* @author ahuang
24+
*
25+
*/
26+
public interface Alert {
27+
long getId();
28+
short getType();
29+
String getSubject();
30+
Long getPodId();
31+
long getDataCenterId();
32+
int getSentCount();
33+
Date getCreatedDate();
34+
Date getLastSent();
35+
Date getResolved();
36+
}
File renamed without changes.

server/src/com/cloud/api/BaseAsyncCmd.java renamed to api/src/com/cloud/api/BaseAsyncCmd.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
package com.cloud.api;
1919

2020
import com.cloud.api.response.AsyncJobResponse;
21-
import com.cloud.async.AsyncJobManager;
22-
import com.cloud.async.AsyncJobVO;
2321

2422
/**
2523
* A base command for supporting asynchronous API calls. When an API command is received, the command will be
@@ -28,8 +26,7 @@
2826
* queryAsyncJobResult API command.
2927
*/
3028
public abstract class BaseAsyncCmd extends BaseCmd {
31-
private AsyncJobManager _asyncJobMgr = null;
32-
private AsyncJobVO _job = null;
29+
private Object _job = null;
3330

3431
@Parameter(name="starteventid", type=CommandType.LONG)
3532
private Long startEventId;
@@ -64,23 +61,11 @@ public ResponseObject getResponse(long jobId) {
6461
return response;
6562
}
6663

67-
public AsyncJobManager getAsyncJobManager() {
68-
return _asyncJobMgr;
69-
}
70-
71-
public void setAsyncJobManager(AsyncJobManager mgr) {
72-
_asyncJobMgr = mgr;
73-
}
74-
7564
public void synchronizeCommand(String syncObjType, long syncObjId) {
76-
_asyncJobMgr.syncAsyncJobExecution(_job, syncObjType, syncObjId);
65+
_responseGenerator.synchronizeCommand(_job, syncObjType, syncObjId);
7766
}
7867

79-
public AsyncJobVO getJob() {
80-
return _job;
81-
}
82-
83-
public void setJob(AsyncJobVO job) {
68+
public void setJob(Object job) {
8469
_job = job;
8570
}
8671

@@ -91,5 +76,4 @@ public Long getStartEventId() {
9176
public void setStartEventId(Long startEventId) {
9277
this.startEventId = startEventId;
9378
}
94-
9579
}

server/src/com/cloud/api/BaseAsyncCreateCmd.java renamed to api/src/com/cloud/api/BaseAsyncCreateCmd.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.cloud.api;
22

3-
import com.cloud.api.response.ApiResponseSerializer;
43
import com.cloud.api.response.CreateCmdResponse;
54

65
public abstract class BaseAsyncCreateCmd extends BaseAsyncCmd {
@@ -22,6 +21,6 @@ public String getResponse(long jobId, long objectId) {
2221
response.setJobId(jobId);
2322
response.setId(objectId);
2423
response.setResponseName(getName());
25-
return ApiResponseSerializer.toSerializedString(response, getResponseType());
24+
return _responseGenerator.toSerializedString(response, getResponseType());
2625
}
2726
}
Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@
2727

2828
import org.apache.log4j.Logger;
2929

30-
import com.cloud.agent.AgentManager;
31-
import com.cloud.async.AsyncJobManager;
3230
import com.cloud.configuration.ConfigurationService;
33-
import com.cloud.consoleproxy.ConsoleProxyManager;
31+
import com.cloud.consoleproxy.ConsoleProxyService;
32+
import com.cloud.dao.EntityManager;
3433
import com.cloud.exception.ConcurrentOperationException;
3534
import com.cloud.exception.InsufficientCapacityException;
3635
import com.cloud.exception.ResourceUnavailableException;
3736
import com.cloud.network.DomainRouterService;
38-
import com.cloud.network.NetworkManager;
39-
import com.cloud.network.security.NetworkGroupManager;
40-
import com.cloud.server.ManagementServer;
41-
import com.cloud.storage.StorageManager;
42-
import com.cloud.storage.snapshot.SnapshotManager;
43-
import com.cloud.template.TemplateManager;
37+
import com.cloud.network.NetworkService;
38+
import com.cloud.network.security.NetworkGroupService;
39+
import com.cloud.resource.ResourceService;
40+
import com.cloud.server.ManagementService;
41+
import com.cloud.storage.StorageService;
42+
import com.cloud.storage.snapshot.SnapshotService;
43+
import com.cloud.template.TemplateService;
4444
import com.cloud.user.Account;
4545
import com.cloud.user.AccountService;
4646
import com.cloud.utils.Pair;
@@ -89,33 +89,35 @@ public enum CommandType {
8989
public static ConfigurationService _configService;
9090
public static AccountService _accountService;
9191
public static UserVmService _userVmService;
92-
public static ManagementServer _mgr;
93-
public static AsyncJobManager _asyncMgr;
94-
public static StorageManager _storageMgr;
95-
public static AgentManager _agentMgr;
96-
public static NetworkManager _networkMgr;
97-
public static TemplateManager _templateMgr;
98-
public static NetworkGroupManager _networkGroupMgr;
99-
public static SnapshotManager _snapshotMgr;
100-
public static ConsoleProxyManager _consoleProxyMgr;
101-
public static DomainRouterService _routerMgr;
92+
public static ManagementService _mgr;
93+
public static StorageService _storageMgr;
94+
public static ResourceService _resourceService;
95+
public static NetworkService _networkService;
96+
public static TemplateService _templateService;
97+
public static NetworkGroupService _networkGroupMgr;
98+
public static SnapshotService _snapshotMgr;
99+
public static ConsoleProxyService _consoleProxyMgr;
100+
public static DomainRouterService _routerService;
101+
public static ResponseGenerator _responseGenerator;
102+
public static EntityManager _entityMgr;
102103

103104

104-
static void setComponents(){
105-
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
105+
static void setComponents(ResponseGenerator generator){
106+
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
107+
_mgr = (ManagementService)ComponentLocator.getComponent(ManagementService.Name);
106108
_accountService = locator.getManager(AccountService.class);
107109
_configService = locator.getManager(ConfigurationService.class);
108110
_userVmService = locator.getManager(UserVmService.class);
109-
_mgr = (ManagementServer)locator.getComponent("management-server");
110-
_asyncMgr = locator.getManager(AsyncJobManager.class);
111-
_storageMgr = locator.getManager(StorageManager.class);
112-
_agentMgr = locator.getManager(AgentManager.class);
113-
_networkMgr = locator.getManager(NetworkManager.class);
114-
_templateMgr = locator.getManager(TemplateManager.class);
115-
_networkGroupMgr = locator.getManager(NetworkGroupManager.class);
116-
_snapshotMgr = locator.getManager(SnapshotManager.class);
117-
_consoleProxyMgr = locator.getManager(ConsoleProxyManager.class);
118-
_routerMgr = locator.getManager(DomainRouterService.class);
111+
_storageMgr = locator.getManager(StorageService.class);
112+
_resourceService = locator.getManager(ResourceService.class);
113+
_networkService = locator.getManager(NetworkService.class);
114+
_templateService = locator.getManager(TemplateService.class);
115+
_networkGroupMgr = locator.getManager(NetworkGroupService.class);
116+
_snapshotMgr = locator.getManager(SnapshotService.class);
117+
_consoleProxyMgr = locator.getManager(ConsoleProxyService.class);
118+
_routerService = locator.getManager(DomainRouterService.class);
119+
_entityMgr = locator.getManager(EntityManager.class);
120+
_responseGenerator = generator;
119121
}
120122

121123
public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException;
@@ -334,14 +336,14 @@ public String buildResponse(ServerApiException apiException, String responseType
334336
StringBuffer sb = new StringBuffer();
335337
if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
336338
// JSON response
337-
sb.append("{ \"" + getName() + "\" : { " + "\"@attributes\":{\"cloud-stack-version\":\""+ApiDBUtils.getVersion()+"\"},");
339+
sb.append("{ \"" + getName() + "\" : { " + "\"@attributes\":{\"cloud-stack-version\":\""+_mgr.getVersion()+"\"},");
338340
sb.append("\"errorcode\" : \"" + apiException.getErrorCode() + "\", \"description\" : \"" + apiException.getDescription() + "\" } }");
339341
} else {
340342
sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
341343
sb.append("<" + getName() + ">");
342344
sb.append("<errorcode>" + apiException.getErrorCode() + "</errorcode>");
343345
sb.append("<description>" + escapeXml(apiException.getDescription()) + "</description>");
344-
sb.append("</" + getName() + " cloud-stack-version=\""+ApiDBUtils.getVersion()+ "\">");
346+
sb.append("</" + getName() + " cloud-stack-version=\""+_mgr.getVersion()+ "\">");
345347
}
346348
return sb.toString();
347349
}
@@ -352,10 +354,10 @@ public String buildResponse(List<Pair<String, Object>> tagList, String responseT
352354

353355
// set up the return value with the name of the response
354356
if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
355-
prefixSb.append("{ \"" + getName() + "\" : { \"@attributes\":{\"cloud-stack-version\":\""+ApiDBUtils.getVersion()+"\"},");
357+
prefixSb.append("{ \"" + getName() + "\" : { \"@attributes\":{\"cloud-stack-version\":\""+ _mgr.getVersion()+"\"},");
356358
} else {
357359
prefixSb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
358-
prefixSb.append("<" + getName() + " cloud-stack-version=\""+ApiDBUtils.getVersion()+ "\">");
360+
prefixSb.append("<" + getName() + " cloud-stack-version=\""+_mgr.getVersion()+ "\">");
359361
}
360362

361363
int i = 0;

server/src/com/cloud/api/Implementation.java renamed to api/src/com/cloud/api/Implementation.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import java.lang.annotation.RetentionPolicy;
77
import java.lang.annotation.Target;
88

9-
import com.cloud.server.ManagementServer;
10-
119
@Retention(RetentionPolicy.RUNTIME)
1210
@Target({TYPE})
1311
public @interface Implementation {

0 commit comments

Comments
 (0)