forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDummySecondaryStorageResource.java
More file actions
217 lines (182 loc) · 7.16 KB
/
DummySecondaryStorageResource.java
File metadata and controls
217 lines (182 loc) · 7.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.storage.resource;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.CheckHealthAnswer;
import com.cloud.agent.api.CheckHealthCommand;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.GetStorageStatsAnswer;
import com.cloud.agent.api.GetStorageStatsCommand;
import com.cloud.agent.api.PingCommand;
import com.cloud.agent.api.PingStorageCommand;
import com.cloud.agent.api.ReadyAnswer;
import com.cloud.agent.api.ReadyCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupStorageCommand;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.DownloadCommand;
import com.cloud.agent.api.storage.DownloadProgressCommand;
import com.cloud.host.Host;
import com.cloud.host.Host.Type;
import com.cloud.resource.ServerResource;
import com.cloud.resource.ServerResourceBase;
import com.cloud.storage.Storage;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.template.TemplateConstants;
import com.cloud.storage.template.TemplateInfo;
public class DummySecondaryStorageResource extends ServerResourceBase implements ServerResource {
private static final Logger s_logger = Logger.getLogger(DummySecondaryStorageResource.class);
String _dc;
String _pod;
String _guid;
String _dummyPath;
@Inject VMTemplateDao _tmpltDao;
private boolean _useServiceVm;
public DummySecondaryStorageResource() {
setUseServiceVm(true);
}
public DummySecondaryStorageResource(boolean useServiceVM) {
setUseServiceVm(useServiceVM);
}
@Override
protected String getDefaultScriptsDir() {
return "dummy";
}
@Override
public Answer executeRequest(Command cmd) {
if (cmd instanceof DownloadProgressCommand) {
return new DownloadAnswer(null, 100, cmd,
com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
"dummyFS",
"/dummy");
} else if (cmd instanceof DownloadCommand) {
return new DownloadAnswer(null, 100, cmd,
com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
"dummyFS",
"/dummy");
} else if (cmd instanceof GetStorageStatsCommand) {
return execute((GetStorageStatsCommand)cmd);
} else if (cmd instanceof CheckHealthCommand) {
return new CheckHealthAnswer((CheckHealthCommand)cmd, true);
} else if (cmd instanceof ReadyCommand) {
return new ReadyAnswer((ReadyCommand)cmd);
} else {
return Answer.createUnsupportedCommandAnswer(cmd);
}
}
@Override
public PingCommand getCurrentStatus(long id) {
return new PingStorageCommand(Host.Type.Storage, id, new HashMap<String, Boolean>());
}
@Override
public Type getType() {
return Host.Type.SecondaryStorage;
}
@Override
public StartupCommand[] initialize() {
final StartupStorageCommand cmd = new StartupStorageCommand("dummy",
StoragePoolType.NetworkFilesystem, 1024*1024*1024*100L,
new HashMap<String, TemplateInfo>());
cmd.setResourceType(Storage.StorageResourceType.SECONDARY_STORAGE);
cmd.setIqn(null);
cmd.setNfsShare(_guid);
fillNetworkInformation(cmd);
cmd.setDataCenter(_dc);
cmd.setPod(_pod);
cmd.setGuid(_guid);
cmd.setName(_guid);
cmd.setVersion(DummySecondaryStorageResource.class.getPackage().getImplementationVersion());
/* gather TemplateInfo in second storage */
cmd.setTemplateInfo(getDefaultSystemVmTemplateInfo());
cmd.getHostDetails().put("mount.parent", "dummy");
cmd.getHostDetails().put("mount.path", "dummy");
cmd.getHostDetails().put("orig.url", _guid);
String tok[] = _dummyPath.split(":");
cmd.setPrivateIpAddress(tok[0]);
return new StartupCommand [] {cmd};
}
protected GetStorageStatsAnswer execute(GetStorageStatsCommand cmd) {
long size = 1024*1024*1024*100L;
return new GetStorageStatsAnswer(cmd, 0, size);
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params);
_guid = (String)params.get("guid");
if (_guid == null) {
throw new ConfigurationException("Unable to find the guid");
}
_dc = (String)params.get("zone");
if (_dc == null) {
throw new ConfigurationException("Unable to find the zone");
}
_pod = (String)params.get("pod");
_dummyPath = (String)params.get("mount.path");
if (_dummyPath == null) {
throw new ConfigurationException("Unable to find mount.path");
}
return true;
}
public void setUseServiceVm(boolean _useServiceVm) {
this._useServiceVm = _useServiceVm;
}
public boolean useServiceVm() {
return _useServiceVm;
}
public Map<String, TemplateInfo> getDefaultSystemVmTemplateInfo() {
List<VMTemplateVO> tmplts = _tmpltDao.listAllSystemVMTemplates();
Map<String, TemplateInfo> tmpltInfo = new HashMap<String, TemplateInfo>();
if (tmplts != null) {
for (VMTemplateVO tmplt : tmplts) {
TemplateInfo routingInfo = new TemplateInfo(tmplt.getUniqueName(), TemplateConstants.DEFAULT_SYSTEM_VM_TEMPLATE_PATH + tmplt.getId() + File.separator, false, false);
tmpltInfo.put(tmplt.getUniqueName(), routingInfo);
}
}
return tmpltInfo;
}
@Override
public void setName(String name) {
// TODO Auto-generated method stub
}
@Override
public void setConfigParams(Map<String, Object> params) {
// TODO Auto-generated method stub
}
@Override
public Map<String, Object> getConfigParams() {
// TODO Auto-generated method stub
return null;
}
@Override
public int getRunLevel() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void setRunLevel(int level) {
// TODO Auto-generated method stub
}
}