mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 10:32:34 +01:00
Revive simulator based on ImageStore changes
Introduced the SimulatorStorageProcessor to handle image store related commands. Right now only mock implementations are provided, no error handling, logging, runtime exception scenarios limited. SystemVMs are able to start up but the default built-in template has trouble in going to Ready state. Signed-off-by: Prasanna Santhanam <tsp@apache.org>
This commit is contained in:
parent
82c75c7fae
commit
d08a6a4e7b
@ -16,20 +16,6 @@
|
||||
// under the License.
|
||||
package com.cloud.agent.manager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import org.apache.cloudstack.storage.command.DeleteCommand;
|
||||
import org.apache.cloudstack.storage.command.DownloadCommand;
|
||||
import org.apache.cloudstack.storage.command.DownloadProgressCommand;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.AttachIsoCommand;
|
||||
import com.cloud.agent.api.AttachVolumeCommand;
|
||||
@ -100,18 +86,32 @@ import com.cloud.agent.api.storage.DestroyCommand;
|
||||
import com.cloud.agent.api.storage.ListTemplateCommand;
|
||||
import com.cloud.agent.api.storage.ListVolumeCommand;
|
||||
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
|
||||
import com.cloud.resource.SimulatorStorageProcessor;
|
||||
import com.cloud.simulator.MockConfigurationVO;
|
||||
import com.cloud.simulator.MockHost;
|
||||
import com.cloud.simulator.MockVMVO;
|
||||
import com.cloud.simulator.dao.MockConfigurationDao;
|
||||
import com.cloud.simulator.dao.MockHostDao;
|
||||
import com.cloud.storage.resource.StorageSubsystemCommandHandler;
|
||||
import com.cloud.storage.resource.StorageSubsystemCommandHandlerBase;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.db.ConnectionConcierge;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import org.apache.cloudstack.storage.command.DeleteCommand;
|
||||
import org.apache.cloudstack.storage.command.DownloadCommand;
|
||||
import org.apache.cloudstack.storage.command.DownloadProgressCommand;
|
||||
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@Local(value = { SimulatorManager.class })
|
||||
@ -129,18 +129,12 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage
|
||||
MockConfigurationDao _mockConfigDao;
|
||||
@Inject
|
||||
MockHostDao _mockHost = null;
|
||||
private ConnectionConcierge _concierge;
|
||||
protected StorageSubsystemCommandHandler storageHandler;
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
/*
|
||||
try {
|
||||
Connection conn = Transaction.getStandaloneSimulatorConnection();
|
||||
conn.setAutoCommit(true);
|
||||
_concierge = new ConnectionConcierge("SimulatorConnection", conn, true);
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to get a db connection to simulator", e);
|
||||
}
|
||||
*/
|
||||
SimulatorStorageProcessor processor = new SimulatorStorageProcessor(this);
|
||||
this.storageHandler = new StorageSubsystemCommandHandlerBase(processor);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -356,6 +350,8 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage
|
||||
return _mockVmMgr.scaleVm((ScaleVmCommand) cmd);
|
||||
} else if (cmd instanceof PvlanSetupCommand) {
|
||||
return _mockNetworkMgr.setupPVLAN((PvlanSetupCommand) cmd);
|
||||
} else if (cmd instanceof StorageSubSystemCommand) {
|
||||
return this.storageHandler.handleStorageCommands((StorageSubSystemCommand)cmd);
|
||||
} else {
|
||||
s_logger.error("Simulator does not implement command of type "+cmd.toString());
|
||||
return Answer.createUnsupportedCommandAnswer(cmd);
|
||||
|
||||
@ -16,21 +16,6 @@
|
||||
// under the License.
|
||||
package com.cloud.resource;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
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.IAgentControl;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
@ -46,6 +31,19 @@ import com.cloud.host.Host;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.simulator.MockHost;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class AgentResourceBase implements ServerResource {
|
||||
@ -121,6 +119,7 @@ public class AgentResourceBase implements ServerResource {
|
||||
hostGuid = (String)params.get("guid");
|
||||
|
||||
_simMgr = ComponentContext.inject(SimulatorManagerImpl.class);
|
||||
_simMgr.configure(name, params);
|
||||
|
||||
agentHost = getAgentMgr().getHost(hostGuid);
|
||||
return true;
|
||||
|
||||
@ -0,0 +1,187 @@
|
||||
/*
|
||||
* 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.resource;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.to.DataStoreTO;
|
||||
import com.cloud.agent.api.to.DataTO;
|
||||
import com.cloud.agent.api.to.DiskTO;
|
||||
import com.cloud.agent.api.to.NfsTO;
|
||||
import com.cloud.agent.manager.SimulatorManager;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.resource.StorageProcessor;
|
||||
import org.apache.cloudstack.storage.command.AttachAnswer;
|
||||
import org.apache.cloudstack.storage.command.AttachCommand;
|
||||
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
|
||||
import org.apache.cloudstack.storage.command.CopyCommand;
|
||||
import org.apache.cloudstack.storage.command.CreateObjectAnswer;
|
||||
import org.apache.cloudstack.storage.command.CreateObjectCommand;
|
||||
import org.apache.cloudstack.storage.command.DeleteCommand;
|
||||
import org.apache.cloudstack.storage.command.DettachAnswer;
|
||||
import org.apache.cloudstack.storage.command.DettachCommand;
|
||||
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
|
||||
import org.apache.cloudstack.storage.to.TemplateObjectTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeObjectTO;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SimulatorStorageProcessor implements StorageProcessor {
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(SimulatorStorageProcessor.class);
|
||||
protected SimulatorManager hypervisorResource;
|
||||
|
||||
public SimulatorStorageProcessor(SimulatorManager resource) {
|
||||
this.hypervisorResource = resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
|
||||
TemplateObjectTO template = new TemplateObjectTO();
|
||||
template.setPath(UUID.randomUUID().toString());
|
||||
template.setFormat(Storage.ImageFormat.RAW);
|
||||
return new CopyCmdAnswer(template);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd) {
|
||||
VolumeObjectTO volume = new VolumeObjectTO();
|
||||
volume.setPath(UUID.randomUUID().toString());
|
||||
volume.setFormat(Storage.ImageFormat.RAW);
|
||||
return new CopyCmdAnswer(volume);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer copyVolumeFromPrimaryToSecondary(CopyCommand cmd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer createTemplateFromVolume(CopyCommand cmd) {
|
||||
DataTO destData = cmd.getDestTO();
|
||||
TemplateObjectTO template = new TemplateObjectTO();
|
||||
template.setPath(template.getName());
|
||||
template.setFormat(Storage.ImageFormat.RAW);
|
||||
DataStoreTO imageStore = destData.getDataStore();
|
||||
if (!(imageStore instanceof NfsTO)) {
|
||||
return new CopyCmdAnswer("unsupported protocol");
|
||||
}
|
||||
|
||||
return new CopyCmdAnswer(template);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer backupSnasphot(CopyCommand cmd) {
|
||||
DataTO srcData = cmd.getSrcTO();
|
||||
DataTO destData = cmd.getDestTO();
|
||||
SnapshotObjectTO snapshot = (SnapshotObjectTO) srcData;
|
||||
DataStoreTO imageStore = destData.getDataStore();
|
||||
if (!(imageStore instanceof NfsTO)) {
|
||||
return new CopyCmdAnswer("unsupported protocol");
|
||||
}
|
||||
|
||||
int index = snapshot.getPath().lastIndexOf("/");
|
||||
|
||||
String snapshotName = snapshot.getPath().substring(index + 1);
|
||||
String snapshotRelPath = null;
|
||||
SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
|
||||
newSnapshot.setPath(snapshotRelPath + File.separator + snapshotName);
|
||||
return new CopyCmdAnswer(newSnapshot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer attachIso(AttachCommand cmd) {
|
||||
DiskTO disk = cmd.getDisk();
|
||||
TemplateObjectTO isoTO = (TemplateObjectTO) disk.getData();
|
||||
DataStoreTO store = isoTO.getDataStore();
|
||||
if (!(store instanceof NfsTO)) {
|
||||
return new AttachAnswer("unsupported protocol");
|
||||
}
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer attachVolume(AttachCommand cmd) {
|
||||
DiskTO disk = cmd.getDisk();
|
||||
return new AttachAnswer(disk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer dettachIso(DettachCommand cmd) {
|
||||
DiskTO disk = cmd.getDisk();
|
||||
TemplateObjectTO isoTO = (TemplateObjectTO) disk.getData();
|
||||
DataStoreTO store = isoTO.getDataStore();
|
||||
if (!(store instanceof NfsTO)) {
|
||||
return new AttachAnswer("unsupported protocol");
|
||||
}
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer dettachVolume(DettachCommand cmd) {
|
||||
DiskTO disk = cmd.getDisk();
|
||||
return new DettachAnswer(disk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer createVolume(CreateObjectCommand cmd) {
|
||||
VolumeObjectTO volume = (VolumeObjectTO) cmd.getData();
|
||||
VolumeObjectTO newVol = new VolumeObjectTO();
|
||||
newVol.setPath(volume.getName());
|
||||
return new CreateObjectAnswer(newVol);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer createSnapshot(CreateObjectCommand cmd) {
|
||||
String snapshotName = UUID.randomUUID().toString();
|
||||
SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
|
||||
newSnapshot.setPath(snapshotName);
|
||||
return new CreateObjectAnswer(newSnapshot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer deleteVolume(DeleteCommand cmd) {
|
||||
return new Answer(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer createVolumeFromSnapshot(CopyCommand cmd) {
|
||||
DataTO srcData = cmd.getSrcTO();
|
||||
SnapshotObjectTO snapshot = (SnapshotObjectTO) srcData;
|
||||
String snapshotPath = snapshot.getPath();
|
||||
int index = snapshotPath.lastIndexOf("/");
|
||||
snapshotPath = snapshotPath.substring(0, index);
|
||||
String snapshotName = snapshotPath.substring(index + 1);
|
||||
VolumeObjectTO newVol = new VolumeObjectTO();
|
||||
newVol.setPath(snapshotName);
|
||||
return new CopyCmdAnswer(newVol);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer deleteSnapshot(DeleteCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user