Skip to content

Commit 73cc474

Browse files
committed
add secondary storage provider
1 parent 7d92c1d commit 73cc474

31 files changed

Lines changed: 1010 additions & 372 deletions

platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStore.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.cloud.agent.api.to.StorageFilerTO;
2222
import com.cloud.storage.Snapshot;
2323
import com.cloud.storage.Storage.StoragePoolType;
24+
import com.cloud.storage.TemplateProfile;
2425
import com.cloud.storage.Volume;
2526
import com.cloud.template.VirtualMachineTemplate;
2627

@@ -35,6 +36,7 @@ public class DataStoreDriverRef {
3536

3637
public enum StoreType {
3738
Primary,
39+
Image,
3840
Backup;
3941
}
4042
public class StoreScope {
@@ -55,6 +57,7 @@ public class StoreScope {
5557
boolean isSharedStorage();
5658
Long getId();
5759
DataStoreDriver getDataStoreDriver();
60+
StorageProvider getProvider();
5861
DataStoreEndPointSelector getEndPointSelector();
5962
FileSystem getFileSystem();
6063
VolumeStrategy getVolumeStrategy();
@@ -65,7 +68,7 @@ public class StoreScope {
6568

6669
VolumeProfile prepareVolume(Volume volume, DataStore destStore);
6770
SnapshotProfile prepareSnapshot(Snapshot snapshot, DataStore destStore);
68-
TemplateProfile prepareTemplate(VirtualMachineTemplate template, DataStore destStore);
71+
TemplateProfile prepareTemplate(long templateId, DataStore destStore);
6972
boolean contains(Volume volume);
7073
boolean contains(Snapshot snapshot);
7174
boolean contains(TemplateProfile template);

platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreDriver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020

2121
import com.cloud.agent.api.Answer;
2222
import com.cloud.agent.api.Command;
23+
import com.cloud.storage.TemplateProfile;
2324
import com.cloud.vm.DiskProfile;
2425

2526
public interface DataStoreDriver {
2627
String getDriverType();
2728
TemplateProfile install(TemplateProfile tp, DataStoreEndPoint ep);
29+
TemplateProfile register(TemplateProfile tp, DataStoreEndPoint ep);
2830
DiskProfile createVolumeFromTemplate(DiskProfile volProfile, TemplateProfile tp, DataStoreEndPoint ep);
2931
DataObject create(DataObject obj);
3032
DataObject copy(DataObject src, DataStore dest);

platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageEvent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020

2121
public enum StorageEvent {
2222
DownloadTemplateToPrimary,
23+
RegisterTemplate,
2324
CreateVolumeFromTemplate;
2425
}

platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
public interface StorageProvider extends Adapter {
1313
List<HypervisorType> supportedHypervisors();
1414
String getProviderName();
15-
StoreType supportedStoreType();
15+
List<StoreType> supportedStoreTypes();
1616
void configure(Map<String, String> storeProviderInfo);
1717
DataStore addDataStore(StoragePool sp, String uri, Map<String, String> params);
1818
DataStore getDataStore(StoragePool pool);

platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateProfile.java

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
package org.apache.cloudstack.platform.subsystem.api.storage;
22

3+
import com.cloud.agent.api.storage.DownloadCommand.Proxy;
4+
import com.cloud.storage.TemplateProfile;
5+
36
public interface TemplateStrategy {
47
TemplateProfile install(TemplateProfile tp);
58
TemplateProfile get(long templateId);
9+
TemplateProfile register(TemplateProfile tp);
10+
boolean canRegister(long templateId);
611
int getDownloadWait();
12+
long getMaxTemplateSizeInBytes();
13+
Proxy getHttpProxy();
714
}

platform/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import org.apache.cloudstack.platform.subsystem.api.storage.VolumeProfile;
2929
import org.apache.cloudstack.platform.subsystem.api.storage.VolumeStrategy;
3030
import org.apache.cloudstack.storage.db.VolumeHostVO;
31+
import org.apache.cloudstack.storage.image.ImageManager;
3132
import org.apache.cloudstack.storage.manager.BackupStorageManager;
32-
import org.apache.cloudstack.storage.manager.TemplateManager;
3333
import org.apache.cloudstack.storage.manager.SecondaryStorageManager;
3434
import org.apache.cloudstack.storage.volume.VolumeManager;
3535
import org.apache.log4j.Logger;
@@ -76,7 +76,7 @@ public class StorageOrchestratorImpl implements StorageOrchestrator {
7676
@Inject
7777
SecondaryStorageManager _secondaryStorageMgr;
7878
@Inject
79-
TemplateManager _templateMgr;
79+
ImageManager _templateMgr;
8080
@Inject
8181
VMTemplateDao _templateDao;
8282

@@ -169,9 +169,8 @@ protected Volume createVolumeOnStorage(Volume volume, DataStore destStore, Strin
169169
volume = _volumeMgr.processEvent(volume, Volume.Event.CreateRequested);
170170

171171
if (volume.getTemplateId() != null) {
172-
VirtualMachineTemplate template = _templateDao.findById(volume.getTemplateId());
173172
DataStore ds = _secondaryStorageMgr.getImageStore(destStore);
174-
TemplateProfile tp = ds.prepareTemplate(template, destStore);
173+
TemplateProfile tp = ds.prepareTemplate(volume.getTemplateId(), destStore);
175174
if (!destStore.contains(tp)) {
176175
tp = _templateMgr.AssociateTemplateStoragePool(tp, destStore);
177176
tp = destStore.getTemplateStrategy().install(tp);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
package org.apache.cloudstack.storage.datastoreconfigurator;
20+
21+
import java.util.Map;
22+
23+
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
24+
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
25+
import org.apache.cloudstack.storage.datastore.DefaultDataStore;
26+
import org.apache.cloudstack.storage.driver.DefaultNfsSecondaryDriver;
27+
import org.apache.cloudstack.storage.epselector.DefaultNfsSecondaryEndPointSelector;
28+
29+
import org.apache.cloudstack.storage.lifecycle.DefaultNfsSecondaryLifeCycle;
30+
31+
import org.apache.cloudstack.storage.strategy.DefaultTemplateStratey;
32+
33+
34+
import com.cloud.storage.StoragePool;
35+
36+
public class NfsSecondaryStorageConfigurator extends NfsDataStoreConfigurator {
37+
@Override
38+
public DataStore getDataStore(StoragePool pool) {
39+
DefaultDataStore ds = new DefaultDataStore();
40+
ds.setEndPointSelector(new DefaultNfsSecondaryEndPointSelector(ds));
41+
ds.setId(pool.getId());
42+
ds.setType(StoreType.Image);
43+
ds.setURI(pool.getHostAddress() + "/" + pool.getPath());
44+
ds.setUUID(pool.getUuid());
45+
ds.setDataStoreDriver(new DefaultNfsSecondaryDriver(ds));
46+
ds.setTemplateStrategy(new DefaultTemplateStratey(ds));
47+
ds.setLifeCycle(new DefaultNfsSecondaryLifeCycle(ds));
48+
return ds;
49+
}
50+
public StoragePool getStoragePool(Map<String, String> configs) {
51+
// TODO Auto-generated method stub
52+
return null;
53+
}
54+
55+
}

platform/storage/src/org/apache/cloudstack/storage/driver/AbstractStorageDriver.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@
2323
import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreEndPoint;
2424
import org.apache.cloudstack.platform.subsystem.api.storage.VolumeProfile;
2525

26-
import org.apache.cloudstack.platform.subsystem.api.storage.TemplateProfile;
2726
import org.apache.cloudstack.platform.subsystem.api.storage.TemplateStrategy;
28-
27+
import com.cloud.agent.api.storage.DownloadProgressCommand;
28+
import com.cloud.agent.api.storage.DownloadProgressCommand.RequestType;
2929
import com.cloud.agent.api.Answer;
3030
import com.cloud.agent.api.storage.CreateAnswer;
3131
import com.cloud.agent.api.storage.CreateCommand;
32+
import com.cloud.agent.api.storage.DownloadCommand;
33+
import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
3234
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
3335
import com.cloud.agent.api.to.VolumeTO;
36+
import com.cloud.storage.TemplateProfile;
3437
import com.cloud.vm.DiskProfile;
3538

3639

@@ -45,18 +48,29 @@ public AbstractStorageDriver(DataStore ds) {
4548
}
4649

4750
public TemplateProfile install(TemplateProfile tp, DataStoreEndPoint ep) {
48-
PrimaryStorageDownloadCommand dcmd = new PrimaryStorageDownloadCommand(tp.getUniqueName(), tp.getURI(), tp.getFormat(),
51+
PrimaryStorageDownloadCommand dcmd = new PrimaryStorageDownloadCommand(tp.getName(), tp.getUrl(), tp.getFormat(),
4952
0, _ds.getId(), _ds.getUUID(), _ts.getDownloadWait());
5053
dcmd.setSecondaryStorageUrl(tp.getImageStorageUri());
5154
dcmd.setPrimaryStorageUrl(_ds.getURI());
52-
Answer asw = ep.sendCommand(dcmd);
55+
PrimaryStorageDownloadAnswer asw = (PrimaryStorageDownloadAnswer)ep.sendCommand(dcmd);
5356

54-
TemplateProfile tpn = new TemplateProfile();
55-
tpn.setLocalPath("/mnt/test");
56-
tpn.setTemplatePoolRefId(tp.getTemplatePoolRefId());
57-
return tpn;
57+
tp.setLocalPath(asw.getInstallPath());
58+
return tp;
5859
}
5960

61+
public TemplateProfile register(TemplateProfile tp, DataStoreEndPoint ep, boolean freshDownload) {
62+
63+
DownloadCommand dcmd =
64+
new DownloadCommand(_ds.getURI(), tp.getTemplate(), _ts.getMaxTemplateSizeInBytes());
65+
dcmd.setProxy(_ts.getHttpProxy());
66+
if (!freshDownload) {
67+
dcmd = new DownloadProgressCommand(dcmd, tp.getJobId(), RequestType.GET_OR_RESTART);
68+
}
69+
70+
ep.sendCommand(dcmd);
71+
return tp;
72+
}
73+
6074
public DiskProfile createVolumeFromTemplate(DiskProfile volProfile, TemplateProfile tp, DataStoreEndPoint ep) {
6175
CreateCommand cmd = new CreateCommand(volProfile, tp.getLocalPath(), _ds.getTO());
6276
CreateAnswer ans = (CreateAnswer)ep.sendCommand(cmd);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
package org.apache.cloudstack.storage.driver;
20+
21+
import org.apache.cloudstack.platform.subsystem.api.storage.DataObject;
22+
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
23+
import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreEndPoint;
24+
25+
import com.cloud.agent.api.Answer;
26+
import com.cloud.agent.api.Command;
27+
import com.cloud.storage.TemplateProfile;
28+
29+
public class DefaultNfsSecondaryDriver extends AbstractStorageDriver {
30+
31+
/**
32+
* @param ds
33+
*/
34+
public DefaultNfsSecondaryDriver(DataStore ds) {
35+
super(ds);
36+
// TODO Auto-generated constructor stub
37+
}
38+
39+
public String getDriverType() {
40+
// TODO Auto-generated method stub
41+
return null;
42+
}
43+
44+
public TemplateProfile register(TemplateProfile tp, DataStoreEndPoint ep) {
45+
// TODO Auto-generated method stub
46+
return null;
47+
}
48+
49+
public DataObject create(DataObject obj) {
50+
// TODO Auto-generated method stub
51+
return null;
52+
}
53+
54+
public DataObject copy(DataObject src, DataStore dest) {
55+
// TODO Auto-generated method stub
56+
return null;
57+
}
58+
59+
public DataObject copy(DataObject src, DataObject dest) {
60+
// TODO Auto-generated method stub
61+
return null;
62+
}
63+
64+
public DataObject move(DataObject src, DataObject dest) {
65+
// TODO Auto-generated method stub
66+
return null;
67+
}
68+
69+
public Answer sendMessage(DataStoreEndPoint dsep, Command cmd) {
70+
// TODO Auto-generated method stub
71+
return null;
72+
}
73+
74+
public boolean delete(DataObject obj) {
75+
// TODO Auto-generated method stub
76+
return false;
77+
}
78+
79+
}

0 commit comments

Comments
 (0)