add lifecycle on primarydatastore

This commit is contained in:
Edison Su 2012-12-06 19:01:06 -08:00
parent 57c9b4c6b1
commit ae59bf6c3b
27 changed files with 388 additions and 132 deletions

View File

@ -1,13 +0,0 @@
package org.apache.cloudstack.engine.subsystem.api.storage;
public interface DataStoreLifeCycle {
public enum DataStoreEvent {
HOSTUP,
HOSTDOWN,
}
void add();
void delete();
void enable();
void disable();
void processEvent(DataStoreEvent event, Object... objs);
}

View File

@ -38,4 +38,6 @@ public interface PrimaryDataStoreInfo {
public State getManagedState();
public String getName();
public String getType();
public PrimaryDataStoreLifeCycle getLifeCycle();
PrimaryDataStoreProvider getProvider();
}

View File

@ -16,24 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.storage.datastore.lifecycle;
package org.apache.cloudstack.engine.subsystem.api.storage;
import java.util.Map;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
public interface PrimaryDataStoreLifeCycle {
public PrimaryDataStoreInfo registerDataStore(Map<String, String> dsInfos);
public boolean initialize(Map<String, String> dsInfos);
public boolean attach(long scope);
public boolean attach(Scope scope);
public boolean dettach(long dataStoreId);
public boolean dettach();
public boolean unmanaged(long dataStoreId);
public boolean unmanaged();
public boolean maintain(long dataStoreId);
public boolean maintain();
public boolean cancelMaintain(long dataStoreId);
public boolean cancelMaintain();
public boolean deleteDataStore(long dataStoreId);
public boolean deleteDataStore();
}

View File

@ -0,0 +1,18 @@
package org.apache.cloudstack.engine.subsystem.api.storage;
import java.util.Map;
public interface PrimaryDataStoreProvider {
public PrimaryDataStoreInfo getDataStore(long dataStoreId);
public long getId();
public String getName();
/**
* @param dsInfos
* @return
*/
PrimaryDataStoreInfo registerDataStore(Map<String, String> dsInfos);
//LifeCycle of provider
public boolean configure();
}

View File

@ -0,0 +1,24 @@
/*
* 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 org.apache.cloudstack.engine.subsystem.api.storage;
public interface Scope {
public ScopeType getScopeType();
public long getScopeId();
}

View File

@ -0,0 +1,25 @@
/*
* 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 org.apache.cloudstack.engine.subsystem.api.storage;
public enum ScopeType {
HOST,
CLUSTER,
ZONE;
}

View File

@ -35,6 +35,8 @@ import javax.naming.ConfigurationException;
import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.QCOW2;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VHD;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VMDK;
@ -47,9 +49,7 @@ import org.apache.cloudstack.storage.command.CreateVolumeFromBaseImageCommand;
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStore;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle;
import org.apache.cloudstack.storage.datastore.provider.DefaultPrimaryDatastoreProviderImpl;
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProvider;
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProviderManager;
import org.apache.cloudstack.storage.image.ImageService;
import org.apache.cloudstack.storage.image.db.ImageDataDao;

View File

@ -49,5 +49,4 @@ public interface PrimaryDataStore extends PrimaryDataStoreInfo {
boolean installTemplate(TemplateOnPrimaryDataStoreInfo template);
VolumeDiskType getDefaultDiskType();
}

View File

@ -0,0 +1,42 @@
/*
* 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 org.apache.cloudstack.storage.scope;
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType;
public class ClusterScope implements Scope {
private ScopeType type = ScopeType.CLUSTER;
private long clusterId;
public ClusterScope(long clusterId) {
this.clusterId = clusterId;
}
@Override
public ScopeType getScopeType() {
return this.type;
}
@Override
public long getScopeId() {
return this.clusterId;
}
}

View File

@ -0,0 +1,39 @@
/*
* 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 org.apache.cloudstack.storage.scope;
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType;
public class HostScope implements Scope {
private ScopeType type = ScopeType.HOST;
private long hostId;
public HostScope(long hostId) {
this.hostId = hostId;
}
@Override
public ScopeType getScopeType() {
return this.type;
}
@Override
public long getScopeId() {
return this.hostId;
}
}

View File

@ -0,0 +1,42 @@
/*
* 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 org.apache.cloudstack.storage.scope;
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType;
public class ZoneScope implements Scope {
private ScopeType type = ScopeType.ZONE;
private long zoneId;
public ZoneScope(long zoneId) {
this.zoneId = zoneId;
}
@Override
public ScopeType getScopeType() {
return this.type;
}
@Override
public long getScopeId() {
return this.zoneId;
}
}

View File

@ -19,5 +19,5 @@
package org.apache.cloudstack.storage.datastore;
public enum DataStoreStatus {
Creating, Up, PrepareForMaintenance, ErrorInMaintenance, CancelMaintenance, Maintenance, Removed;
Initial, Initialized, Creating, Up, PrepareForMaintenance, ErrorInMaintenance, CancelMaintenance, Maintenance, Removed;
}

View File

@ -8,10 +8,13 @@ import javax.inject.Inject;
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
import org.apache.cloudstack.storage.HypervisorHostEndPoint;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
import org.apache.cloudstack.storage.datastore.driver.DefaultPrimaryDataStoreDriverImpl;
import org.apache.cloudstack.storage.datastore.driver.PrimaryDataStoreDriver;
import org.apache.cloudstack.storage.image.TemplateInfo;
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
@ -33,6 +36,7 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
protected PrimaryDataStoreDriver driver;
protected PrimaryDataStoreVO pdsv;
protected PrimaryDataStoreInfo pdsInfo;
protected PrimaryDataStoreLifeCycle lifeCycle;
@Inject
private VolumeDao volumeDao;
@Inject
@ -40,14 +44,20 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
@Inject
TemplatePrimaryDataStoreManager templatePrimaryStoreMgr;
private DefaultPrimaryDataStore(PrimaryDataStoreDriver driver, PrimaryDataStoreVO pdsv, PrimaryDataStoreInfo pdsInfo) {
this.driver = driver;
private DefaultPrimaryDataStore(PrimaryDataStoreVO pdsv) {
this.pdsv = pdsv;
this.pdsInfo = pdsInfo;
}
public static DefaultPrimaryDataStore createDataStore(PrimaryDataStoreDriver driver, PrimaryDataStoreVO pdsv, PrimaryDataStoreInfo pdsInfo) {
DefaultPrimaryDataStore dataStore = new DefaultPrimaryDataStore(driver, pdsv, pdsInfo);
public void setDriver(PrimaryDataStoreDriver driver) {
this.driver = driver;
}
public void setLifeCycle(PrimaryDataStoreLifeCycle lifeCycle) {
this.lifeCycle = lifeCycle;
}
public static DefaultPrimaryDataStore createDataStore(PrimaryDataStoreVO pdsv) {
DefaultPrimaryDataStore dataStore = new DefaultPrimaryDataStore(pdsv);
return ComponentInject.inject(dataStore);
}
@ -120,7 +130,7 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
@Override
public VolumeObject createVolume(VolumeInfo vi, VolumeDiskType diskType) {
if (!pdsInfo.isVolumeDiskTypeSupported(diskType)) {
if (!isVolumeDiskTypeSupported(diskType)) {
return null;
}
VolumeObject vo = (VolumeObject) vi;
@ -193,4 +203,16 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
// TODO Auto-generated method stub
return null;
}
@Override
public PrimaryDataStoreLifeCycle getLifeCycle() {
// TODO Auto-generated method stub
return null;
}
@Override
public PrimaryDataStoreProvider getProvider() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -108,7 +108,7 @@ public class PrimaryDataStoreVO implements Identity {
}
public PrimaryDataStoreVO() {
// TODO Auto-generated constructor stub
this.status = DataStoreStatus.Initial;
}
public String getName() {

View File

@ -1,6 +1,7 @@
package org.apache.cloudstack.storage.datastore.driver;
import java.util.List;
import java.util.Map;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
@ -8,6 +9,7 @@ import org.apache.cloudstack.storage.command.CreateVolumeAnswer;
import org.apache.cloudstack.storage.command.CreateVolumeCommand;
import org.apache.cloudstack.storage.command.CreateVolumeFromBaseImageCommand;
import org.apache.cloudstack.storage.command.DeleteVolume;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO;
import org.apache.cloudstack.storage.to.VolumeTO;
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
@ -19,10 +21,13 @@ import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.utils.exception.CloudRuntimeException;
@Component
public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver {
private static final Logger s_logger = Logger.getLogger(DefaultPrimaryDataStoreDriverImpl.class);
protected PrimaryDataStore dataStore;
public DefaultPrimaryDataStoreDriverImpl(PrimaryDataStore dataStore) {
this.dataStore = dataStore;
}
@Override
public boolean createVolume(VolumeObject vol) {
// The default driver will send createvolume command to one of hosts
@ -110,4 +115,22 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean initialize(Map<String, String> params) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean grantAccess(EndPoint ep) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean revokeAccess(EndPoint ep) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -1,5 +1,7 @@
package org.apache.cloudstack.storage.datastore.driver;
import java.util.Map;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
import org.apache.cloudstack.storage.volume.VolumeObject;
@ -18,4 +20,11 @@ public interface PrimaryDataStoreDriver {
long getCapacity();
long getAvailableCapacity();
//Lifecycle API
boolean initialize(Map<String, String> params);
boolean grantAccess(EndPoint ep);
boolean revokeAccess(EndPoint ep);
}

View File

@ -25,18 +25,23 @@ import java.util.Map;
import javax.inject.Inject;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType;
import org.apache.cloudstack.storage.datastore.DataStoreStatus;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProvider;
import org.springframework.stereotype.Component;
public class DefaultPrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLifeCycle {
private final PrimaryDataStoreProvider provider;
protected PrimaryDataStoreInfo dataStore;
protected PrimaryDataStoreDao dataStoreDao;
public DefaultPrimaryDataStoreLifeCycleImpl(PrimaryDataStoreProvider provider, PrimaryDataStoreDao dataStoreDao) {
this.provider = provider;
public DefaultPrimaryDataStoreLifeCycleImpl(PrimaryDataStoreDao dataStoreDao, PrimaryDataStore dataStore) {
this.dataStoreDao = dataStoreDao;
this.dataStore = dataStore;
}
protected class DataStoreUrlParser {
@ -75,54 +80,54 @@ public class DefaultPrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLif
}
@Override
public PrimaryDataStoreInfo registerDataStore(Map<String, String> dsInfos) {
public boolean initialize(Map<String, String> dsInfos) {
DataStoreUrlParser parser = new DataStoreUrlParser(dsInfos.get("url"));
PrimaryDataStoreVO dataStore = new PrimaryDataStoreVO();
PrimaryDataStoreVO dataStore = dataStoreDao.findById(this.dataStore.getId());
dataStore.setName(dsInfos.get("name"));
dataStore.setPoolType(parser.getSchema());
dataStore.setPort(parser.port);
dataStore.setDataCenterId(Integer.parseInt(dsInfos.get("dcId")));
dataStore.setHostAddress(parser.getHost());
dataStore.setPath(parser.getPath());
dataStore.setStorageProviderId(this.provider.getId());
dataStore.setClusterId(Long.parseLong(dsInfos.get("clusterId")));
dataStore = dataStoreDao.persist(dataStore);
dataStore.setStatus(DataStoreStatus.Initialized);
dataStoreDao.update(this.dataStore.getId(), dataStore);
//TODO: add extension point for each data store
return this.provider.getDataStore(dataStore.getId());
this.dataStore = this.dataStore.getProvider().getDataStore(dataStore.getId());
return true;
}
@Override
public boolean attach(long scope) {
public boolean attach(Scope scope) {
//if (scope.getScopeType() == ScopeType.CLUSTER)
return false;
}
@Override
public boolean dettach() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean dettach(long dataStoreId) {
public boolean unmanaged() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean unmanaged(long dataStoreId) {
public boolean maintain() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean maintain(long dataStoreId) {
public boolean cancelMaintain() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean cancelMaintain(long dataStoreId) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean deleteDataStore(long dataStoreId) {
public boolean deleteDataStore() {
// TODO Auto-generated method stub
return false;
}

View File

@ -20,12 +20,13 @@ package org.apache.cloudstack.storage.datastore.manager;
import javax.inject.Inject;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderDao;
import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle;
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProvider;
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProviderManager;
import org.springframework.stereotype.Component;
@ -43,14 +44,7 @@ public class DefaultPrimaryDataStoreManagerImpl implements PrimaryDataStoreManag
PrimaryDataStoreVO dataStoreVO = dataStoreDao.findById(dataStoreId);
Long providerId = dataStoreVO.getStorageProviderId();
PrimaryDataStoreProvider provider = providerManager.getDataStoreProvider(providerId);
PrimaryDataStore dataStore = provider.getDataStore(dataStoreId);
PrimaryDataStore dataStore = (PrimaryDataStore)provider.getDataStore(dataStoreId);
return dataStore;
}
@Override
public PrimaryDataStoreLifeCycle getPrimaryDataStoreLifeCycle(long dataStoreId) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -18,11 +18,10 @@
*/
package org.apache.cloudstack.storage.datastore.manager;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle;
public interface PrimaryDataStoreManager {
public PrimaryDataStore getPrimaryDataStore(long dataStoreId);
public PrimaryDataStoreLifeCycle getPrimaryDataStoreLifeCycle(long dataStoreId);
}

View File

@ -4,29 +4,31 @@ import java.util.Map;
import javax.inject.Inject;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStore;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderVO;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.driver.DefaultPrimaryDataStoreDriverImpl;
import org.apache.cloudstack.storage.datastore.driver.PrimaryDataStoreDriver;
import org.apache.cloudstack.storage.datastore.lifecycle.DefaultPrimaryDataStoreLifeCycleImpl;
import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle;
import org.springframework.stereotype.Component;
@Component
public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProvider {
private final String providerName = "default primary data store provider";
protected PrimaryDataStoreDriver driver;
private PrimaryDataStoreProviderVO provider;
private PrimaryDataStoreProviderVO providerVO;
@Inject
protected PrimaryDataStoreDao dataStoreDao;
protected PrimaryDataStoreLifeCycle dataStoreLifeCycle;
@Inject
protected PrimaryDataStoreProviderDao providerDao;
public DefaultPrimaryDatastoreProviderImpl() {
this.driver = new DefaultPrimaryDataStoreDriverImpl();
this.dataStoreLifeCycle = new DefaultPrimaryDataStoreLifeCycleImpl(this, dataStoreDao);
}
@Override
@ -36,29 +38,37 @@ public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProv
return null;
}
PrimaryDataStore pds = DefaultPrimaryDataStore.createDataStore(driver, dsv, null);
DefaultPrimaryDataStore pds = DefaultPrimaryDataStore.createDataStore(dsv);
PrimaryDataStoreDriver driver = new DefaultPrimaryDataStoreDriverImpl(pds);
pds.setDriver(driver);
DefaultPrimaryDataStoreLifeCycleImpl lifeCycle = new DefaultPrimaryDataStoreLifeCycleImpl(dataStoreDao, pds);
pds.setLifeCycle(lifeCycle);
return pds;
}
@Override
public PrimaryDataStoreLifeCycle getDataStoreLifeCycle() {
return dataStoreLifeCycle;
public PrimaryDataStore registerDataStore(Map<String, String> dsInfos) {
PrimaryDataStoreVO dataStoreVO = new PrimaryDataStoreVO();
dataStoreVO.setStorageProviderId(this.getId());
dataStoreVO = dataStoreDao.persist(dataStoreVO);
PrimaryDataStore dataStore = this.getDataStore(dataStoreVO.getId());
PrimaryDataStoreLifeCycle lifeCycle = dataStore.getLifeCycle();
lifeCycle.initialize(dsInfos);
return getDataStore(dataStore.getId());
}
@Override
public long getId() {
return this.provider.getId();
return this.providerVO.getId();
}
@Override
public boolean register(PrimaryDataStoreProviderVO provider, Map<String, Object> params) {
this.provider = provider;
return true;
}
@Override
public boolean init(PrimaryDataStoreProviderVO provider) {
this.provider = provider;
public boolean configure() {
this.providerVO = providerDao.findByName(this.providerName);
return true;
}

View File

@ -1,17 +0,0 @@
package org.apache.cloudstack.storage.datastore.provider;
import java.util.Map;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderVO;
import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle;
public interface PrimaryDataStoreProvider {
public PrimaryDataStore getDataStore(long dataStoreId);
public PrimaryDataStoreLifeCycle getDataStoreLifeCycle();
public long getId();
public String getName();
public boolean register(PrimaryDataStoreProviderVO provider, Map<String, Object> params);
public boolean init(PrimaryDataStoreProviderVO provider);
}

View File

@ -2,6 +2,8 @@ package org.apache.cloudstack.storage.datastore.provider;
import java.util.List;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
import com.cloud.utils.component.Manager;
public interface PrimaryDataStoreProviderManager extends Manager {

View File

@ -24,6 +24,7 @@ import java.util.Map;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderVO;
import org.springframework.stereotype.Component;
@ -60,10 +61,9 @@ public class PrimaryDataStoreProviderManagerImpl implements PrimaryDataStoreProv
PrimaryDataStoreProviderVO dataStoreProvider = new PrimaryDataStoreProviderVO();
dataStoreProvider.setName(provider.getName());
dataStoreProvider = providerDao.persist(dataStoreProvider);
provider.register(dataStoreProvider, params);
}
PrimaryDataStoreProviderVO providervo = providerDao.findByName(provider.getName());
provider.init(providervo);
provider.configure();
}
return true;
}

View File

@ -72,23 +72,35 @@ public class TemplatePrimaryDataStoreManagerImpl implements TemplatePrimaryDataS
retries--;
} while (retries > 0);
if (templateStoreVO == null) {
throw new CloudRuntimeException("waiting too long for template downloading, marked it as failed");
}
return templateStoreVO;
}
@Override
public TemplateOnPrimaryDataStoreObject createTemplateOnPrimaryDataStore(TemplateInfo template, PrimaryDataStoreInfo dataStore) {
TemplatePrimaryDataStoreVO templateStoreVO = new TemplatePrimaryDataStoreVO(dataStore.getId(), template.getId());
try {
templateStoreVO = templateStoreDao.persist(templateStoreVO);
} catch (Throwable th) {
templateStoreVO = templateStoreDao.findByTemplateIdAndPoolId(template.getId(), dataStore.getId());
if (templateStoreVO != null) {
templateStoreVO = waitingForTemplateDownload(template, dataStore);
} else {
throw new CloudRuntimeException("Failed create db entry: " + th.toString());
TemplatePrimaryDataStoreVO templateStoreVO = null;
boolean freshNewTemplate = false;
templateStoreVO = templateStoreDao.findByTemplateIdAndPoolId(template.getId(), dataStore.getId());
if (templateStoreVO == null) {
try {
templateStoreVO = new TemplatePrimaryDataStoreVO(dataStore.getId(), template.getId());
templateStoreVO = templateStoreDao.persist(templateStoreVO);
freshNewTemplate = true;
} catch (Throwable th) {
templateStoreVO = templateStoreDao.findByTemplateIdAndPoolId(template.getId(), dataStore.getId());
if (templateStoreVO == null) {
throw new CloudRuntimeException("Failed create db entry: " + th.toString());
}
}
}
//If it's not a fresh template downloading, waiting for other people downloading finished.
if (!freshNewTemplate && templateStoreVO.getState() != TemplateOnPrimaryDataStoreStateMachine.State.Ready) {
templateStoreVO = waitingForTemplateDownload(template, dataStore);
}
TemplateOnPrimaryDataStoreObject templateStoreObject = new TemplateOnPrimaryDataStoreObject(dataStore, template, templateStoreVO, templateStoreDao, this);
return templateStoreObject;
}

View File

@ -1,5 +1,7 @@
package org.apache.cloudstack.storage.datastore.driver;
import java.util.Map;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
import org.apache.cloudstack.storage.volume.VolumeObject;
@ -49,4 +51,22 @@ public class SolidfirePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
return 0;
}
@Override
public boolean initialize(Map<String, String> params) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean grantAccess(EndPoint ep) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean revokeAccess(EndPoint ep) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -1,24 +1,21 @@
package org.apache.cloudstack.storage.datastore.provider;
import javax.inject.Inject;
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStore;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
import org.apache.cloudstack.storage.datastore.driver.SolidfirePrimaryDataStoreDriver;
import org.apache.cloudstack.storage.datastore.lifecycle.DefaultPrimaryDataStoreLifeCycleImpl;
import org.springframework.stereotype.Component;
@Component
public class SolidfirePrimaryDataStoreProvider extends
DefaultPrimaryDatastoreProviderImpl {
private final String name = "Solidfre Primary Data Store Provider";
private SolidfirePrimaryDataStoreDriver driver;
@Inject
public SolidfirePrimaryDataStoreProvider(PrimaryDataStoreDao dataStoreDao) {
super(dataStoreDao);
driver = new SolidfirePrimaryDataStoreDriver();
public SolidfirePrimaryDataStoreProvider() {
super();
// TODO Auto-generated constructor stub
}
@ -34,7 +31,12 @@ public class SolidfirePrimaryDataStoreProvider extends
return null;
}
PrimaryDataStore pds = DefaultPrimaryDataStore.createDataStore(driver, dsv, null);
DefaultPrimaryDataStore pds = DefaultPrimaryDataStore.createDataStore(dsv);
SolidfirePrimaryDataStoreDriver driver = new SolidfirePrimaryDataStoreDriver();
pds.setDriver(driver);
DefaultPrimaryDataStoreLifeCycleImpl lifeCycle = new DefaultPrimaryDataStoreLifeCycleImpl(super.dataStoreDao, pds);
pds.setLifeCycle(lifeCycle);
return pds;
}
}

View File

@ -12,11 +12,11 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
import org.apache.cloudstack.storage.command.CreateVolumeAnswer;
import org.apache.cloudstack.storage.command.CreateVolumeFromBaseImageCommand;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle;
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProvider;
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProviderManager;
import org.junit.Before;
import org.junit.Test;
@ -120,13 +120,12 @@ public class VolumeTest {
try {
primaryDataStoreProviderMgr.configure("primary data store mgr", new HashMap<String, Object>());
PrimaryDataStoreProvider provider = primaryDataStoreProviderMgr.getDataStoreProvider("Solidfre Primary Data Store Provider");
PrimaryDataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
Map<String, String> params = new HashMap<String, String>();
params.put("url", "nfs://test/test");
params.put("dcId", dcId.toString());
params.put("clusterId", clusterId.toString());
params.put("name", "my primary data store");
PrimaryDataStoreInfo primaryDataStoreInfo = lifeCycle.registerDataStore(params);
PrimaryDataStoreInfo primaryDataStoreInfo = provider.registerDataStore(params);
return primaryDataStoreInfo;
} catch (ConfigurationException e) {
return null;