mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-8502
Added CitrixStorageSubSystemCommandWrapper to complete the CitrixResourceBase refactor. - All 101 unit tests are green
This commit is contained in:
parent
3efdc6c356
commit
add4277720
@ -75,6 +75,8 @@ public abstract class RequestWrapper {
|
||||
commandWrapper = resourceCommands.get(commandClass2);
|
||||
|
||||
keepCommandClass = commandClass2;
|
||||
} catch (final ClassCastException e) {
|
||||
throw new NullPointerException("No key found for '" + keepCommandClass.getClass() + "' in the Map!");
|
||||
} catch (final NullPointerException e) {
|
||||
// Will now traverse all the resource hierarchy. Returning null
|
||||
// is not a problem.
|
||||
@ -108,6 +110,8 @@ public abstract class RequestWrapper {
|
||||
keepResourceClass = resourceClass2;
|
||||
|
||||
commandWrapper = retrieveCommands(command.getClass(), resourceCommands2);
|
||||
} catch (final ClassCastException e) {
|
||||
throw new NullPointerException("No key found for '" + command.getClass() + "' in the Map!");
|
||||
} catch (final NullPointerException e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
@ -46,7 +46,6 @@ import javax.naming.ConfigurationException;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
|
||||
import org.apache.cloudstack.storage.to.TemplateObjectTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeObjectTO;
|
||||
import org.apache.log4j.Logger;
|
||||
@ -717,7 +716,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
||||
if (record.isControlDomain || record.isASnapshot || record.isATemplate) {
|
||||
continue; // Skip DOM0
|
||||
}
|
||||
String platform = StringUtils.mapToString(record.platform);
|
||||
final String platform = StringUtils.mapToString(record.platform);
|
||||
if (platform.isEmpty()) {
|
||||
continue; //Skip if platform is null
|
||||
}
|
||||
@ -1642,13 +1641,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
||||
|
||||
@Override
|
||||
public Answer executeRequest(final Command cmd) {
|
||||
|
||||
// We need this one because the StorageSubSystemCommand is from another
|
||||
// hierarchy.
|
||||
if (cmd instanceof StorageSubSystemCommand) {
|
||||
return storageHandler.handleStorageCommands((StorageSubSystemCommand) cmd);
|
||||
}
|
||||
|
||||
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
|
||||
try {
|
||||
return wrapper.execute(cmd, this);
|
||||
@ -2012,6 +2004,10 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
||||
return _migratewait;
|
||||
}
|
||||
|
||||
public StorageSubsystemCommandHandler getStorageHandler() {
|
||||
return storageHandler;
|
||||
}
|
||||
|
||||
protected boolean getHostInfo(final Connection conn) throws IllegalArgumentException {
|
||||
try {
|
||||
final Host myself = Host.getByUuid(conn, _host.getUuid());
|
||||
|
||||
@ -0,0 +1,38 @@
|
||||
//
|
||||
// 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.hypervisor.xenserver.resource.wrapper;
|
||||
|
||||
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
|
||||
import com.cloud.resource.CommandWrapper;
|
||||
import com.cloud.resource.ResourceWrapper;
|
||||
import com.cloud.storage.resource.StorageSubsystemCommandHandler;
|
||||
|
||||
@ResourceWrapper(handles = StorageSubSystemCommand.class)
|
||||
public final class CitrixStorageSubSystemCommandWrapper extends CommandWrapper<StorageSubSystemCommand, Answer, CitrixResourceBase> {
|
||||
|
||||
@Override
|
||||
public Answer execute(final StorageSubSystemCommand command, final CitrixResourceBase citrixResourceBase) {
|
||||
final StorageSubsystemCommandHandler handler = citrixResourceBase.getStorageHandler();
|
||||
return handler.handleStorageCommands(command);
|
||||
}
|
||||
}
|
||||
@ -33,6 +33,8 @@ import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cloudstack.storage.command.AttachAnswer;
|
||||
import org.apache.cloudstack.storage.command.AttachCommand;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.cloudstack.storage.to.VolumeObjectTO;
|
||||
import org.apache.xmlrpc.XmlRpcException;
|
||||
@ -109,6 +111,7 @@ import com.cloud.agent.api.storage.DestroyCommand;
|
||||
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
|
||||
import com.cloud.agent.api.storage.ResizeVolumeCommand;
|
||||
import com.cloud.agent.api.to.DataStoreTO;
|
||||
import com.cloud.agent.api.to.DiskTO;
|
||||
import com.cloud.agent.api.to.IpAddressTO;
|
||||
import com.cloud.agent.api.to.NicTO;
|
||||
import com.cloud.agent.api.to.StorageFilerTO;
|
||||
@ -123,6 +126,7 @@ import com.cloud.network.PhysicalNetworkSetupInfo;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc;
|
||||
import com.cloud.storage.resource.StorageSubsystemCommandHandler;
|
||||
import com.cloud.vm.DiskProfile;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.xensource.xenapi.Connection;
|
||||
@ -1807,6 +1811,24 @@ public class CitrixRequestWrapperTest {
|
||||
// Requires more testing, but the VirtualResourceRouting is quite big.
|
||||
assertNull(answer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStorageSubSystemCommand() {
|
||||
final DiskTO disk = Mockito.mock(DiskTO.class);
|
||||
final String vmName = "Test";
|
||||
final AttachCommand command = new AttachCommand(disk, vmName);
|
||||
|
||||
final StorageSubsystemCommandHandler handler = Mockito.mock(StorageSubsystemCommandHandler.class);
|
||||
when(citrixResourceBase.getStorageHandler()).thenReturn(handler);
|
||||
|
||||
when(handler.handleStorageCommands(command)).thenReturn(new AttachAnswer(disk));
|
||||
|
||||
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
|
||||
assertNotNull(wrapper);
|
||||
|
||||
final Answer answer = wrapper.execute(command, citrixResourceBase);
|
||||
assertTrue(answer.getResult());
|
||||
}
|
||||
}
|
||||
|
||||
class NotAValidCommand extends Command {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user