mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
replace spring injection in nfssecondarystorage
This commit is contained in:
parent
593b60ca51
commit
1283712d93
@ -1494,10 +1494,14 @@ SecondaryStorageResource {
|
||||
|
||||
try {
|
||||
Class<?> clazz = Class.forName(value);
|
||||
_storage = (StorageLayer)ComponentContext.inject(clazz);
|
||||
_storage = (StorageLayer)clazz.newInstance();
|
||||
_storage.configure("StorageLayer", params);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new ConfigurationException("Unable to find class " + value);
|
||||
} catch (InstantiationException e) {
|
||||
throw new ConfigurationException("Unable to find class " + value);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new ConfigurationException("Unable to find class " + value);
|
||||
}
|
||||
}
|
||||
_storage.mkdirs(_parent);
|
||||
|
||||
@ -90,9 +90,9 @@ public class TemplateObject implements TemplateInfo {
|
||||
} else {
|
||||
ObjectInDataStoreVO obj = ojbectInStoreMgr.findObject(this.imageVO.getId(), DataObjectType.TEMPLATE, this.dataStore.getId(), this.dataStore.getRole());
|
||||
if (obj.getState() != ObjectInDataStoreStateMachine.State.Ready) {
|
||||
return this.dataStore.getUri() + File.separator + "?type=" + DataObjectType.TEMPLATE + "&size=" + this.imageVO.getSize();
|
||||
return this.dataStore.getUri() + File.separator + "&objType=" + DataObjectType.TEMPLATE + "&size=" + this.imageVO.getSize();
|
||||
} else {
|
||||
return this.dataStore.getUri() + File.separator + "?type=" + DataObjectType.TEMPLATE + "&path=" + obj.getInstallPath();
|
||||
return this.dataStore.getUri() + File.separator + "&objType=" + DataObjectType.TEMPLATE + "&path=" + obj.getInstallPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* 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.command;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
public class CreateVolumeCommand extends Command implements StorageSubSystemCommand {
|
||||
protected String volumeUri;
|
||||
|
||||
public CreateVolumeCommand(String volumeUri) {
|
||||
super();
|
||||
this.volumeUri = volumeUri;
|
||||
}
|
||||
|
||||
protected CreateVolumeCommand() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getVolume() {
|
||||
return this.volumeUri;
|
||||
}
|
||||
|
||||
}
|
||||
@ -39,6 +39,7 @@ import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@Component
|
||||
public class DefaultEndPointSelector implements EndPointSelector {
|
||||
@ -48,6 +49,8 @@ public class DefaultEndPointSelector implements EndPointSelector {
|
||||
HostDao hostDao;
|
||||
private String findOneHostInaScope = "select id from host where "
|
||||
+ " status == 'Up' and hypervisor_type != 'VMware' and type in ('Routing', 'SecondaryStorageVM') ";
|
||||
private String findOneHostOnPrimaryStorage = "select id from host where"
|
||||
+ "status == 'Up' and type == 'Routing' ";
|
||||
|
||||
protected boolean moveBetweenPrimaryImage(DataStore srcStore,
|
||||
DataStore destStore) {
|
||||
@ -62,9 +65,9 @@ public class DefaultEndPointSelector implements EndPointSelector {
|
||||
}
|
||||
|
||||
@DB
|
||||
protected EndPoint findEndPointInScope(Scope scope) {
|
||||
protected EndPoint findEndPointInScope(Scope scope, String sqlBase) {
|
||||
StringBuilder sbuilder = new StringBuilder();
|
||||
sbuilder.append(findOneHostInaScope);
|
||||
sbuilder.append(sqlBase);
|
||||
|
||||
if (scope.getScopeType() == ScopeType.HOST) {
|
||||
sbuilder.append(" and id = ");
|
||||
@ -76,7 +79,7 @@ public class DefaultEndPointSelector implements EndPointSelector {
|
||||
sbuilder.append(" and data_center_id = ");
|
||||
sbuilder.append(scope.getScopeId());
|
||||
}
|
||||
|
||||
//TODO: order by rand() is slow if there are lot of hosts
|
||||
sbuilder.append(" ORDER by rand() limit 1");
|
||||
String sql = sbuilder.toString();
|
||||
PreparedStatement pstmt = null;
|
||||
@ -129,7 +132,7 @@ public class DefaultEndPointSelector implements EndPointSelector {
|
||||
// if both are zone scope
|
||||
selectedScope = srcScope;
|
||||
}
|
||||
return findEndPointInScope(selectedScope);
|
||||
return findEndPointInScope(selectedScope, findOneHostInaScope);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -146,4 +149,19 @@ public class DefaultEndPointSelector implements EndPointSelector {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
protected EndPoint findEndpointForPrimaryStorage(DataStore store) {
|
||||
return findEndPointInScope(store.getScope(), findOneHostOnPrimaryStorage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EndPoint select(DataObject object) {
|
||||
DataStore store = object.getDataStore();
|
||||
if (store.getRole() == DataStoreRole.Primary) {
|
||||
return findEndpointForPrimaryStorage(store);
|
||||
} else {
|
||||
throw new CloudRuntimeException("not implemented yet");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,4 +23,10 @@ import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
|
||||
public interface EndPointSelector {
|
||||
public EndPoint select(DataObject srcData, DataObject destData);
|
||||
|
||||
/**
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
EndPoint select(DataObject object);
|
||||
}
|
||||
|
||||
@ -16,9 +16,10 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.datastore.driver;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult;
|
||||
@ -28,10 +29,10 @@ import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
import org.apache.cloudstack.framework.async.AsyncRpcConext;
|
||||
import org.apache.cloudstack.storage.command.CreateObjectCommand;
|
||||
import org.apache.cloudstack.storage.command.CreateVolumeAnswer;
|
||||
import org.apache.cloudstack.storage.command.CreateVolumeCommand;
|
||||
import org.apache.cloudstack.storage.command.DeleteCommand;
|
||||
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
|
||||
import org.apache.cloudstack.storage.endpoint.EndPointSelector;
|
||||
import org.apache.cloudstack.storage.snapshot.SnapshotInfo;
|
||||
import org.apache.cloudstack.storage.volume.PrimaryDataStoreDriver;
|
||||
import org.apache.log4j.Logger;
|
||||
@ -41,11 +42,9 @@ import com.cloud.agent.api.Answer;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Inject
|
||||
EndPointSelector selector;
|
||||
|
||||
public DefaultPrimaryDataStoreDriverImpl() {
|
||||
|
||||
}
|
||||
@ -83,8 +82,8 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
|
||||
@Override
|
||||
public void deleteAsync(DataObject vo, AsyncCompletionCallback<CommandResult> callback) {
|
||||
DeleteCommand cmd = new DeleteCommand(vo.getUri());
|
||||
List<EndPoint> endPoints = null;
|
||||
EndPoint ep = endPoints.get(0);
|
||||
|
||||
EndPoint ep = selector.select(vo);
|
||||
AsyncRpcConext<CommandResult> context = new AsyncRpcConext<CommandResult>(callback);
|
||||
AsyncCallbackDispatcher<DefaultPrimaryDataStoreDriverImpl, Answer> caller = AsyncCallbackDispatcher.create(this);
|
||||
caller.setCallback(caller.getTarget().deleteCallback(null, null))
|
||||
@ -153,9 +152,8 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
|
||||
@Override
|
||||
public void createAsync(DataObject vol,
|
||||
AsyncCompletionCallback<CreateCmdResult> callback) {
|
||||
List<EndPoint> endPoints = null;
|
||||
EndPoint ep = endPoints.get(0);
|
||||
CreateVolumeCommand createCmd = new CreateVolumeCommand(vol.getUri());
|
||||
EndPoint ep = selector.select(vol);
|
||||
CreateObjectCommand createCmd = new CreateObjectCommand(vol.getUri());
|
||||
|
||||
CreateVolumeContext<CommandResult> context = null;
|
||||
AsyncCallbackDispatcher<DefaultPrimaryDataStoreDriverImpl, Answer> caller = AsyncCallbackDispatcher.create(this);
|
||||
@ -163,7 +161,6 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
|
||||
.setCallback(caller.getTarget().createAsyncCallback(null, null));
|
||||
|
||||
ep.sendMessageAsync(createCmd, caller);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -33,7 +33,7 @@ import org.apache.cloudstack.storage.command.CopyCmd;
|
||||
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
|
||||
import org.apache.cloudstack.storage.command.CreatePrimaryDataStoreCmd;
|
||||
import org.apache.cloudstack.storage.command.CreateVolumeAnswer;
|
||||
import org.apache.cloudstack.storage.command.CreateVolumeCommand;
|
||||
import org.apache.cloudstack.storage.command.CreateObjectCommand;
|
||||
import org.apache.cloudstack.storage.command.CreateVolumeFromBaseImageCommand;
|
||||
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
|
||||
import org.apache.cloudstack.storage.datastore.protocol.DataStoreProtocol;
|
||||
@ -82,8 +82,8 @@ public class XenServerStorageResource {
|
||||
return execute((CreatePrimaryDataStoreCmd) command);
|
||||
} else if (command instanceof CreateVolumeFromBaseImageCommand) {
|
||||
return execute((CreateVolumeFromBaseImageCommand)command);
|
||||
} else if (command instanceof CreateVolumeCommand) {
|
||||
return execute((CreateVolumeCommand) command);
|
||||
} else if (command instanceof CreateObjectCommand) {
|
||||
return execute((CreateObjectCommand) command);
|
||||
} else if (command instanceof DeleteVolumeCommand) {
|
||||
return execute((DeleteVolumeCommand)command);
|
||||
}
|
||||
@ -114,7 +114,7 @@ public class XenServerStorageResource {
|
||||
vdi.destroy(conn);
|
||||
}
|
||||
|
||||
protected CreateVolumeAnswer execute(CreateVolumeCommand cmd) {
|
||||
protected CreateVolumeAnswer execute(CreateObjectCommand cmd) {
|
||||
VolumeTO volume = null;
|
||||
PrimaryDataStoreTO primaryDataStore = volume.getDataStore();
|
||||
Connection conn = hypervisorResource.getConnection();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user