merge object_store

This commit is contained in:
Edison Su 2013-06-20 00:18:00 -07:00
commit 97f8c524b8
586 changed files with 38513 additions and 26208 deletions

View File

@ -82,6 +82,7 @@ public class AgentShell implements IAgentShell, Daemon {
private int _pingRetries;
private final List<Agent> _agents = new ArrayList<Agent>();
public AgentShell() {
}

View File

@ -23,6 +23,7 @@ public class Answer extends Command {
protected String details;
protected Answer() {
this(null);
}
public Answer(Command command) {

View File

@ -1,3 +1,4 @@
package com.cloud.agent.api.storage;
// 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

View File

@ -16,23 +16,24 @@
// under the License.
package com.cloud.agent.api.storage;
public class DeleteVolumeCommand extends ssCommand {
private String volumePath;
/**
* Password authentication
*/
public class PasswordAuth {
public DeleteVolumeCommand() {
}
String userName;
String password;
public PasswordAuth() {
public DeleteVolumeCommand(String secUrl, String volumePath) {
this.setSecUrl(secUrl);
this.volumePath = volumePath;
}
@Override
public boolean executeInSequence() {
return true;
public PasswordAuth(String user, String password) {
this.userName = user;
this.password = password;
}
public String getUserName() {
return userName;
}
public String getPassword() {
return password;
}
public String getVolumePath() {
return volumePath;
}
}

View File

@ -0,0 +1,72 @@
// 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.agent.api.storage;
import java.net.URI;
/**
* Download Proxy
*/
public class Proxy {
private String _host;
private int _port;
private String _userName;
private String _password;
public Proxy() {
}
public Proxy(String host, int port, String userName, String password) {
this._host = host;
this._port = port;
this._userName = userName;
this._password = password;
}
public Proxy(URI uri) {
this._host = uri.getHost();
this._port = uri.getPort() == -1 ? 3128 : uri.getPort();
String userInfo = uri.getUserInfo();
if (userInfo != null) {
String[] tokens = userInfo.split(":");
if (tokens.length == 1) {
this._userName = userInfo;
this._password = "";
} else if (tokens.length == 2) {
this._userName = tokens[0];
this._password = tokens[1];
}
}
}
public String getHost() {
return _host;
}
public int getPort() {
return _port;
}
public String getUserName() {
return _userName;
}
public String getPassword() {
return _password;
}
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.engine.subsystem.api.storage;
package com.cloud.agent.api.to;
public enum DataObjectType {
VOLUME,

View File

@ -16,9 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.engine.subsystem.api.storage;
package com.cloud.agent.api.to;
import com.cloud.storage.DataStoreRole;
public interface ImageDataStoreProvider extends DataStoreProvider {
public interface DataStoreTO {
public DataStoreRole getRole();
}

View File

@ -16,9 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.storage.image.motion;
package com.cloud.agent.api.to;
import org.apache.cloudstack.storage.motion.DataMotionStrategy;
public interface DataTO {
public DataObjectType getObjectType();
public DataStoreTO getDataStore();
/**
* @return
*/
String getPath();
public interface ImageMotionStrategy extends DataMotionStrategy {
long getId();
}

View File

@ -16,23 +16,45 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.storage.datastore.db;
package com.cloud.agent.api.to;
import org.springframework.stereotype.Component;
import com.cloud.storage.Volume;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchCriteria2;
import com.cloud.utils.db.SearchCriteriaService;
import com.cloud.utils.db.SearchCriteria.Op;
@Component
class DataStoreProviderDaoImpl extends GenericDaoBase<DataStoreProviderVO, Long> implements DataStoreProviderDao {
@Override
public DataStoreProviderVO findByName(String name) {
SearchCriteriaService<DataStoreProviderVO, DataStoreProviderVO> sc = SearchCriteria2.create(DataStoreProviderVO.class);
sc.addAnd(sc.getEntity().getName(), Op.EQ, name);
return sc.find();
public class DiskTO {
private DataTO data;
private Long diskSeq;
private Volume.Type type;
public DiskTO() {
}
public DiskTO(DataTO data, Long diskSeq, Volume.Type type) {
this.data = data;
this.diskSeq = diskSeq;
this.type = type;
}
}
public DataTO getData() {
return data;
}
public void setData(DataTO data) {
this.data = data;
}
public Long getDiskSeq() {
return diskSeq;
}
public void setDiskSeq(Long diskSeq) {
this.diskSeq = diskSeq;
}
public Volume.Type getType() {
return type;
}
public void setType(Volume.Type type) {
this.type = type;
}
}

View File

@ -14,31 +14,47 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.storage.to;
package com.cloud.agent.api.to;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import com.cloud.storage.DataStoreRole;
public final class NfsTO implements DataStoreTO {
private String _url;
private DataStoreRole _role;
public NfsTO() {
super();
public class NfsPrimaryDataStoreTO extends PrimaryDataStoreTO {
private String server;
private String path;
public NfsPrimaryDataStoreTO(PrimaryDataStoreInfo dataStore) {
super(dataStore);
}
public void setServer(String server) {
this.server = server;
public NfsTO(String url, DataStoreRole role) {
super();
this._url = url;
this._role = role;
}
public String getServer() {
return this.server;
public String getUrl() {
return _url;
}
public void setPath(String path) {
this.path = path;
public void setUrl(String _url) {
this._url = _url;
}
public String getPath() {
return this.path;
@Override
public DataStoreRole getRole() {
return _role;
}
public void setRole(DataStoreRole _role) {
this._role = _role;
}
}

View File

@ -18,9 +18,10 @@ package com.cloud.agent.api.to;
import java.util.Date;
import com.cloud.storage.DataStoreRole;
import com.cloud.utils.S3Utils;
public final class S3TO implements S3Utils.ClientOptions {
public final class S3TO implements S3Utils.ClientOptions, DataStoreTO {
private Long id;
private String uuid;
@ -33,6 +34,7 @@ public final class S3TO implements S3Utils.ClientOptions {
private Integer maxErrorRetry;
private Integer socketTimeout;
private Date created;
private boolean enableRRS;
public S3TO() {
@ -44,7 +46,7 @@ public final class S3TO implements S3Utils.ClientOptions {
final String secretKey, final String endPoint,
final String bucketName, final Boolean httpsFlag,
final Integer connectionTimeout, final Integer maxErrorRetry,
final Integer socketTimeout, final Date created) {
final Integer socketTimeout, final Date created, final boolean enableRRS) {
super();
@ -59,6 +61,7 @@ public final class S3TO implements S3Utils.ClientOptions {
this.maxErrorRetry = maxErrorRetry;
this.socketTimeout = socketTimeout;
this.created = created;
this.enableRRS = enableRRS;
}
@ -128,6 +131,10 @@ public final class S3TO implements S3Utils.ClientOptions {
return false;
}
if (enableRRS != thatS3TO.enableRRS) {
return false;
}
return true;
}
@ -249,4 +256,20 @@ public final class S3TO implements S3Utils.ClientOptions {
this.created = created;
}
@Override
public DataStoreRole getRole() {
return DataStoreRole.Image;
}
public boolean getEnableRRS() {
return enableRRS;
}
public void setEnableRRS(boolean enableRRS) {
this.enableRRS = enableRRS;
}
}

View File

@ -16,7 +16,9 @@
// under the License.
package com.cloud.agent.api.to;
public class SwiftTO {
import com.cloud.storage.DataStoreRole;
public class SwiftTO implements DataStoreTO {
Long id;
String url;
String account;
@ -54,5 +56,11 @@ public class SwiftTO {
return key;
}
@Override
public DataStoreRole getRole() {
return DataStoreRole.Image;
}
}

View File

@ -58,7 +58,7 @@ public class VirtualMachineTO {
Map<String, String> params;
String uuid;
VolumeTO[] disks;
DiskTO[] disks;
NicTO[] nics;
public VirtualMachineTO(long id, String instanceName, VirtualMachine.Type type, int cpus, Integer speed, long minRam, long maxRam, BootloaderType bootloader, String os, boolean enableHA, boolean limitCpuUse, String vncPassword) {
@ -215,11 +215,11 @@ public class VirtualMachineTO {
this.bootupScripts = bootupScripts;
}
public VolumeTO[] getDisks() {
public DiskTO[] getDisks() {
return disks;
}
public void setDisks(VolumeTO[] disks) {
public void setDisks(DiskTO[] disks) {
this.disks = disks;
}

View File

@ -124,15 +124,6 @@ public interface ManagementService {
*/
Pair<List<? extends Host>, Integer> searchForServers(ListHostsCmd cmd);
/**
* Creates a new template
*
* @param cmd
* @return updated template
*/
VirtualMachineTemplate updateTemplate(UpdateIsoCmd cmd);
VirtualMachineTemplate updateTemplate(UpdateTemplateCmd cmd);
@ -223,28 +214,6 @@ public interface ManagementService {
*/
List<? extends Capacity> listCapacities(ListCapacityCmd cmd);
/**
* List ISOs that match the specified criteria.
*
* @param cmd
* The command that wraps the (optional) templateId, name, keyword, templateFilter, bootable, account,
* and zoneId
* parameters.
* @return list of ISOs
*/
Set<Pair<Long, Long>> listIsos(ListIsosCmd cmd);
/**
* List templates that match the specified criteria.
*
* @param cmd
* The command that wraps the (optional) templateId, name, keyword, templateFilter, bootable, account,
* and zoneId
* parameters.
* @return list of ISOs
*/
Set<Pair<Long, Long>> listTemplates(ListTemplatesCmd cmd);
/**
* List system VMs by the given search criteria
@ -271,20 +240,6 @@ public interface ManagementService {
Map<String, Object> listCapabilities(ListCapabilitiesCmd cmd);
/**
* Extracts the volume to a particular location.
*
* @param cmd
* the command specifying url (where the volume needs to be extracted to), zoneId (zone where the volume
* exists),
* id (the id of the volume)
* @throws URISyntaxException
* @throws InternalErrorException
* @throws PermissionDeniedException
*
*/
Long extractVolume(ExtractVolumeCmd cmd) throws URISyntaxException;
/**
* return an array of available hypervisors
*
@ -412,7 +367,7 @@ public interface ManagementService {
* @return List of capacities
*/
List<? extends Capacity> listTopConsumedResources(ListCapacityCmd cmd);
List<String> listDeploymentPlanners();
VirtualMachine upgradeSystemVM(ScaleSystemVMCmd cmd) throws ResourceUnavailableException, ManagementServerException, VirtualMachineMigrationException, ConcurrentOperationException;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.engine.subsystem.api.storage;
package com.cloud.storage;
import com.cloud.utils.exception.CloudRuntimeException;

View File

@ -14,3 +14,15 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.storage;
import org.apache.cloudstack.api.InternalIdentity;
public interface GuestOSHypervisor extends InternalIdentity {
String getHypervisorType();
String getGuestOsName();
long getGuestOsId();
}

View File

@ -14,27 +14,34 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.agent.api.storage;
package com.cloud.storage;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
public interface ImageStore extends Identity, InternalIdentity {
public class DeleteTemplateCommand extends ssCommand {
private String templatePath;
/**
* @return name of the object store.
*/
String getName();
/**
* @return availability zone.
*/
Long getDataCenterId();
public DeleteTemplateCommand() {
}
/**
* @return object store provider name
*/
String getProviderName();
public DeleteTemplateCommand(String secUrl, String templatePath) {
this.setSecUrl(secUrl);
this.templatePath = templatePath;
}
@Override
public boolean executeInSequence() {
return true;
}
public String getTemplatePath() {
return templatePath;
}
/**
*
* @return data store protocol
*/
String getProtocol();
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.engine.subsystem.api.storage;
package com.cloud.storage;
public enum ScopeType {
HOST,

View File

@ -18,12 +18,13 @@ package com.cloud.storage;
import java.util.Date;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.fsm.StateObject;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.fsm.StateObject;
public interface Snapshot extends ControlledEntity, Identity, InternalIdentity, StateObject<Snapshot.State> {
public enum Type {
MANUAL,
@ -59,6 +60,9 @@ public interface Snapshot extends ControlledEntity, Identity, InternalIdentity,
CreatedOnPrimary,
BackingUp,
BackedUp,
Copying,
Destroying,
Destroyed,//it's a state, user can't see the snapshot from ui, while the snapshot may still exist on the storage
Error;
public String toString() {
@ -75,6 +79,8 @@ public interface Snapshot extends ControlledEntity, Identity, InternalIdentity,
OperationNotPerformed,
BackupToSecondary,
BackedupToSecondary,
DestroyRequested,
CopyingRequested,
OperationSucceeded,
OperationFailed
}
@ -85,8 +91,6 @@ public interface Snapshot extends ControlledEntity, Identity, InternalIdentity,
long getVolumeId();
String getPath();
String getName();
Date getCreated();

View File

@ -21,13 +21,13 @@ import java.util.List;
public class Storage {
public static enum ImageFormat {
QCOW2(true, true, false),
RAW(false, false, false),
VHD(true, true, true),
ISO(false, false, false),
QCOW2(true, true, false, "qcow2"),
RAW(false, false, false, "raw"),
VHD(true, true, true, "vhd"),
ISO(false, false, false, "iso"),
OVA(true, true, true, "ova"),
BAREMETAL(false, false, false),
TAR(false, false, false);
BAREMETAL(false, false, false, "BAREMETAL"),
TAR(false, false, false, "tar");
private final boolean thinProvisioned;
private final boolean supportSparse;
@ -66,6 +66,7 @@ public class Storage {
return fileExtension;
}
}
public static enum FileSystem {

View File

@ -58,7 +58,7 @@ public interface StoragePool extends Identity, InternalIdentity {
/**
* @return available storage in bytes
*/
long getAvailableBytes();
long getUsedBytes();
Long getClusterId();

View File

@ -18,12 +18,17 @@ package com.cloud.storage;
import java.net.UnknownHostException;
import org.apache.cloudstack.api.command.admin.storage.AddImageStoreCmd;
import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaintenanceCmd;
import org.apache.cloudstack.api.command.admin.storage.CreateCacheStoreCmd;
import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
import org.apache.cloudstack.api.command.admin.storage.DeleteImageStoreCmd;
import org.apache.cloudstack.api.command.admin.storage.DeletePoolCmd;
import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd;
import com.cloud.exception.DiscoveryException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceInUseException;
import com.cloud.exception.ResourceUnavailableException;
@ -43,6 +48,8 @@ public interface StorageService{
*/
StoragePool createPool(CreateStoragePoolCmd cmd) throws ResourceInUseException, IllegalArgumentException,
UnknownHostException, ResourceUnavailableException;
ImageStore createCacheStore(CreateCacheStoreCmd cmd);
/**
* Delete the storage pool
@ -82,4 +89,9 @@ public interface StorageService{
public StoragePool updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException;
public StoragePool getStoragePool(long id);
boolean deleteImageStore(DeleteImageStoreCmd cmd);
ImageStore discoverImageStore(AddImageStoreCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException;
}

View File

@ -35,7 +35,7 @@ public interface Upload extends InternalIdentity, Identity {
FTP_UPLOAD, HTTP_DOWNLOAD
}
long getHostId();
long getDataStoreId();
Date getCreated();

View File

@ -44,6 +44,7 @@ public interface Volume extends ControlledEntity, Identity, InternalIdentity, Ba
Destroying("The volume is destroying, and can't be recovered."),
UploadOp ("The volume upload operation is in progress or in short the volume is on secondary storage"),
Uploading("volume is uploading"),
Copying("volume is copying from image store to primary, in case it's an uploaded volume"),
Uploaded("volume is uploaded");
String _description;
@ -73,9 +74,9 @@ public interface Volume extends ControlledEntity, Identity, InternalIdentity, Ba
s_fsm.addTransition(Resizing, Event.OperationSucceeded, Ready);
s_fsm.addTransition(Resizing, Event.OperationFailed, Ready);
s_fsm.addTransition(Allocated, Event.UploadRequested, UploadOp);
s_fsm.addTransition(Uploaded, Event.CopyRequested, Creating);// CopyRequested for volume from sec to primary storage
s_fsm.addTransition(Creating, Event.CopySucceeded, Ready);
s_fsm.addTransition(Creating, Event.CopyFailed, Uploaded);// Copying volume from sec to primary failed.
s_fsm.addTransition(Uploaded, Event.CopyRequested, Copying);
s_fsm.addTransition(Copying, Event.OperationSucceeded, Ready);
s_fsm.addTransition(Copying, Event.OperationFailed, Uploaded);
s_fsm.addTransition(UploadOp, Event.DestroyRequested, Destroy);
s_fsm.addTransition(Ready, Event.DestroyRequested, Destroy);
s_fsm.addTransition(Destroy, Event.ExpungingRequested, Expunging);
@ -152,7 +153,7 @@ public interface Volume extends ControlledEntity, Identity, InternalIdentity, Ba
Date getCreated();
long getDiskOfferingId();
Long getDiskOfferingId();
String getChainInfo();
@ -173,4 +174,5 @@ public interface Volume extends ControlledEntity, Identity, InternalIdentity, Ba
* @param reserv
*/
void setReservationId(String reserv);
Storage.ImageFormat getFormat();
}

View File

@ -18,9 +18,12 @@
*/
package com.cloud.storage;
import java.net.URISyntaxException;
import org.apache.cloudstack.api.command.user.volume.*;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InternalErrorException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.user.Account;
@ -36,7 +39,7 @@ public interface VolumeApiService {
* @throws PermissionDeniedException
*/
Volume allocVolume(CreateVolumeCmd cmd) throws ResourceAllocationException;
/**
* Creates the volume based on the given criteria
*
@ -50,7 +53,7 @@ public interface VolumeApiService {
/**
* Resizes the volume based on the given criteria
*
*
* @param cmd
* the API command wrapping the criteria
* @return the volume object
@ -58,7 +61,7 @@ public interface VolumeApiService {
*/
Volume resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationException;
Volume migrateVolume(MigrateVolumeCmd cmd) throws ConcurrentOperationException;
Volume migrateVolume(MigrateVolumeCmd cmd);
/**
* Uploads the volume to secondary storage
@ -75,5 +78,24 @@ public interface VolumeApiService {
Volume detachVolumeFromVM(DetachVolumeCmd cmmd);
Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account account)
throws ResourceAllocationException;
Snapshot allocSnapshot(Long volumeId, Long policyId)
throws ResourceAllocationException;
Volume updateVolume(UpdateVolumeCmd updateVolumeCmd);
/**
* Extracts the volume to a particular location.
*
* @param cmd
* the command specifying url (where the volume needs to be extracted to), zoneId (zone where the volume
* exists),
* id (the id of the volume)
* @throws URISyntaxException
* @throws InternalErrorException
* @throws PermissionDeniedException
*
*/
String extractVolume(ExtractVolumeCmd cmd);
}

View File

@ -31,7 +31,7 @@ import com.cloud.storage.Volume;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
public interface SnapshotService {
public interface SnapshotApiService {
/**
* List all snapshots of a disk volume. Optionally lists snapshots created by specified interval

View File

@ -16,7 +16,7 @@
// under the License.
package com.cloud.storage.template;
public class TemplateInfo {
public class TemplateProp {
String templateName;
String installPath;
long size;
@ -25,11 +25,11 @@ public class TemplateInfo {
boolean isPublic;
boolean isCorrupted;
protected TemplateInfo() {
protected TemplateProp() {
}
public TemplateInfo(String templateName, String installPath, long size, long physicalSize, boolean isPublic, boolean isCorrupted) {
public TemplateProp(String templateName, String installPath, long size, long physicalSize, boolean isPublic, boolean isCorrupted) {
this.templateName = templateName;
this.installPath = installPath;
this.size = size;
@ -38,7 +38,7 @@ public class TemplateInfo {
this.isCorrupted = isCorrupted;
}
public TemplateInfo(String templateName, String installPath, boolean isPublic, boolean isCorrupted) {
public TemplateProp(String templateName, String installPath, boolean isPublic, boolean isCorrupted) {
this(templateName, installPath, 0, 0, isPublic, isCorrupted);
}

View File

@ -24,19 +24,22 @@ import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoPermissionsCmd;
import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
import org.apache.cloudstack.api.command.user.iso.ExtractIsoCmd;
import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
import org.apache.cloudstack.api.command.user.iso.UpdateIsoCmd;
import org.apache.cloudstack.api.command.user.template.CopyTemplateCmd;
import org.apache.cloudstack.api.command.user.template.CreateTemplateCmd;
import org.apache.cloudstack.api.command.user.template.DeleteTemplateCmd;
import org.apache.cloudstack.api.command.user.template.ExtractTemplateCmd;
import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
import org.apache.cloudstack.api.command.user.template.UpdateTemplateCmd;
import com.cloud.exception.InternalErrorException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
import com.cloud.utils.exception.CloudRuntimeException;
public interface TemplateService {
public interface TemplateApiService {
VirtualMachineTemplate registerTemplate(RegisterTemplateCmd cmd) throws URISyntaxException, ResourceAllocationException;
@ -72,29 +75,32 @@ public interface TemplateService {
*
* @param cmd
* - the command specifying the mode and id of the ISO
* @return extractId.
* @return extractUrl extract url.
*/
Long extract(ExtractIsoCmd cmd) throws InternalErrorException;
String extract(ExtractIsoCmd cmd) throws InternalErrorException;
/**
* Extracts a Template
*
* @param cmd
* - the command specifying the mode and id of the template
* @return extractId
* @return extractUrl extract url
*/
Long extract(ExtractTemplateCmd cmd) throws InternalErrorException;
String extract(ExtractTemplateCmd cmd) throws InternalErrorException;
VirtualMachineTemplate getTemplate(long templateId);
List<String> listTemplatePermissions(BaseListTemplateOrIsoPermissionsCmd cmd);
boolean updateTemplateOrIsoPermissions(BaseUpdateTemplateOrIsoPermissionsCmd cmd);
VirtualMachineTemplate createPrivateTemplateRecord(CreateTemplateCmd cmd,
Account templateOwner) throws ResourceAllocationException;
VirtualMachineTemplate createPrivateTemplate(CreateTemplateCmd command)
throws CloudRuntimeException;
VirtualMachineTemplate updateTemplate(UpdateIsoCmd cmd);
VirtualMachineTemplate updateTemplate(UpdateTemplateCmd cmd);
}

View File

@ -19,6 +19,8 @@ package com.cloud.vm;
import java.util.List;
import java.util.Map;
import com.cloud.agent.api.to.DataTO;
import com.cloud.agent.api.to.DiskTO;
import com.cloud.agent.api.to.VolumeTO;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.offering.ServiceOffering;
@ -111,11 +113,11 @@ public interface VirtualMachineProfile<T extends VirtualMachine> {
List<NicProfile> getNics();
List<VolumeTO> getDisks();
List<DiskTO> getDisks();
void addNic(int index, NicProfile nic);
void addDisk(int index, VolumeTO disk);
void addDisk(int index, DiskTO disk);
StringBuilder getBootArgsBuilder();
@ -125,7 +127,7 @@ public interface VirtualMachineProfile<T extends VirtualMachine> {
void addNic(NicProfile nic);
void addDisk(VolumeTO disk);
void addDisk(DiskTO disk);
VirtualMachine.Type getType();

View File

@ -69,8 +69,8 @@ import com.cloud.server.TaggedResourceService;
import com.cloud.storage.DataStoreProviderApiService;
import com.cloud.storage.StorageService;
import com.cloud.storage.VolumeApiService;
import com.cloud.storage.snapshot.SnapshotService;
import com.cloud.template.TemplateService;
import com.cloud.storage.snapshot.SnapshotApiService;
import com.cloud.template.TemplateApiService;
import com.cloud.user.Account;
import com.cloud.user.AccountService;
import com.cloud.user.DomainService;
@ -116,9 +116,9 @@ public abstract class BaseCmd {
@Inject public VolumeApiService _volumeService;
@Inject public ResourceService _resourceService;
@Inject public NetworkService _networkService;
@Inject public TemplateService _templateService;
@Inject public TemplateApiService _templateService;
@Inject public SecurityGroupService _securityGroupService;
@Inject public SnapshotService _snapshotService;
@Inject public SnapshotApiService _snapshotService;
@Inject public VpcVirtualNetworkApplianceService _routerService;
@Inject public ResponseGenerator _responseGenerator;
@Inject public EntityManager _entityMgr;

View File

@ -122,6 +122,7 @@ import org.apache.cloudstack.api.response.HostForMigrationResponse;
import org.apache.cloudstack.api.response.HostResponse;
import org.apache.cloudstack.api.response.HypervisorCapabilitiesResponse;
import org.apache.cloudstack.api.response.IPAddressResponse;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.api.response.InstanceGroupResponse;
import org.apache.cloudstack.api.response.InternalLoadBalancerElementResponse;
import org.apache.cloudstack.api.response.IpForwardingRuleResponse;
@ -187,6 +188,7 @@ import org.apache.cloudstack.region.PortableIpRange;
import org.apache.cloudstack.region.Region;
import org.apache.cloudstack.usage.Usage;
import com.cloud.storage.ImageStore;
import java.text.DecimalFormat;
import java.util.EnumSet;
import java.util.List;
@ -278,7 +280,7 @@ public interface ResponseGenerator {
Host findHostById(Long hostId);
List<TemplateResponse> createTemplateResponses(long templateId, long zoneId, boolean readyOnly);
//List<TemplateResponse> createTemplateResponses(long templateId, long zoneId, boolean readyOnly);
VpnUsersResponse createVpnUserResponse(VpnUser user);
@ -294,7 +296,9 @@ public interface ResponseGenerator {
SecurityGroupResponse createSecurityGroupResponse(SecurityGroup group);
ExtractResponse createExtractResponse(Long uploadId, Long id, Long zoneId, Long accountId, String mode);
ExtractResponse createExtractResponse(Long uploadId, Long id, Long zoneId, Long accountId, String mode, String url);
ExtractResponse createExtractResponse(Long id, Long zoneId, Long accountId, String mode, String url);
String toSerializedString(CreateCmdResponse response, String responseType);
@ -304,7 +308,9 @@ public interface ResponseGenerator {
//List<EventResponse> createEventResponse(EventJoinVO... events);
TemplateResponse createIsoResponse(VirtualMachineTemplate result);
TemplateResponse createTemplateUpdateResponse(VirtualMachineTemplate result);
List<TemplateResponse> createTemplateResponses(VirtualMachineTemplate result, Long zoneId, boolean readyOnly);
List<CapacityResponse> createCapacityResponse(List<? extends Capacity> result, DecimalFormat format);
@ -324,13 +330,13 @@ public interface ResponseGenerator {
Long getSecurityGroupId(String groupName, long accountId);
List<TemplateResponse> createIsoResponses(long isoId, Long zoneId, boolean readyOnly);
List<TemplateResponse> createIsoResponses(VirtualMachineTemplate iso, Long zoneId, boolean readyOnly);
// List<TemplateResponse> createIsoResponses(long isoId, Long zoneId, boolean readyOnly);
//List<TemplateResponse> createIsoResponses(VirtualMachineTemplate iso, long zoneId, boolean readyOnly);
ProjectResponse createProjectResponse(Project project);
List<TemplateResponse> createIsoResponses(VirtualMachineTemplate iso, long zoneId, boolean readyOnly);
List<TemplateResponse> createTemplateResponses(long templateId, Long vmId);
FirewallResponse createFirewallResponse(FirewallRule fwRule);
@ -363,6 +369,8 @@ public interface ResponseGenerator {
RegionResponse createRegionResponse(Region region);
ImageStoreResponse createImageStoreResponse(ImageStore os);
/**
* @param resourceTag
* @param keyValueOnly TODO
@ -437,7 +445,7 @@ public interface ResponseGenerator {
public NicResponse createNicResponse(Nic result);
ApplicationLoadBalancerResponse createLoadBalancerContainerReponse(ApplicationLoadBalancerRule lb, Map<Ip, UserVm> lbInstances);
AffinityGroupResponse createAffinityGroupResponse(AffinityGroup group);
Long getAffinityGroupId(String name, long entityOwnerId);

View File

@ -16,23 +16,22 @@
// under the License.
package org.apache.cloudstack.api.command.admin.host;
import java.util.List;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.HostResponse;
import org.apache.cloudstack.api.command.admin.storage.AddImageStoreCmd;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.log4j.Logger;
import com.cloud.exception.DiscoveryException;
import com.cloud.host.Host;
import com.cloud.storage.ImageStore;
import com.cloud.user.Account;
@APICommand(name = "addSecondaryStorage", description="Adds secondary storage.", responseObject=HostResponse.class)
@APICommand(name = "addSecondaryStorage", description="Adds secondary storage.", responseObject=ImageStoreResponse.class)
public class AddSecondaryStorageCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(AddSecondaryStorageCmd.class.getName());
private static final String s_name = "addsecondarystorageresponse";
@ -48,6 +47,8 @@ public class AddSecondaryStorageCmd extends BaseCmd {
description="the Zone ID for the secondary storage")
private Long zoneId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -60,6 +61,7 @@ public class AddSecondaryStorageCmd extends BaseCmd {
return zoneId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@ -76,17 +78,19 @@ public class AddSecondaryStorageCmd extends BaseCmd {
@Override
public void execute(){
try {
List<? extends Host> result = _resourceService.discoverHosts(this);
HostResponse hostResponse = null;
if (result != null && result.size() > 0) {
for (Host host : result) {
// There should only be one secondary storage host per add
hostResponse = _responseGenerator.createHostResponse(host);
hostResponse.setResponseName(getCommandName());
hostResponse.setObjectName("secondarystorage");
this.setResponseObject(hostResponse);
}
AddImageStoreCmd cmd = new AddImageStoreCmd();
cmd.setUrl(this.getUrl());
cmd.setZoneId(this.getZoneId());
cmd.setProviderName("NFS");
try{
ImageStore result = _storageService.discoverImageStore(cmd);
ImageStoreResponse storeResponse = null;
if (result != null ) {
storeResponse = _responseGenerator.createImageStoreResponse(result);
storeResponse.setResponseName(getCommandName());
storeResponse.setObjectName("secondarystorage");
this.setResponseObject(storeResponse);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
}

View File

@ -0,0 +1,154 @@
// 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.api.command.admin.storage;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.log4j.Logger;
import com.cloud.exception.DiscoveryException;
import com.cloud.storage.ImageStore;
import com.cloud.user.Account;
@APICommand(name = "addImageStore", description="Adds backup image store.", responseObject=ImageStoreResponse.class, since = "4.2.0")
public class AddImageStoreCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(AddImageStoreCmd.class.getName());
private static final String s_name = "addimagestoreresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name for the image store")
private String name;
@Parameter(name=ApiConstants.URL, type=CommandType.STRING, description="the URL for the image store")
private String url;
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType=ZoneResponse.class,
description="the Zone ID for the image store")
private Long zoneId;
@Parameter(name=ApiConstants.PROVIDER, type=CommandType.STRING,
required=true, description="the image store provider name")
private String providerName;
@Parameter(name=ApiConstants.DETAILS, type=CommandType.MAP, description="the details for the image store. Example: details[0].key=accesskey&details[0].value=s389ddssaa&details[1].key=secretkey&details[1].value=8dshfsss")
private Map<String, String> details;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getUrl() {
return url;
}
public String getName() {
return name;
}
public Long getZoneId() {
return zoneId;
}
public Map<String, String> getDetails() {
Map<String, String> detailsMap = null;
if (details != null && !details.isEmpty()) {
detailsMap = new HashMap<String, String>();
Collection<?> props = details.values();
Iterator<?> iter = props.iterator();
while (iter.hasNext()) {
HashMap<String, String> detail = (HashMap<String, String>) iter.next();
String key = detail.get("key");
String value = detail.get("value");
detailsMap.put(key, value);
}
}
return detailsMap;
}
public String getProviderName() {
return this.providerName;
}
public void setUrl(String url) {
this.url = url;
}
public void setZoneId(Long zoneId) {
this.zoneId = zoneId;
}
public void setProviderName(String providerName) {
this.providerName = providerName;
}
public void setDetails(Map<String, String> details) {
this.details = details;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public void execute(){
try{
ImageStore result = _storageService.discoverImageStore(this);
ImageStoreResponse storeResponse = null;
if (result != null ) {
storeResponse = _responseGenerator.createImageStoreResponse(result);
storeResponse.setResponseName(getCommandName());
storeResponse.setObjectName("secondarystorage");
this.setResponseObject(storeResponse);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
}
} catch (DiscoveryException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
}
}

View File

@ -31,12 +31,17 @@ import static org.apache.cloudstack.api.BaseCmd.CommandType.BOOLEAN;
import static org.apache.cloudstack.api.BaseCmd.CommandType.INTEGER;
import static org.apache.cloudstack.api.BaseCmd.CommandType.STRING;
import java.util.HashMap;
import java.util.Map;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.S3Response;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.log4j.Logger;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.DiscoveryException;
@ -44,10 +49,11 @@ import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.storage.S3;
import com.cloud.storage.ImageStore;
@APICommand(name = "addS3", description = "Adds S3", responseObject = S3Response.class, since = "4.0.0")
@APICommand(name = "addS3", description = "Adds S3", responseObject = ImageStoreResponse.class, since = "4.0.0")
public final class AddS3Cmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(AddS3Cmd.class.getName());
private static String COMMAND_NAME = "adds3response";
@ -88,26 +94,33 @@ public final class AddS3Cmd extends BaseCmd {
ServerApiException, ConcurrentOperationException, ResourceAllocationException,
NetworkRuleConflictException {
final S3 result;
AddImageStoreCmd cmd = new AddImageStoreCmd();
cmd.setProviderName("S3");
Map<String, String> details = new HashMap<String, String>();
details.put(ApiConstants.S3_ACCESS_KEY, this.getAccessKey());
details.put(ApiConstants.S3_SECRET_KEY, this.getSecretKey());
details.put(ApiConstants.S3_END_POINT, this.getEndPoint());
details.put(ApiConstants.S3_BUCKET_NAME, this.getBucketName());
details.put(ApiConstants.S3_HTTPS_FLAG, this.getHttpsFlag().toString());
details.put(ApiConstants.S3_CONNECTION_TIMEOUT, this.getConnectionTimeout().toString());
details.put(ApiConstants.S3_MAX_ERROR_RETRY, this.getMaxErrorRetry().toString());
details.put(ApiConstants.S3_SOCKET_TIMEOUT, this.getSocketTimeout().toString());
try {
result = _resourceService.discoverS3(this);
if (result == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add S3.");
try{
ImageStore result = _storageService.discoverImageStore(cmd);
ImageStoreResponse storeResponse = null;
if (result != null ) {
storeResponse = _responseGenerator.createImageStoreResponse(result);
storeResponse.setResponseName(getCommandName());
storeResponse.setObjectName("secondarystorage");
this.setResponseObject(storeResponse);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
}
} catch (DiscoveryException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add S3 due to " + e.getMessage());
} catch (DiscoveryException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
final S3Response response = _responseGenerator.createS3Response(result);
response.setResponseName(this.getCommandName());
this.setResponseObject(response);
}
@Override

View File

@ -0,0 +1,123 @@
/*
* 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.api.command.admin.storage;
import java.util.Map;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.BaseCmd.CommandType;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.log4j.Logger;
import com.cloud.exception.DiscoveryException;
import com.cloud.storage.ImageStore;
import com.cloud.user.Account;
@APICommand(name = "createCacheStore", description="create cache store.", responseObject=ImageStoreResponse.class)
public class CreateCacheStoreCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(AddImageStoreCmd.class.getName());
private static final String s_name = "createcachestoreresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.URL, type=CommandType.STRING, required=true, description="the URL for the cache store")
private String url;
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType=ZoneResponse.class,
description="the Zone ID for the image store")
private Long zoneId;
@Parameter(name=ApiConstants.DETAILS, type=CommandType.MAP, description="the details for the image store")
private Map<String, String> details;
@Parameter(name=ApiConstants.SCOPE, type=CommandType.STRING,
required=false, description="the scope of the image store: zone only for now")
private String scope;
@Parameter(name=ApiConstants.PROVIDER, type=CommandType.STRING,
required=false, description="the cache store provider name")
private String providerName;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getUrl() {
return url;
}
public Long getZoneId() {
return zoneId;
}
public Map<String, String> getDetails() {
return details;
}
public String getScope() {
return this.scope;
}
public String getProviderName() {
return this.providerName;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public void execute(){
try{
ImageStore result = _storageService.createCacheStore(this);
ImageStoreResponse storeResponse = null;
if (result != null ) {
storeResponse = _responseGenerator.createImageStoreResponse(result);
storeResponse.setResponseName(getCommandName());
storeResponse.setObjectName("secondarystorage");
this.setResponseObject(storeResponse);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
}
} catch (Exception ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
}
}

View File

@ -0,0 +1,80 @@
// 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.api.command.admin.storage;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.HostResponse;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.log4j.Logger;
import com.cloud.user.Account;
@APICommand(name = "deleteImageStore", description = "Deletes an image store .", responseObject = SuccessResponse.class, since = "4.2.0")
public class DeleteImageStoreCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(DeleteImageStoreCmd.class.getName());
private static final String s_name = "deleteimagestoreresponse";
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = ImageStoreResponse.class,
required = true, description = "the image store ID")
private Long id;
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getId() {
return id;
}
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public void execute() {
boolean result = _storageService.deleteImageStore(this);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete image store");
}
}
}

View File

@ -0,0 +1,109 @@
// 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.api.command.admin.storage;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.ClusterResponse;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.PodResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.log4j.Logger;
import com.cloud.async.AsyncJob;
@APICommand(name = "listImageStores", description="Lists image stores.", responseObject=ImageStoreResponse.class, since = "4.2.0")
public class ListImageStoresCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListImageStoresCmd.class.getName());
private static final String s_name = "listimagestoreresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the image store")
private String storeName;
@Parameter(name=ApiConstants.PROTOCOL, type=CommandType.STRING, description="the image store protocol")
private String protocol;
@Parameter(name=ApiConstants.PROVIDER, type=CommandType.STRING, description="the image store provider")
private String provider;
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class,
description="the Zone ID for the image store")
private Long zoneId;
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = ImageStoreResponse.class,
description="the ID of the storage pool")
private Long id;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getZoneId() {
return zoneId;
}
public String getStoreName() {
return storeName;
}
public String getProtocol() {
return protocol;
}
public Long getId() {
return id;
}
public String getProvider() {
return provider;
}
public void setProvider(String provider) {
this.provider = provider;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public void execute(){
ListResponse<ImageStoreResponse> response = _queryService.searchForImageStores(this);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
}

View File

@ -18,23 +18,18 @@
*/
package org.apache.cloudstack.api.command.admin.storage;
import java.util.ArrayList;
import java.util.List;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.S3Response;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.storage.S3;
@APICommand(name = "listS3s", description = "Lists S3s", responseObject = S3Response.class, since = "4.0.0")
@APICommand(name = "listS3s", description = "Lists S3s", responseObject = ImageStoreResponse.class, since = "4.0.0")
public class ListS3sCmd extends BaseListCmd {
private static final String COMMAND_NAME = "lists3sresponse";
@ -44,28 +39,11 @@ public class ListS3sCmd extends BaseListCmd {
ServerApiException, ConcurrentOperationException, ResourceAllocationException,
NetworkRuleConflictException {
final List<? extends S3> result = _resourceService.listS3s(this);
final ListResponse<S3Response> response = new ListResponse<S3Response>();
final List<S3Response> s3Responses = new ArrayList<S3Response>();
if (result != null) {
for (S3 s3 : result) {
S3Response s3Response = _responseGenerator.createS3Response(s3);
s3Response.setResponseName(this.getCommandName());
s3Response.setObjectName("s3");
s3Responses.add(s3Response);
}
}
response.setResponses(s3Responses);
response.setResponseName(this.getCommandName());
ListImageStoresCmd cmd = new ListImageStoresCmd();
cmd.setProvider("S3");
ListResponse<ImageStoreResponse> response = _queryService.searchForImageStores(cmd);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
@Override

View File

@ -16,21 +16,24 @@
// under the License.
package org.apache.cloudstack.api.command.admin.swift;
import java.util.HashMap;
import java.util.Map;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.HostResponse;
import org.apache.cloudstack.api.response.SwiftResponse;
import org.apache.cloudstack.api.command.admin.storage.AddImageStoreCmd;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.log4j.Logger;
import com.cloud.exception.DiscoveryException;
import com.cloud.storage.Swift;
import com.cloud.storage.ImageStore;
import com.cloud.user.Account;
@APICommand(name = "addSwift", description = "Adds Swift.", responseObject = HostResponse.class, since="3.0.0")
@APICommand(name = "addSwift", description = "Adds Swift.", responseObject = ImageStoreResponse.class, since="3.0.0")
public class AddSwiftCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(AddSwiftCmd.class.getName());
private static final String s_name = "addswiftresponse";
@ -87,21 +90,29 @@ public class AddSwiftCmd extends BaseCmd {
@Override
public void execute(){
try {
Swift result = _resourceService.discoverSwift(this);
SwiftResponse swiftResponse = null;
if (result != null) {
swiftResponse = _responseGenerator.createSwiftResponse(result);
swiftResponse.setResponseName(getCommandName());
swiftResponse.setObjectName("swift");
this.setResponseObject(swiftResponse);
AddImageStoreCmd cmd = new AddImageStoreCmd();
cmd.setProviderName("Swift");
cmd.setUrl(this.getUrl());
Map<String, String> details = new HashMap<String, String>();
details.put(ApiConstants.ACCOUNT, this.getAccount());
details.put(ApiConstants.USERNAME, this.getUsername());
details.put(ApiConstants.KEY, this.getKey());
try{
ImageStore result = _storageService.discoverImageStore(cmd);
ImageStoreResponse storeResponse = null;
if (result != null ) {
storeResponse = _responseGenerator.createImageStoreResponse(result);
storeResponse.setResponseName(getCommandName());
storeResponse.setObjectName("secondarystorage");
this.setResponseObject(storeResponse);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Swift");
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
}
} catch (DiscoveryException ex) {
String errMsg = "Failed to add Swift due to " + ex.toString();
s_logger.warn(errMsg, ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errMsg);
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
}
}

View File

@ -16,23 +16,18 @@
// under the License.
package org.apache.cloudstack.api.command.admin.swift;
import java.util.ArrayList;
import java.util.List;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.HostResponse;
import org.apache.cloudstack.api.command.admin.storage.ListImageStoresCmd;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.SwiftResponse;
import org.apache.log4j.Logger;
import com.cloud.storage.Swift;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
@APICommand(name = "listSwifts", description = "List Swift.", responseObject = HostResponse.class, since="3.0.0")
@APICommand(name = "listSwifts", description = "List Swift.", responseObject = ImageStoreResponse.class, since="3.0.0")
public class ListSwiftsCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListSwiftsCmd.class.getName());
private static final String s_name = "listswiftsresponse";
@ -65,19 +60,10 @@ public class ListSwiftsCmd extends BaseListCmd {
@Override
public void execute(){
Pair<List<? extends Swift>, Integer> result = _resourceService.listSwifts(this);
ListResponse<SwiftResponse> response = new ListResponse<SwiftResponse>();
List<SwiftResponse> swiftResponses = new ArrayList<SwiftResponse>();
if (result != null) {
for (Swift swift : result.first()) {
SwiftResponse swiftResponse = _responseGenerator.createSwiftResponse(swift);
swiftResponse.setResponseName(getCommandName());
swiftResponse.setObjectName("swift");
swiftResponses.add(swiftResponse);
}
}
response.setResponses(swiftResponses, result.second());
ListImageStoresCmd cmd = new ListImageStoresCmd();
cmd.setProvider("Swift");
ListResponse<ImageStoreResponse> response = _queryService.searchForImageStores(cmd);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}

View File

@ -80,7 +80,7 @@ public class PrepareTemplateCmd extends BaseCmd {
ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
VirtualMachineTemplate vmTemplate = _templateService.prepareTemplate(templateId, zoneId);
List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(vmTemplate.getId(), zoneId, true);
List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(vmTemplate, zoneId, true);
response.setResponses(templateResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);

View File

@ -33,6 +33,7 @@ import com.cloud.exception.InternalErrorException;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.utils.Pair;
@APICommand(name = "extractIso", description="Extracts an ISO", responseObject=ExtractResponse.class)
public class ExtractIsoCmd extends BaseAsyncCmd {
@ -123,9 +124,9 @@ public class ExtractIsoCmd extends BaseAsyncCmd {
public void execute(){
try {
UserContext.current().setEventDetails(getEventDescription());
Long uploadId = _templateService.extract(this);
if (uploadId != null){
ExtractResponse response = _responseGenerator.createExtractResponse(uploadId, id, zoneId, getEntityOwnerId(), mode);
String uploadUrl = _templateService.extract(this);
if (uploadUrl != null) {
ExtractResponse response = _responseGenerator.createExtractResponse(id, zoneId, getEntityOwnerId(), mode, uploadUrl);
response.setResponseName(getCommandName());
response.setObjectName("iso");
this.setResponseObject(response);

View File

@ -148,15 +148,7 @@ public class ListIsosCmd extends BaseListTaggedResourcesCmd {
@Override
public void execute(){
Set<Pair<Long, Long>> isoZonePairSet = _mgr.listIsos(this);
ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
List<TemplateResponse> templateResponses = new ArrayList<TemplateResponse>();
for (Pair<Long, Long> iso : isoZonePairSet) {
List<TemplateResponse> responses = _responseGenerator.createIsoResponses(iso.first(), iso.second(), listInReadyState());
templateResponses.addAll(responses);
}
response.setResponses(templateResponses);
ListResponse<TemplateResponse> response = _queryService.listIsos(this);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}

View File

@ -88,7 +88,7 @@ public class RegisterIsoCmd extends BaseCmd {
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType = ProjectResponse.class,
description="Register iso for the project")
private Long projectId;
@Parameter(name=ApiConstants.IMAGE_STORE_UUID, type=CommandType.STRING,
description="Image store uuid")
private String imageStoreUuid;
@ -147,7 +147,7 @@ public class RegisterIsoCmd extends BaseCmd {
public String getChecksum() {
return checksum;
}
public String getImageStoreUuid() {
return this.imageStoreUuid;
}
@ -180,7 +180,7 @@ public class RegisterIsoCmd extends BaseCmd {
VirtualMachineTemplate template = _templateService.registerIso(this);
if (template != null) {
ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(template.getId(), zoneId, false);
List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(template, zoneId, false);
response.setResponses(templateResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);

View File

@ -66,9 +66,9 @@ public class UpdateIsoCmd extends BaseUpdateTemplateOrIsoCmd {
@Override
public void execute(){
VirtualMachineTemplate result = _mgr.updateTemplate(this);
VirtualMachineTemplate result = _templateService.updateTemplate(this);
if (result != null) {
TemplateResponse response = _responseGenerator.createIsoResponse(result);
TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {

View File

@ -152,7 +152,7 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
@Override
public void create() throws ResourceAllocationException {
Snapshot snapshot = _snapshotService.allocSnapshot(getVolumeId(), getPolicyId());
Snapshot snapshot = this._volumeService.allocSnapshot(getVolumeId(), getPolicyId());
if (snapshot != null) {
this.setEntityId(snapshot.getId());
this.setEntityUuid(snapshot.getUuid());
@ -165,15 +165,19 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
public void execute() {
s_logger.info("VOLSS: createSnapshotCmd starts:" + System.currentTimeMillis());
UserContext.current().setEventDetails("Volume Id: "+getVolumeId());
Snapshot snapshot = _snapshotService.createSnapshot(getVolumeId(), getPolicyId(), getEntityId(), _accountService.getAccount(getEntityOwnerId()));
if (snapshot != null) {
SnapshotResponse response = _responseGenerator.createSnapshotResponse(snapshot);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
Snapshot snapshot;
try {
snapshot = _volumeService.takeSnapshot(this.getVolumeId(), this.getPolicyId(), this.getEntityId(), _accountService.getAccount(getEntityOwnerId()));
if (snapshot != null) {
SnapshotResponse response = _responseGenerator.createSnapshotResponse(snapshot);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + volumeId);
}
} catch (Exception e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + volumeId);
}
s_logger.info("VOLSS: backupSnapshotCmd finishes:" + System.currentTimeMillis());
}

View File

@ -124,7 +124,7 @@ public class CopyTemplateCmd extends BaseAsyncCmd {
VirtualMachineTemplate template = _templateService.copyTemplate(this);
if (template != null){
List<TemplateResponse> listResponse = _responseGenerator.createTemplateResponses(template.getId(), getDestinationZoneId(), false);
List<TemplateResponse> listResponse = _responseGenerator.createTemplateResponses(template, getDestinationZoneId(), false);
TemplateResponse response = new TemplateResponse();
if (listResponse != null && !listResponse.isEmpty()) {
response = listResponse.get(0);

View File

@ -34,6 +34,7 @@ import com.cloud.exception.InternalErrorException;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.utils.Pair;
@APICommand(name = "extractTemplate", description="Extracts a template", responseObject=ExtractResponse.class)
public class ExtractTemplateCmd extends BaseAsyncCmd {
@ -125,9 +126,9 @@ public class ExtractTemplateCmd extends BaseAsyncCmd {
public void execute(){
try {
UserContext.current().setEventDetails(getEventDescription());
Long uploadId = _templateService.extract(this);
if (uploadId != null){
ExtractResponse response = _responseGenerator.createExtractResponse(uploadId, id, zoneId, getEntityOwnerId(), mode);
String uploadUrl = _templateService.extract(this);
if (uploadUrl != null) {
ExtractResponse response = _responseGenerator.createExtractResponse(id, zoneId, getEntityOwnerId(), mode, uploadUrl);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {

View File

@ -26,6 +26,7 @@ import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.TemplateResponse;
import org.apache.cloudstack.api.response.VolumeResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.log4j.Logger;
@ -55,7 +56,7 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the template name")
private String templateName;
@Parameter(name=ApiConstants.TEMPLATE_FILTER, type=CommandType.STRING, required=true, description="possible values are \"featured\", \"self\", \"selfexecutable\",\"sharedexecutable\",\"executable\", and \"community\". " +
@Parameter(name=ApiConstants.TEMPLATE_FILTER, type=CommandType.STRING, required=true, description="possible values are \"featured\", \"self\", \"selfexecutable\",\"sharedexecutable\",\"executable\", and \"community\". " +
"* featured : templates that have been marked as featured and public. " +
"* self : templates that have been registered or created by the calling user. " +
"* selfexecutable : same as self, but only returns templates that can be used to deploy a new VM. " +
@ -119,17 +120,7 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
@Override
public void execute(){
Set<Pair<Long, Long>> templateZonePairSet = _mgr.listTemplates(this);
ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
List<TemplateResponse> templateResponses = new ArrayList<TemplateResponse>();
for (Pair<Long, Long> template : templateZonePairSet) {
List<TemplateResponse> responses = _responseGenerator.createTemplateResponses(template.first().longValue(), template.second(), listInReadyState());
templateResponses.addAll(responses);
}
response.setResponses(templateResponses);
ListResponse<TemplateResponse> response = _queryService.listTemplates(this);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}

View File

@ -110,11 +110,7 @@ public class RegisterTemplateCmd extends BaseCmd {
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType = ProjectResponse.class,
description="Register template for the project")
private Long projectId;
@Parameter(name=ApiConstants.IMAGE_STORE_UUID, type=CommandType.STRING,
description="Image store uuid")
private String imageStoreUuid;
@Parameter(name=ApiConstants.DETAILS, type=CommandType.MAP, description="Template details in key/value pairs.")
protected Map details;
@ -196,10 +192,7 @@ public class RegisterTemplateCmd extends BaseCmd {
public String getTemplateTag() {
return templateTag;
}
public String getImageStoreUuid() {
return this.imageStoreUuid;
}
public Map getDetails() {
if (details == null || details.isEmpty()) {
@ -244,7 +237,7 @@ public class RegisterTemplateCmd extends BaseCmd {
VirtualMachineTemplate template = _templateService.registerTemplate(this);
if (template != null){
ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(template.getId(), zoneId, false);
List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(template, zoneId, false);
response.setResponses(templateResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);

View File

@ -66,9 +66,9 @@ public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd {
@Override
public void execute(){
VirtualMachineTemplate result = _mgr.updateTemplate(this);
VirtualMachineTemplate result = _templateService.updateTemplate(this);
if (result != null) {
TemplateResponse response = _responseGenerator.createIsoResponse(result);
TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(result);
response.setObjectName("template");
response.setResponseName(getCommandName());
this.setResponseObject(response);

View File

@ -117,7 +117,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd {
}
public Boolean getDisplayVolume() {
return displayVolume;
return displayVolume != null ? displayVolume : Boolean.TRUE;
}
/////////////////////////////////////////////////////

View File

@ -126,33 +126,26 @@ public class ExtractVolumeCmd extends BaseAsyncCmd {
@Override
public void execute(){
try {
UserContext.current().setEventDetails("Volume Id: "+getId());
Long uploadId = _mgr.extractVolume(this);
if (uploadId != null){
Upload uploadInfo = _entityMgr.findById(Upload.class, uploadId);
ExtractResponse response = new ExtractResponse();
response.setResponseName(getCommandName());
response.setObjectName("volume");
Volume vol = _entityMgr.findById(Volume.class, id);
response.setId(vol.getUuid());
response.setName(vol.getName());
DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
response.setZoneId(zone.getUuid());
response.setZoneName(zone.getName());
response.setMode(mode);
response.setUploadId(uploadInfo.getUuid());
response.setState(uploadInfo.getUploadState().toString());
Account account = _entityMgr.findById(Account.class, getEntityOwnerId());
response.setAccountId(account.getUuid());
response.setUrl(uploadInfo.getUploadUrl());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract volume");
}
} catch (URISyntaxException ex) {
s_logger.info(ex);
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage());
UserContext.current().setEventDetails("Volume Id: " + getId());
String uploadUrl = _volumeService.extractVolume(this);
if (uploadUrl != null) {
ExtractResponse response = new ExtractResponse();
response.setResponseName(getCommandName());
response.setObjectName("volume");
Volume vol = _entityMgr.findById(Volume.class, id);
response.setId(vol.getUuid());
response.setName(vol.getName());
DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
response.setZoneId(zone.getUuid());
response.setZoneName(zone.getName());
response.setMode(mode);
response.setState(Upload.Status.DOWNLOAD_URL_CREATED.toString());
Account account = _entityMgr.findById(Account.class, getEntityOwnerId());
response.setAccountId(account.getUuid());
response.setUrl(uploadUrl);
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract volume");
}
}
}

View File

@ -98,18 +98,15 @@ public class MigrateVolumeCmd extends BaseAsyncCmd {
@Override
public void execute(){
Volume result;
try {
result = _volumeService.migrateVolume(this);
if (result != null) {
VolumeResponse response = _responseGenerator.createVolumeResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
} catch (ConcurrentOperationException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate volume: ");
}
Volume result;
result = _volumeService.migrateVolume(this);
if (result != null) {
VolumeResponse response = _responseGenerator.createVolumeResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate volume");
}
}
}

View File

@ -0,0 +1,86 @@
// 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.api.response;
import org.apache.cloudstack.api.BaseResponse;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
public class ImageStoreDetailResponse extends BaseResponse {
@SerializedName("name") @Param(description="detail property name of the image store")
private String name;
@SerializedName("value") @Param(description="detail property value of the image store")
private String value;
public ImageStoreDetailResponse(){
super();
}
public ImageStoreDetailResponse(String name, String val){
super();
this.name = name;
this.value = val;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
String oid = this.getName();
result = prime * result + ((oid== null) ? 0 : oid.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ImageStoreDetailResponse other = (ImageStoreDetailResponse) obj;
String oid = this.getName();
if (oid == null) {
if (other.getName() != null)
return false;
} else if (!oid.equals(other.getName()))
return false;
else if ( this.getValue().equals(other.getValue()))
return false;
return true;
}
}

View File

@ -0,0 +1,149 @@
// 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.api.response;
import java.util.LinkedHashSet;
import java.util.Set;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.EntityReference;
import com.cloud.serializer.Param;
import com.cloud.storage.ImageStore;
import com.cloud.storage.ScopeType;
import com.google.gson.annotations.SerializedName;
@EntityReference(value=ImageStore.class)
public class ImageStoreResponse extends BaseResponse {
@SerializedName("id") @Param(description="the ID of the image store")
private String id;
@SerializedName("zoneid") @Param(description="the Zone ID of the image store")
private String zoneId;
@SerializedName(ApiConstants.ZONE_NAME) @Param(description="the Zone name of the image store")
private String zoneName;
@SerializedName("name") @Param(description="the name of the image store")
private String name;
@SerializedName("url") @Param(description="the url of the image store")
private String url;
@SerializedName("protocol") @Param(description="the protocol of the image store")
private String protocol;
@SerializedName("providername") @Param(description="the provider name of the image store")
private String providerName;
@SerializedName("scope") @Param(description="the scope of the image store")
private ScopeType scope;
@SerializedName("details") @Param(description="the details of the image store")
private Set<ImageStoreDetailResponse> details;
public ImageStoreResponse(){
this.details = new LinkedHashSet<ImageStoreDetailResponse>();
}
@Override
public String getObjectId() {
return this.getId();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getZoneId() {
return zoneId;
}
public void setZoneId(String zoneId) {
this.zoneId = zoneId;
}
public String getZoneName() {
return zoneName;
}
public void setZoneName(String zoneName) {
this.zoneName = zoneName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getProviderName() {
return providerName;
}
public void setProviderName(String providerName) {
this.providerName = providerName;
}
public ScopeType getScope() {
return scope;
}
public void setScope(ScopeType type) {
this.scope = type;
}
public String getProtocol() {
return protocol;
}
public void setProtocol(String protocol) {
this.protocol = protocol;
}
public Set<ImageStoreDetailResponse> getDetails() {
return details;
}
public void setDetails(Set<ImageStoreDetailResponse> details) {
this.details = details;
}
public void addDetail(ImageStoreDetailResponse detail){
this.details.add(detail);
}
}

View File

@ -17,8 +17,10 @@
package org.apache.cloudstack.api.response;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
@ -31,7 +33,7 @@ import com.google.gson.annotations.SerializedName;
@EntityReference(value=VirtualMachineTemplate.class)
@SuppressWarnings("unused")
public class TemplateResponse extends BaseResponse implements ControlledEntityResponse {
public class TemplateResponse extends BaseResponse implements ControlledViewEntityResponse {
@SerializedName(ApiConstants.ID) @Param(description="the template ID")
private String id;
@ -82,6 +84,8 @@ public class TemplateResponse extends BaseResponse implements ControlledEntityRe
@SerializedName(ApiConstants.ACCOUNT) @Param(description="the account name to which the template belongs")
private String account;
//TODO: since a template can be associated to more than one zones, this model is not accurate. For backward-compatibility, keep these fields
// here, but add a zones field to capture multiple zones.
@SerializedName(ApiConstants.ZONE_ID) @Param(description="the ID of the zone for this template")
private String zoneId;
@ -133,8 +137,11 @@ public class TemplateResponse extends BaseResponse implements ControlledEntityRe
@SerializedName(ApiConstants.DETAILS) @Param(description="additional key/value details tied with template")
private Map details;
@SerializedName("zones") @Param(description="list of zones associated with tempate", responseObject = TemplateZoneResponse.class)
private Set<TemplateZoneResponse> zones;
@SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with tempate", responseObject = ResourceTagResponse.class)
private List<ResourceTagResponse> tags;
private Set<ResourceTagResponse> tags;
@SerializedName(ApiConstants.SSHKEY_ENABLED) @Param(description="true if template is sshkey enabled, false otherwise")
private Boolean sshKeyEnabled;
@ -142,6 +149,12 @@ public class TemplateResponse extends BaseResponse implements ControlledEntityRe
@SerializedName(ApiConstants.IS_DYNAMICALLY_SCALABLE) @Param(description="true if template contains XS/VMWare tools inorder to support dynamic scaling of VM cpu/memory")
private Boolean isDynamicallyScalable;
public TemplateResponse(){
zones = new LinkedHashSet<TemplateZoneResponse>();
tags = new LinkedHashSet<ResourceTagResponse>();
}
@Override
public String getObjectId() {
return this.getId();
@ -291,10 +304,22 @@ public class TemplateResponse extends BaseResponse implements ControlledEntityRe
this.details = details;
}
public void setTags(List<ResourceTagResponse> tags) {
public void setTags(Set<ResourceTagResponse> tags) {
this.tags = tags;
}
public void addTag(ResourceTagResponse tag){
this.tags.add(tag);
}
public void setZones(Set<TemplateZoneResponse> zones){
this.zones = zones;
}
public void addZone(TemplateZoneResponse zone){
this.zones.add(zone);
}
public void setSshKeyEnabled(boolean sshKeyEnabled) {
this.sshKeyEnabled = sshKeyEnabled;
}
@ -303,4 +328,7 @@ public class TemplateResponse extends BaseResponse implements ControlledEntityRe
this.isDynamicallyScalable = isDynamicallyScalable;
}
public String getZoneId() {
return zoneId;
}
}

View File

@ -0,0 +1,90 @@
// 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.api.response;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
public class TemplateZoneResponse extends BaseResponse {
@SerializedName(ApiConstants.ZONE_ID) @Param(description="the ID of the zone for the template")
private String zoneId;
@SerializedName(ApiConstants.ZONE_NAME) @Param(description="the name of the zone for the template")
private String zoneName;
public TemplateZoneResponse(){
super();
}
public TemplateZoneResponse(String zoneId, String zoneName){
super();
this.zoneId = zoneId;
this.zoneName = zoneName;
}
public String getZoneId() {
return zoneId;
}
public void setZoneId(String zoneId) {
this.zoneId = zoneId;
}
public String getZoneName() {
return zoneName;
}
public void setZoneName(String zoneName) {
this.zoneName = zoneName;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
String oid = this.getZoneId();
result = prime * result + ((oid== null) ? 0 : oid.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TemplateZoneResponse other = (TemplateZoneResponse) obj;
String oid = this.getZoneId();
if (oid == null) {
if (other.getZoneId() != null)
return false;
} else if (!oid.equals(other.getZoneId()))
return false;
else if ( this.getZoneName().equals(other.getZoneName()))
return false;
return true;
}
}

View File

@ -20,11 +20,13 @@ import org.apache.cloudstack.affinity.AffinityGroupResponse;
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
import org.apache.cloudstack.api.command.admin.internallb.ListInternalLBVMsCmd;
import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
import org.apache.cloudstack.api.command.admin.storage.ListImageStoresCmd;
import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
import org.apache.cloudstack.api.command.user.iso.ListIsosCmd;
import org.apache.cloudstack.api.command.user.job.ListAsyncJobsCmd;
import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd;
import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd;
@ -32,11 +34,33 @@ import org.apache.cloudstack.api.command.user.project.ListProjectInvitationsCmd;
import org.apache.cloudstack.api.command.user.project.ListProjectsCmd;
import org.apache.cloudstack.api.command.user.securitygroup.ListSecurityGroupsCmd;
import org.apache.cloudstack.api.command.user.tag.ListTagsCmd;
import org.apache.cloudstack.api.command.user.template.ListTemplatesCmd;
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd;
import org.apache.cloudstack.api.command.user.volume.ListResourceDetailsCmd;
import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.AsyncJobResponse;
import org.apache.cloudstack.api.response.DiskOfferingResponse;
import org.apache.cloudstack.api.response.DomainRouterResponse;
import org.apache.cloudstack.api.response.EventResponse;
import org.apache.cloudstack.api.response.HostResponse;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.api.response.InstanceGroupResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.ProjectAccountResponse;
import org.apache.cloudstack.api.response.ProjectInvitationResponse;
import org.apache.cloudstack.api.response.ProjectResponse;
import org.apache.cloudstack.api.response.ResourceTagResponse;
import org.apache.cloudstack.api.response.SecurityGroupResponse;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.TemplateResponse;
import org.apache.cloudstack.api.response.UserResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.response.VolumeResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.api.response.*;
import com.cloud.exception.PermissionDeniedException;
@ -75,6 +99,8 @@ public interface QueryService {
public ListResponse<StoragePoolResponse> searchForStoragePools(ListStoragePoolsCmd cmd);
public ListResponse<ImageStoreResponse> searchForImageStores(ListImageStoresCmd cmd);
public ListResponse<AccountResponse> searchForAccounts(ListAccountsCmd cmd);
public ListResponse<AsyncJobResponse> searchForAsyncJobs(ListAsyncJobsCmd cmd);
@ -85,6 +111,9 @@ public interface QueryService {
public ListResponse<ZoneResponse> listDataCenters(ListZonesByCmd cmd);
public ListResponse<TemplateResponse> listTemplates(ListTemplatesCmd cmd);
public ListResponse<TemplateResponse> listIsos(ListIsosCmd cmd);
public ListResponse<AffinityGroupResponse> listAffinityGroups(Long affinityGroupId, String affinityGroupName,
String affinityGroupType, Long vmId, String accountName, Long domainId, boolean isRecursive,
boolean listAll, Long startIndex, Long pageSize);

View File

@ -21,29 +21,29 @@ import junit.framework.TestCase;
import org.apache.cloudstack.api.ResponseGenerator;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.command.admin.host.AddSecondaryStorageCmd;
import org.apache.cloudstack.api.command.admin.storage.AddImageStoreCmd;
import org.apache.cloudstack.api.response.HostResponse;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
import com.cloud.host.Host;
import com.cloud.resource.ResourceService;
import edu.emory.mathcs.backport.java.util.Arrays;
import com.cloud.storage.ImageStore;
import com.cloud.storage.StorageService;
public class AddSecondaryStorageCmdTest extends TestCase {
private AddSecondaryStorageCmd addSecondaryStorageCmd;
private AddImageStoreCmd addImageStoreCmd;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Override
@Before
public void setUp() {
addSecondaryStorageCmd = new AddSecondaryStorageCmd() {
addImageStoreCmd = new AddImageStoreCmd() {
};
}
@ -51,69 +51,48 @@ public class AddSecondaryStorageCmdTest extends TestCase {
@Test
public void testExecuteForResult() throws Exception {
ResourceService resourceService = Mockito.mock(ResourceService.class);
addSecondaryStorageCmd._resourceService = resourceService;
StorageService resourceService = Mockito.mock(StorageService.class);
addImageStoreCmd._storageService = resourceService;
Host host = Mockito.mock(Host.class);
Host[] mockHosts = new Host[] { host };
ImageStore store = Mockito.mock(ImageStore.class);
Mockito.when(resourceService.discoverHosts(addSecondaryStorageCmd))
.thenReturn(Arrays.asList(mockHosts));
Mockito.when(resourceService.discoverImageStore(addImageStoreCmd))
.thenReturn(store);
ResponseGenerator responseGenerator = Mockito
.mock(ResponseGenerator.class);
addSecondaryStorageCmd._responseGenerator = responseGenerator;
addImageStoreCmd._responseGenerator = responseGenerator;
HostResponse responseHost = new HostResponse();
ImageStoreResponse responseHost = new ImageStoreResponse();
responseHost.setName("Test");
Mockito.when(responseGenerator.createHostResponse(host)).thenReturn(
Mockito.when(responseGenerator.createImageStoreResponse(store)).thenReturn(
responseHost);
addSecondaryStorageCmd.execute();
addImageStoreCmd.execute();
Mockito.verify(responseGenerator).createHostResponse(host);
Mockito.verify(responseGenerator).createImageStoreResponse(store);
HostResponse actualResponse = (HostResponse) addSecondaryStorageCmd
ImageStoreResponse actualResponse = (ImageStoreResponse) addImageStoreCmd
.getResponseObject();
Assert.assertEquals(responseHost, actualResponse);
Assert.assertEquals("addsecondarystorageresponse",
Assert.assertEquals("addimagestoreresponse",
actualResponse.getResponseName());
}
@Test
public void testExecuteForEmptyResult() throws Exception {
ResourceService resourceService = Mockito.mock(ResourceService.class);
addSecondaryStorageCmd._resourceService = resourceService;
Host[] mockHosts = new Host[] {};
Mockito.when(resourceService.discoverHosts(addSecondaryStorageCmd))
.thenReturn(Arrays.asList(mockHosts));
try {
addSecondaryStorageCmd.execute();
} catch (ServerApiException exception) {
Assert.assertEquals("Failed to add secondary storage",
exception.getDescription());
}
}
@Test
public void testExecuteForNullResult() throws Exception {
ResourceService resourceService = Mockito.mock(ResourceService.class);
addSecondaryStorageCmd._resourceService = resourceService;
StorageService resourceService = Mockito.mock(StorageService.class);
addImageStoreCmd._storageService = resourceService;
Mockito.when(resourceService.discoverHosts(addSecondaryStorageCmd))
Mockito.when(resourceService.discoverImageStore(addImageStoreCmd))
.thenReturn(null);
try {
addSecondaryStorageCmd.execute();
addImageStoreCmd.execute();
} catch (ServerApiException exception) {
Assert.assertEquals("Failed to add secondary storage",
exception.getDescription());

View File

@ -1,97 +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.api.command.test;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.cloudstack.api.ResponseGenerator;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.command.admin.swift.AddSwiftCmd;
import org.apache.cloudstack.api.response.SwiftResponse;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
import com.cloud.exception.DiscoveryException;
import com.cloud.resource.ResourceService;
import com.cloud.storage.Swift;
public class AddSwiftCmdTest extends TestCase {
private AddSwiftCmd addSwiftCmd;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
addSwiftCmd = new AddSwiftCmd();
}
@Test
public void testExecuteSuccess() {
ResourceService resourceService = Mockito.mock(ResourceService.class);
addSwiftCmd._resourceService = resourceService;
Swift swift = Mockito.mock(Swift.class);
try {
Mockito.when(resourceService.discoverSwift(addSwiftCmd))
.thenReturn(swift);
} catch (DiscoveryException e) {
e.printStackTrace();
}
ResponseGenerator responseGenerator = Mockito
.mock(ResponseGenerator.class);
addSwiftCmd._responseGenerator = responseGenerator;
SwiftResponse swiftResponse = Mockito.mock(SwiftResponse.class);
Mockito.when(responseGenerator.createSwiftResponse(swift)).thenReturn(
swiftResponse);
addSwiftCmd.execute();
}
@Test
public void testExecuteFailure() {
ResourceService resourceService = Mockito.mock(ResourceService.class);
addSwiftCmd._resourceService = resourceService;
try {
Mockito.when(resourceService.discoverSwift(addSwiftCmd))
.thenReturn(null);
} catch (DiscoveryException e) {
e.printStackTrace();
}
try {
addSwiftCmd.execute();
} catch (ServerApiException exception) {
Assert.assertEquals("Failed to add Swift",
exception.getDescription());
}
}
}

View File

@ -30,7 +30,7 @@
<artifactId>cloud-plugin-acl-static-role-based</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-dedicated-resources</artifactId>
<version>${project.version}</version>
@ -211,7 +211,7 @@
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-engine-storage-backup</artifactId>
<artifactId>cloud-engine-storage-cache</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -221,7 +221,7 @@
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-engine-storage-imagemotion</artifactId>
<artifactId>cloud-engine-storage-datamotion</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -244,6 +244,21 @@
<artifactId>cloud-plugin-storage-volume-default</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-storage-image-default</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-storage-image-s3</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-storage-image-swift</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-syslog-alerts</artifactId>

View File

@ -93,7 +93,7 @@
<entry key="cache.size" value="50" />
<entry key="cache.time.to.live" value="600" />
</map>
</property>
</property>
</bean>
<bean id="diskOfferingDaoImpl" class="com.cloud.storage.dao.DiskOfferingDaoImpl">
@ -156,7 +156,7 @@
<entry key="cache.size" value="100" />
<entry key="cache.time.to.live" value="600" />
</map>
</property>
</property>
</bean>
<bean id="dedicatedResourceDaoImpl" class="com.cloud.dc.dao.DedicatedResourceDaoImpl">
<property name="configParams">
@ -166,7 +166,7 @@
</map>
</property>
</bean>
<!--
DAOs with default configuration
-->
@ -198,7 +198,6 @@
<bean id="dataCenterJoinDaoImpl" class="com.cloud.api.query.dao.DataCenterJoinDaoImpl" />
<bean id="dataCenterLinkLocalIpAddressDaoImpl" class="com.cloud.dc.dao.DataCenterLinkLocalIpAddressDaoImpl" />
<bean id="dataCenterVnetDaoImpl" class="com.cloud.dc.dao.DataCenterVnetDaoImpl" />
<bean id="dataStoreProviderDaoImpl" class="org.apache.cloudstack.storage.datastore.db.DataStoreProviderDaoImpl" />
<bean id="dcDetailsDaoImpl" class="com.cloud.dc.dao.DcDetailsDaoImpl" />
<bean id="engineDcDetailsDaoImpl" class="org.apache.cloudstack.engine.datacenter.entity.api.db.dao.DcDetailsDaoImpl" />
<bean id="diskOfferingJoinDaoImpl" class="com.cloud.api.query.dao.DiskOfferingJoinDaoImpl" />
@ -221,6 +220,7 @@
<bean id="globalLoadBalancerLbRuleMapDaoImpl" class="org.apache.cloudstack.region.gslb.GlobalLoadBalancerLbRuleMapDaoImpl" />
<bean id="guestOSCategoryDaoImpl" class="com.cloud.storage.dao.GuestOSCategoryDaoImpl" />
<bean id="guestOSDaoImpl" class="com.cloud.storage.dao.GuestOSDaoImpl" />
<bean id="guestOSHypervisorDaoImpl" class="com.cloud.storage.dao.GuestOSHypervisorDaoImpl" />
<bean id="highAvailabilityDaoImpl" class="com.cloud.ha.dao.HighAvailabilityDaoImpl" />
<bean id="hostDaoImpl" class="com.cloud.host.dao.HostDaoImpl" />
<bean id="engineHostDetailsDaoImpl" class="org.apache.cloudstack.engine.datacenter.entity.api.db.dao.HostDetailsDaoImpl" />
@ -231,8 +231,13 @@
<bean id="hostTransferMapDaoImpl" class="com.cloud.cluster.agentlb.dao.HostTransferMapDaoImpl" />
<bean id="iPAddressDaoImpl" class="com.cloud.network.dao.IPAddressDaoImpl" />
<bean id="identityDaoImpl" class="com.cloud.uuididentity.dao.IdentityDaoImpl" />
<bean id="imageDaoStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.ImageDaoStoreDaoImpl" />
<bean id="imageDataStoreProviderDaoImpl" class="org.apache.cloudstack.storage.image.db.ImageDataStoreProviderDaoImpl" />
<bean id="imageStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.ImageStoreDaoImpl" />
<bean id="imageStoreDetailsDaoImpl" class="org.apache.cloudstack.storage.image.db.ImageStoreDetailsDaoImpl" />
<bean id="imageStoreJoinDaoImpl" class="com.cloud.api.query.dao.ImageStoreJoinDaoImpl" />
<bean id="snapshotDataStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.SnapshotDataStoreDaoImpl" />
<bean id="templateDataStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.TemplateDataStoreDaoImpl" />
<bean id="templateJoinDaoImpl" class="com.cloud.api.query.dao.TemplateJoinDaoImpl" />
<bean id="volumeDataStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.VolumeDataStoreDaoImpl" />
<bean id="inlineLoadBalancerNicMapDaoImpl" class="com.cloud.network.dao.InlineLoadBalancerNicMapDaoImpl" />
<bean id="instanceGroupDaoImpl" class="com.cloud.vm.dao.InstanceGroupDaoImpl" />
<bean id="instanceGroupJoinDaoImpl" class="com.cloud.api.query.dao.InstanceGroupJoinDaoImpl" />
@ -284,7 +289,7 @@
<bean id="portForwardingRulesDaoImpl" class="com.cloud.network.rules.dao.PortForwardingRulesDaoImpl" />
<bean id="portProfileDaoImpl" class="com.cloud.network.dao.PortProfileDaoImpl" />
<bean id="primaryDataStoreDaoImpl" class="org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl" />
<bean id="primaryDataStoreDetailsDaoImpl" class="org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDetailsDaoImpl" />
<bean id="primaryDataStoreDetailsDaoImpl" class="org.apache.cloudstack.storage.volume.db.PrimaryDataStoreDetailsDaoImpl" />
<bean id="privateIpDaoImpl" class="com.cloud.network.vpc.dao.PrivateIpDaoImpl" />
<bean id="projectAccountDaoImpl" class="com.cloud.projects.dao.ProjectAccountDaoImpl" />
<bean id="projectAccountJoinDaoImpl" class="com.cloud.api.query.dao.ProjectAccountJoinDaoImpl" />
@ -312,7 +317,6 @@
<bean id="site2SiteCustomerGatewayDaoImpl" class="com.cloud.network.dao.Site2SiteCustomerGatewayDaoImpl" />
<bean id="site2SiteVpnConnectionDaoImpl" class="com.cloud.network.dao.Site2SiteVpnConnectionDaoImpl" />
<bean id="site2SiteVpnGatewayDaoImpl" class="com.cloud.network.dao.Site2SiteVpnGatewayDaoImpl" />
<bean id="snapshotDao2Impl" class="org.apache.cloudstack.storage.snapshot.db.SnapshotDao2Impl" />
<bean id="snapshotDaoImpl" class="com.cloud.storage.dao.SnapshotDaoImpl" />
<bean id="snapshotPolicyDaoImpl" class="com.cloud.storage.dao.SnapshotPolicyDaoImpl" />
<bean id="snapshotScheduleDaoImpl" class="com.cloud.storage.dao.SnapshotScheduleDaoImpl" />
@ -368,7 +372,6 @@
<bean id="versionDaoImpl" class="com.cloud.upgrade.dao.VersionDaoImpl" />
<bean id="virtualRouterProviderDaoImpl" class="com.cloud.network.dao.VirtualRouterProviderDaoImpl" />
<bean id="vmRulesetLogDaoImpl" class="com.cloud.network.security.dao.VmRulesetLogDaoImpl" />
<bean id="volumeDao2Impl" class="org.apache.cloudstack.storage.volume.db.VolumeDao2Impl" />
<bean id="volumeDaoImpl" class="com.cloud.storage.dao.VolumeDaoImpl" />
<bean id="volumeDetailsDaoImpl" class="com.cloud.storage.dao.VolumeDetailsDaoImpl" />
<bean id="volumeHostDaoImpl" class="com.cloud.storage.dao.VolumeHostDaoImpl" />
@ -734,9 +737,10 @@
<bean id="agentMonitor" class="com.cloud.agent.manager.AgentMonitor" />
<bean id="alertGenerator" class="com.cloud.event.AlertGenerator" />
<bean id="ancientDataMotionStrategy" class="org.apache.cloudstack.storage.motion.AncientDataMotionStrategy" />
<bean id="storageCacheManagerImpl" class="org.apache.cloudstack.storage.cache.manager.StorageCacheManagerImpl" />
<bean id="storageCacheRandomAllocator" class="org.apache.cloudstack.storage.cache.allocator.StorageCacheRandomAllocator" />
<bean id="xenserverSnapshotStrategy" class="org.apache.cloudstack.storage.snapshot.XenserverSnapshotStrategy" />
<bean id="xenserverStorageMotionStrategy" class="org.apache.cloudstack.storage.motion.XenServerStorageMotionStrategy" />
<bean id="ancientImageDataStoreProvider" class="org.apache.cloudstack.storage.image.store.AncientImageDataStoreProvider" />
<bean id="ancientSnapshotStrategy" class="org.apache.cloudstack.storage.snapshot.strategy.AncientSnapshotStrategy" />
<bean id="apiDBUtils" class="com.cloud.api.ApiDBUtils" />
<bean id="apiDiscoveryServiceImpl" class="org.apache.cloudstack.discovery.ApiDiscoveryServiceImpl" />
<bean id="apiDispatcher" class="com.cloud.api.ApiDispatcher" />
@ -753,17 +757,15 @@
<bean id="dataObjectManagerImpl" class="org.apache.cloudstack.storage.datastore.DataObjectManagerImpl" />
<bean id="dataStoreManagerImpl" class="org.apache.cloudstack.storage.datastore.DataStoreManagerImpl" />
<bean id="defaultEndPointSelector" class="org.apache.cloudstack.storage.endpoint.DefaultEndPointSelector" />
<bean id="defaultPrimaryDataStoreProviderManagerImpl" class="org.apache.cloudstack.storage.datastore.manager.DefaultPrimaryDataStoreProviderManagerImpl" />
<bean id="primaryDataStoreProviderManagerImpl" class="org.apache.cloudstack.storage.datastore.manager.PrimaryDataStoreProviderManagerImpl" />
<bean id="imageStoreProviderManagerImpl" class="org.apache.cloudstack.storage.image.manager.ImageStoreProviderManagerImpl" />
<bean id="eventUtils" class="com.cloud.event.EventUtils" />
<bean id="hypervisorHostEndPointRpcServer" class="org.apache.cloudstack.storage.HypervisorHostEndPointRpcServer" />
<bean id="iSCSI" class="org.apache.cloudstack.storage.datastore.type.ISCSI" />
<bean id="ISO" class="org.apache.cloudstack.storage.image.format.ISO" />
<bean id="imageDataFactoryImpl" class="org.apache.cloudstack.storage.image.ImageDataFactoryImpl" />
<bean id="imageDataManagerImpl" class="org.apache.cloudstack.storage.image.manager.ImageDataManagerImpl" />
<bean id="imageDataStoreHelper" class="org.apache.cloudstack.storage.image.datastore.ImageDataStoreHelper" />
<bean id="imageDataStoreManagerImpl" class="org.apache.cloudstack.storage.image.manager.ImageDataStoreManagerImpl" />
<bean id="templateDataFactoryImpl" class="org.apache.cloudstack.storage.image.TemplateDataFactoryImpl" />
<bean id="imageStoreHelper" class="org.apache.cloudstack.storage.image.datastore.ImageStoreHelper" />
<bean id="imageFormatHelper" class="org.apache.cloudstack.storage.image.format.ImageFormatHelper" />
<bean id="imageServiceImpl" class="org.apache.cloudstack.storage.image.ImageServiceImpl" />
<bean id="templateServiceImpl" class="org.apache.cloudstack.storage.image.TemplateServiceImpl" />
<bean id="iso" class="org.apache.cloudstack.engine.subsystem.api.storage.type.Iso" />
<bean id="networkFileSystem" class="org.apache.cloudstack.storage.datastore.type.NetworkFileSystem" />
<bean id="networkRestService" class="org.apache.cloudstack.engine.rest.service.api.NetworkRestService" />
@ -780,7 +782,6 @@
<bean id="snapshotStateMachineManagerImpl" class="org.apache.cloudstack.storage.snapshot.SnapshotStateMachineManagerImpl" />
<bean id="statsCollector" class="com.cloud.server.StatsCollector" />
<bean id="storagePoolAutomationImpl" class="com.cloud.storage.StoragePoolAutomationImpl" />
<bean id="templateInstallStrategyImpl" class="org.apache.cloudstack.storage.volume.TemplateInstallStrategyImpl" />
<bean id="unknown" class="org.apache.cloudstack.storage.image.format.Unknown" />
<bean id="usageEventUtils" class="com.cloud.event.UsageEventUtils" />
<bean id="userContextInitializer" class="com.cloud.user.UserContextInitializer" />
@ -808,8 +809,12 @@
<bean id="vMSnapshotManagerImpl" class="com.cloud.vm.snapshot.VMSnapshotManagerImpl" />
<bean id="volumeManagerImpl" class="com.cloud.storage.VolumeManagerImpl" />
<bean id="ClassicalPrimaryDataStoreProvider" class="org.apache.cloudstack.storage.datastore.provider.CloudStackPrimaryDataStoreProviderImpl" />
<bean id="cloudStackImageStoreProviderImpl" class="org.apache.cloudstack.storage.datastore.provider.CloudStackImageStoreProviderImpl" />
<bean id="s3ImageStoreProviderImpl" class="org.apache.cloudstack.storage.datastore.provider.S3ImageStoreProviderImpl" />
<bean id="swiftImageStoreProviderImpl" class="org.apache.cloudstack.storage.datastore.provider.SwiftImageStoreProviderImpl" />
<bean id="ApplicationLoadBalancerService" class="org.apache.cloudstack.network.lb.ApplicationLoadBalancerManagerImpl" />
<bean id="InternalLoadBalancerVMManager" class="org.apache.cloudstack.network.lb.InternalLoadBalancerVMManagerImpl" />
<bean id="StorageCacheReplacementAlgorithm" class="org.apache.cloudstack.storage.cache.manager.StorageCacheReplacementAlgorithmLRU" />
<!--=======================================================================================================-->

View File

@ -249,6 +249,12 @@ listSwifts=1
addS3=1
listS3s=1
#### image store commands
addImageStore=1
listImageStores=1
deleteImageStore=1
createCacheStore=1
#### host commands
addHost=3
addCluster=1

View File

@ -132,6 +132,10 @@ under the License.
<priority value="INFO"/>
</category>
<category name="org.apache.cloudstack">
<priority value="DEBUG"/>
</category>
<category name="org.apache.cloudstack.api.command">
<priority value="TRACE"/>
</category>

View File

@ -22,39 +22,39 @@ import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.StartupCommand;
import com.cloud.exception.ConnectionException;
import com.cloud.host.HostVO;
import com.cloud.host.Host;
import com.cloud.host.Status;
/**
* There are several types of events that the AgentManager forwards
*
*
* 1. Agent Connect & Disconnect
* 2. Commands sent by the agent.
* 3. Answers sent by the agent.
*/
public interface Listener {
/**
*
* @param agentId id of the agent
* @param seq sequence number return by the send() method.
* @param answers answers to the commands.
* @return true if processed. false if not.
*/
/**
*
* @param agentId id of the agent
* @param seq sequence number return by the send() method.
* @param answers answers to the commands.
* @return true if processed. false if not.
*/
boolean processAnswers(long agentId, long seq, Answer[] answers);
/**
* This method is called by the AgentManager when an agent sent
* a command to the server. In order to process these commands,
* the Listener must be registered for host commands.
*
*
* @param agentId id of the agent.
* @param seq sequence number of the command sent.
* @param commands commands that were sent.
* @return true if you processed the commands. false if not.
*/
boolean processCommands(long agentId, long seq, Command[] commands);
/**
* process control command sent from agent under its management
* @param agentId
@ -72,26 +72,26 @@ public interface Listener {
* @param agentId id of the agent
* @throws ConnectionException if host has problems and needs to put into maintenance state.
*/
void processConnect(HostVO host, StartupCommand cmd, boolean forRebalance) throws ConnectionException;
void processConnect(Host host, StartupCommand cmd, boolean forRebalance) throws ConnectionException;
/**
* This method is called by AgentManager when an agent disconnects
* from this server if the listener has been registered for host events.
*
*
* If the Listener is passed to the send() method, this method is
* also called by AgentManager if the agent disconnected.
*
*
* @param agentId id of the agent
* @param state the current state of the agent.
*/
boolean processDisconnect(long agentId, Status state);
/**
* If this Listener is passed to the send() method, this method
* is called by AgentManager after processing an answer
* from the agent. Returning true means you're expecting more
* answers from the agent using the same sequence number.
*
*
* @return true if expecting more answers using the same sequence number.
*/
boolean isRecurring();
@ -102,7 +102,7 @@ public interface Listener {
* is in seconds. -1 indicates to wait forever. 0 indicates to
* use the default timeout. If the timeout is
* reached, processTimeout on this same Listener is called.
*
*
* @return timeout in seconds before processTimeout is called.
*/
int getTimeout();
@ -115,5 +115,5 @@ public interface Listener {
* @return true if processed; false if not.
*/
boolean processTimeout(long agentId, long seq);
}

View File

@ -1,75 +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 com.cloud.agent.api;
import java.util.List;
public class CleanupSnapshotBackupCommand extends Command {
private String secondaryStoragePoolURL;
private Long dcId;
private Long accountId;
private Long volumeId;
private List<String> validBackupUUIDs;
protected CleanupSnapshotBackupCommand() {
}
/*
* @param secondaryStoragePoolURL This is what shows up in the UI when you click on Secondary storage.
* In the code, it is present as: In the vmops.host_details table, there is a field mount.parent. This is the value of that field
* If you have better ideas on how to get it, you are welcome.
* @param validBackupUUID The VHD which are valid
*/
public CleanupSnapshotBackupCommand(String secondaryStoragePoolURL,
Long dcId,
Long accountId,
Long volumeId,
List<String> validBackupUUIDs)
{
this.secondaryStoragePoolURL = secondaryStoragePoolURL;
this.dcId = dcId;
this.accountId = accountId;
this.volumeId = volumeId;
this.validBackupUUIDs = validBackupUUIDs;
}
public String getSecondaryStoragePoolURL() {
return secondaryStoragePoolURL;
}
public Long getDcId() {
return dcId;
}
public Long getAccountId() {
return accountId;
}
public Long getVolumeId() {
return volumeId;
}
public List<String> getValidBackupUUIDs() {
return validBackupUUIDs;
}
@Override
public boolean executeInSequence() {
return false;
}
}

View File

@ -17,24 +17,32 @@
package com.cloud.agent.api;
import com.cloud.agent.api.storage.ssCommand;
import com.cloud.agent.api.to.DataStoreTO;
public class ComputeChecksumCommand extends ssCommand {
private DataStoreTO store;
private String templatePath;
public ComputeChecksumCommand() {
super();
}
public ComputeChecksumCommand(String secUrl, String templatePath) {
super(secUrl);
public ComputeChecksumCommand(DataStoreTO store, String templatePath) {
this.templatePath = templatePath;
this.setStore(store);
}
public String getTemplatePath() {
return templatePath;
}
public DataStoreTO getStore() {
return store;
}
public void setStore(DataStoreTO store) {
this.store = store;
}
}

View File

@ -1,61 +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 com.cloud.agent.api;
import com.cloud.agent.api.LogLevel.Log4jLevel;
import com.cloud.agent.api.to.SwiftTO;
/**
*
*
*/
public class DeleteObjectFromSwiftCommand extends Command {
@LogLevel(Log4jLevel.Off)
private SwiftTO swift;
private String container;
private String object;
protected DeleteObjectFromSwiftCommand() {
}
public DeleteObjectFromSwiftCommand(SwiftTO swift, String container, String object) {
this.swift = swift;
this.container = container;
this.object = object;
}
public SwiftTO getSwift() {
return this.swift;
}
public String getContainer() {
return container;
}
public String getObject() {
return object;
}
@Override
public boolean executeInSequence() {
// TODO Auto-generated method stub
return true;
}
}

View File

@ -1,96 +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 com.cloud.agent.api;
import com.cloud.agent.api.LogLevel.Log4jLevel;
import com.cloud.agent.api.to.S3TO;
import com.cloud.agent.api.to.SwiftTO;
import com.cloud.storage.StoragePool;
/**
* This command encapsulates a primitive operation which enables coalescing the backed up VHD snapshots on the secondary server
* This currently assumes that the secondary storage are mounted on the XenServer.
*/
public class DeleteSnapshotBackupCommand extends SnapshotCommand {
@LogLevel(Log4jLevel.Off)
private SwiftTO swift;
private S3TO s3;
private Boolean all;
public SwiftTO getSwift() {
return swift;
}
public Boolean isAll() {
return all;
}
public void setAll(Boolean all) {
this.all = all;
}
public void setSwift(SwiftTO swift) {
this.swift = swift;
}
public S3TO getS3() {
return s3;
}
protected DeleteSnapshotBackupCommand() {
}
/**
* Given 2 VHD files on the secondary storage which are linked in a parent chain as follows:
* backupUUID = parent(childUUID)
* It gets another VHD
* previousBackupVHD = parent(backupUUID)
*
* And
* 1) it coalesces backupUuid into its parent.
* 2) It deletes the VHD file corresponding to backupUuid
* 3) It sets the parent VHD of childUUID to that of previousBackupUuid
*
* It takes care of the cases when
* 1) childUUID is null. - Step 3 is not done.
* 2) previousBackupUUID is null
* - Merge childUUID into its parent backupUUID
* - Set the UUID of the resultant VHD to childUUID
* - Essentially we are deleting the oldest VHD file and setting the current oldest VHD to childUUID
*
* @param volumeName The name of the volume whose snapshot was taken (something like i-3-SV-ROOT)
* @param secondaryStoragePoolURL This is what shows up in the UI when you click on Secondary storage.
* In the code, it is present as: In the vmops.host_details table, there is a field mount.parent. This is the value of that field
* If you have better ideas on how to get it, you are welcome.
* @param backupUUID The VHD which has to be deleted
* @param childUUID The child VHD file of the backup whose parent is reset to its grandparent.
*/
public DeleteSnapshotBackupCommand(StoragePool pool,
SwiftTO swift,
S3TO s3,
String secondaryStoragePoolURL,
Long dcId,
Long accountId,
Long volumeId,
String backupUUID, Boolean all)
{
super(pool, secondaryStoragePoolURL, backupUUID, null, dcId, accountId, volumeId);
setSwift(swift);
this.s3 = s3;
setAll(all);
}
}

View File

@ -16,27 +16,23 @@
// under the License.
package com.cloud.agent.api;
import com.cloud.agent.api.to.DataStoreTO;
/**
* This command encapsulates a primitive operation which enables coalescing the backed up VHD snapshots on the secondary server
* This currently assumes that the secondary storage are mounted on the XenServer.
*/
public class DeleteSnapshotsDirCommand extends Command {
String secondaryStorageUrl;
Long dcId;
Long accountId;
Long volumeId;
DataStoreTO store;
String directory;
protected DeleteSnapshotsDirCommand() {
}
public DeleteSnapshotsDirCommand(String secondaryStorageUrl,
Long dcId, Long accountId, Long volumeId)
{
this.secondaryStorageUrl = secondaryStorageUrl;
this.dcId = dcId;
this.accountId = accountId;
this.volumeId = volumeId;
public DeleteSnapshotsDirCommand(DataStoreTO store, String dir) {
this.store = store;
this.directory = dir;
}
@Override
@ -44,20 +40,12 @@ public class DeleteSnapshotsDirCommand extends Command {
return true;
}
public String getSecondaryStorageUrl() {
return secondaryStorageUrl;
public DataStoreTO getDataStore() {
return store;
}
public Long getDcId() {
return dcId;
}
public Long getAccountId() {
return accountId;
public String getDirectory() {
return directory;
}
public Long getVolumeId() {
return volumeId;
}
}

View File

@ -1,106 +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 com.cloud.agent.api;
import com.cloud.agent.api.to.S3TO;
public class DeleteTemplateFromS3Command extends Command {
private S3TO s3;
private Long templateId;
private Long accountId;
protected DeleteTemplateFromS3Command() {
super();
}
public DeleteTemplateFromS3Command(final S3TO s3, final Long accountId,
final Long templateId) {
super();
this.s3 = s3;
this.accountId = accountId;
this.templateId = templateId;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((accountId == null) ? 0 : accountId.hashCode());
result = prime * result + ((s3 == null) ? 0 : s3.hashCode());
result = prime * result
+ ((templateId == null) ? 0 : templateId.hashCode());
return result;
}
@Override
public boolean equals(Object thatObject) {
if (this == thatObject) {
return true;
}
if (thatObject == null) {
return false;
}
if (getClass() != thatObject.getClass()) {
return false;
}
final DeleteTemplateFromS3Command thatCommand = (DeleteTemplateFromS3Command) thatObject;
if (!(accountId == thatCommand.accountId)
|| (this.accountId != null && this.accountId
.equals(thatCommand.accountId))) {
return false;
}
if (!(templateId == thatCommand.templateId)
|| (this.templateId != null && this.templateId
.equals(thatCommand.templateId))) {
return false;
}
return true;
}
public S3TO getS3() {
return s3;
}
public Long getTemplateId() {
return templateId;
}
public Long getAccountId() {
return accountId;
}
@Override
public boolean executeInSequence() {
return true;
}
}

View File

@ -17,23 +17,27 @@
package com.cloud.agent.api;
import java.util.List;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
import com.cloud.agent.api.to.DiskTO;
import com.cloud.agent.api.to.VolumeTO;
public class MigrateWithStorageAnswer extends Answer {
List<VolumeTO> volumeTos;
List<VolumeObjectTO> volumeTos;
public MigrateWithStorageAnswer(MigrateWithStorageCommand cmd, Exception ex) {
super(cmd, ex);
volumeTos = null;
}
public MigrateWithStorageAnswer(MigrateWithStorageCommand cmd, List<VolumeTO> volumeTos) {
public MigrateWithStorageAnswer(MigrateWithStorageCommand cmd, List<VolumeObjectTO> volumeTos) {
super(cmd, true, null);
this.volumeTos = volumeTos;
}
public List<VolumeTO> getVolumeTos() {
public List<VolumeObjectTO> getVolumeTos() {
return volumeTos;
}
}

View File

@ -17,22 +17,25 @@
package com.cloud.agent.api;
import java.util.List;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
import com.cloud.agent.api.to.VolumeTO;
public class MigrateWithStorageCompleteAnswer extends Answer {
List<VolumeTO> volumeTos;
List<VolumeObjectTO> volumeTos;
public MigrateWithStorageCompleteAnswer(MigrateWithStorageCompleteCommand cmd, Exception ex) {
super(cmd, ex);
volumeTos = null;
}
public MigrateWithStorageCompleteAnswer(MigrateWithStorageCompleteCommand cmd, List<VolumeTO> volumeTos) {
public MigrateWithStorageCompleteAnswer(MigrateWithStorageCompleteCommand cmd, List<VolumeObjectTO> volumeTos) {
super(cmd, true, null);
this.volumeTos = volumeTos;
}
public List<VolumeTO> getVolumeTos() {
public List<VolumeObjectTO> getVolumeTos() {
return volumeTos;
}
}

View File

@ -18,16 +18,16 @@ package com.cloud.agent.api;
import java.util.Map;
import com.cloud.storage.template.TemplateInfo;
import com.cloud.storage.template.TemplateProp;
public class ModifyStoragePoolAnswer extends Answer {
StoragePoolInfo poolInfo;
Map<String, TemplateInfo> templateInfo;
Map<String, TemplateProp> templateInfo;
protected ModifyStoragePoolAnswer() {
}
public ModifyStoragePoolAnswer(ModifyStoragePoolCommand cmd, long capacityBytes, long availableBytes, Map<String, TemplateInfo> tInfo) {
public ModifyStoragePoolAnswer(ModifyStoragePoolCommand cmd, long capacityBytes, long availableBytes, Map<String, TemplateProp> tInfo) {
super(cmd);
this.result = true;
this.poolInfo = new StoragePoolInfo(null,
@ -46,11 +46,11 @@ public class ModifyStoragePoolAnswer extends Answer {
}
public Map<String, TemplateInfo> getTemplateInfo() {
public Map<String, TemplateProp> getTemplateInfo() {
return templateInfo;
}
public void setTemplateInfo(Map<String, TemplateInfo> templateInfo) {
public void setTemplateInfo(Map<String, TemplateProp> templateInfo) {
this.templateInfo = templateInfo;
}

View File

@ -17,8 +17,10 @@
package com.cloud.agent.api;
import com.cloud.agent.api.LogLevel.Log4jLevel;
import com.cloud.agent.api.to.DataStoreTO;
public class SecStorageSetupCommand extends Command {
private DataStoreTO store;
private String secUrl;
private Certificates certs;
@ -57,10 +59,11 @@ public class SecStorageSetupCommand extends Command {
super();
}
public SecStorageSetupCommand(String secUrl, Certificates certs) {
public SecStorageSetupCommand(DataStoreTO store, String secUrl, Certificates certs) {
super();
this.secUrl = secUrl;
this.certs = certs;
this.store = store;
}
@Override
@ -80,4 +83,14 @@ public class SecStorageSetupCommand extends Command {
this.secUrl = secUrl;
}
public DataStoreTO getDataStore() {
return store;
}
public void setDataStore(DataStoreTO store) {
this.store = store;
}
}

View File

@ -53,8 +53,8 @@ public class SnapshotCommand extends Command {
public SnapshotCommand(StoragePool pool,
String secondaryStorageUrl, String snapshotUuid,
String snapshotName, Long dcId, Long accountId, Long volumeId) {
this.primaryStoragePoolNameLabel = pool.getUuid();
this.primaryPool = new StorageFilerTO(pool);
// this.primaryStoragePoolNameLabel = pool.getUuid();
//this.primaryPool = new StorageFilerTO(pool);
this.snapshotUuid = snapshotUuid;
this.secondaryStorageUrl = secondaryStorageUrl;
this.dcId = dcId;

View File

@ -22,13 +22,13 @@ import java.util.Map;
import com.cloud.host.Host;
import com.cloud.storage.Storage;
import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.storage.template.TemplateInfo;
import com.cloud.storage.template.TemplateProp;
public class StartupStorageCommand extends StartupCommand {
String parent;
Map<String, TemplateInfo> templateInfo;
Map<String, TemplateProp> templateInfo;
long totalSize;
StoragePoolInfo poolInfo;
Storage.StorageResourceType resourceType;
@ -40,7 +40,7 @@ public class StartupStorageCommand extends StartupCommand {
super(Host.Type.Storage);
}
public StartupStorageCommand(String parent, StoragePoolType fsType, long totalSize, Map<String, TemplateInfo> info) {
public StartupStorageCommand(String parent, StoragePoolType fsType, long totalSize, Map<String, TemplateProp> info) {
super(Host.Type.Storage);
this.parent = parent;
this.totalSize = totalSize;
@ -50,7 +50,7 @@ public class StartupStorageCommand extends StartupCommand {
}
public StartupStorageCommand(String parent, StoragePoolType fsType, Map<String, TemplateInfo> templateInfo, StoragePoolInfo poolInfo) {
public StartupStorageCommand(String parent, StoragePoolType fsType, Map<String, TemplateProp> templateInfo, StoragePoolInfo poolInfo) {
super(Host.Type.Storage);
this.parent = parent;
this.templateInfo = templateInfo;
@ -79,11 +79,11 @@ public class StartupStorageCommand extends StartupCommand {
return totalSize;
}
public Map<String, TemplateInfo> getTemplateInfo() {
public Map<String, TemplateProp> getTemplateInfo() {
return templateInfo;
}
public void setTemplateInfo(Map<String, TemplateInfo> templateInfo) {
public void setTemplateInfo(Map<String, TemplateProp> templateInfo) {
this.templateInfo = templateInfo;
}

View File

@ -28,7 +28,7 @@ public abstract class AbstractDownloadCommand extends ssCommand {
protected AbstractDownloadCommand() {
}
protected AbstractDownloadCommand(String name, String url, ImageFormat format, long accountId) {
protected AbstractDownloadCommand(String name, String url, ImageFormat format, Long accountId) {
assert(url != null);
url = url.replace('\\', '/');

View File

@ -24,6 +24,7 @@ public class CopyVolumeAnswer extends Answer {
private String volumePath;
protected CopyVolumeAnswer() {
super();
}
public CopyVolumeAnswer(Command command, boolean success, String details, String volumeFolder, String volumePath) {

View File

@ -23,6 +23,7 @@ public class CreateAnswer extends Answer {
VolumeTO volume;
boolean requestTemplateReload = false;
protected CreateAnswer() {
super();
}
public CreateAnswer(CreateCommand cmd, VolumeTO volume) {

View File

@ -27,7 +27,9 @@ public class CreatePrivateTemplateAnswer extends Answer {
private String _uniqueName;
private ImageFormat _format;
public CreatePrivateTemplateAnswer() {}
public CreatePrivateTemplateAnswer() {
super();
}
public CreatePrivateTemplateAnswer(Command cmd, boolean success, String result, String path, long virtualSize,
long physicalSize, String uniqueName, ImageFormat format) {

View File

@ -19,27 +19,27 @@ package com.cloud.agent.api.storage;
import java.util.Map;
import com.cloud.agent.api.Answer;
import com.cloud.storage.template.TemplateInfo;
import com.cloud.storage.template.TemplateProp;
public class ListTemplateAnswer extends Answer {
private String secUrl;
private Map<String, TemplateInfo> templateInfos;
private Map<String, TemplateProp> templateInfos;
public ListTemplateAnswer() {
super();
}
public ListTemplateAnswer(String secUrl, Map<String, TemplateInfo> templateInfos) {
public ListTemplateAnswer(String secUrl, Map<String, TemplateProp> templateInfos) {
super(null, true, "success");
this.setSecUrl(secUrl);
this.templateInfos = templateInfos;
}
public Map<String, TemplateInfo> getTemplateInfo() {
public Map<String, TemplateProp> getTemplateInfo() {
return templateInfos;
}
public void setTemplateInfo(Map<String, TemplateInfo> templateInfos) {
public void setTemplateInfo(Map<String, TemplateProp> templateInfos) {
this.templateInfos = templateInfos;
}

View File

@ -16,39 +16,32 @@
// under the License.
package com.cloud.agent.api.storage;
import com.cloud.agent.api.LogLevel;
import com.cloud.agent.api.LogLevel.Log4jLevel;
import com.cloud.agent.api.to.SwiftTO;
import com.cloud.agent.api.to.DataStoreTO;
public class ListTemplateCommand extends StorageCommand {
private String secUrl;
@LogLevel(Log4jLevel.Off)
private SwiftTO swift;
private DataStoreTO store;
//private String secUrl;
public ListTemplateCommand() {
}
public ListTemplateCommand(String secUrl) {
this.secUrl = secUrl;
this.swift = null;
public ListTemplateCommand(DataStoreTO store) {
this.store = store;
// this.secUrl = url;
}
public ListTemplateCommand(SwiftTO swift) {
this.secUrl = null;
this.swift = swift;
}
@Override
public boolean executeInSequence() {
return true;
}
public String getSecUrl() {
return secUrl;
public DataStoreTO getDataStore() {
return store;
}
public SwiftTO getSwift() {
return swift;
}
// public String getSecUrl() {
// return secUrl;
// }
}

View File

@ -19,27 +19,27 @@ package com.cloud.agent.api.storage;
import java.util.Map;
import com.cloud.agent.api.Answer;
import com.cloud.storage.template.TemplateInfo;
import com.cloud.storage.template.TemplateProp;
public class ListVolumeAnswer extends Answer {
private String secUrl;
private Map<Long, TemplateInfo> templateInfos;
private Map<Long, TemplateProp> templateInfos;
public ListVolumeAnswer() {
super();
}
public ListVolumeAnswer(String secUrl, Map<Long, TemplateInfo> templateInfos) {
public ListVolumeAnswer(String secUrl, Map<Long, TemplateProp> templateInfos) {
super(null, true, "success");
this.setSecUrl(secUrl);
this.templateInfos = templateInfos;
}
public Map<Long, TemplateInfo> getTemplateInfo() {
public Map<Long, TemplateProp> getTemplateInfo() {
return templateInfos;
}
public void setTemplateInfo(Map<Long, TemplateInfo> templateInfos) {
public void setTemplateInfo(Map<Long, TemplateProp> templateInfos) {
this.templateInfos = templateInfos;
}

View File

@ -16,15 +16,19 @@
// under the License.
package com.cloud.agent.api.storage;
import com.cloud.agent.api.to.DataStoreTO;
public class ListVolumeCommand extends StorageCommand {
private DataStoreTO store;
private String secUrl;
public ListVolumeCommand() {
}
public ListVolumeCommand(String secUrl) {
public ListVolumeCommand(DataStoreTO store, String secUrl) {
this.store = store;
this.secUrl = secUrl;
}
@ -37,4 +41,7 @@ public class ListVolumeCommand extends StorageCommand {
return secUrl;
}
public DataStoreTO getDataStore() {
return store;
}
}

View File

@ -22,6 +22,7 @@ import com.cloud.agent.api.Command;
public class ManageVolumeAvailabilityAnswer extends Answer {
protected ManageVolumeAvailabilityAnswer() {
super();
}
public ManageVolumeAvailabilityAnswer(Command command, boolean success, String details) {

View File

@ -23,6 +23,7 @@ public class PrimaryStorageDownloadAnswer extends Answer {
private long templateSize = 0L;
protected PrimaryStorageDownloadAnswer() {
super();
}
public PrimaryStorageDownloadAnswer(String detail) {

View File

@ -34,7 +34,16 @@ public class PrimaryStorageDownloadCommand extends AbstractDownloadCommand {
String primaryStorageUrl;
protected PrimaryStorageDownloadCommand() {
}
public PrimaryStorageDownloadCommand(String url, StoragePool pool, int wait) {
super(null, url, null, null);
this.poolId = pool.getId();
this.poolUuid = pool.getUuid();
this.primaryPool = new StorageFilerTO(pool);
setWait(wait);
}
public PrimaryStorageDownloadCommand(String name, String url, ImageFormat format, long accountId, StoragePool pool, int wait) {
super(name, url, format, accountId);

View File

@ -22,7 +22,7 @@ public class ResizeVolumeAnswer extends Answer {
private long newSize;
protected ResizeVolumeAnswer() {
super();
}
public ResizeVolumeAnswer(ResizeVolumeCommand cmd, boolean result, String details, long newSize) {

View File

@ -21,7 +21,9 @@ import com.cloud.agent.api.Command;
public class UpgradeDiskAnswer extends Answer {
public UpgradeDiskAnswer() {}
public UpgradeDiskAnswer() {
super();
}
public UpgradeDiskAnswer(Command cmd, boolean success, String details) {
super(cmd, success, details);

View File

@ -18,7 +18,6 @@ package com.cloud.agent.api.storage;
import org.apache.cloudstack.api.InternalIdentity;
import com.cloud.agent.api.storage.DownloadCommand.PasswordAuth;
import com.cloud.agent.api.to.TemplateTO;
import com.cloud.storage.Upload.Type;
import com.cloud.template.VirtualMachineTemplate;

View File

@ -39,8 +39,6 @@ public class ArrayTypeAdaptor<T> implements JsonDeserializer<T[]>, JsonSerialize
protected Gson _gson = null;
private static final String s_pkg = Command.class.getPackage().getName() + ".";
public ArrayTypeAdaptor() {
}
@ -53,7 +51,7 @@ public class ArrayTypeAdaptor<T> implements JsonDeserializer<T[]>, JsonSerialize
JsonArray array = new JsonArray();
for (T cmd : src) {
JsonObject obj = new JsonObject();
obj.add(cmd.getClass().getName().substring(s_pkg.length()), _gson.toJsonTree(cmd));
obj.add(cmd.getClass().getName(), _gson.toJsonTree(cmd));
array.add(obj);
}
@ -71,7 +69,7 @@ public class ArrayTypeAdaptor<T> implements JsonDeserializer<T[]>, JsonSerialize
JsonObject element = (JsonObject)it.next();
Map.Entry<String, JsonElement> entry = element.entrySet().iterator().next();
String name = s_pkg + entry.getKey();
String name = entry.getKey();
Class<?> clazz;
try {
clazz = Class.forName(name);

View File

@ -0,0 +1,66 @@
// 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.agent.transport;
import java.lang.reflect.Type;
import java.util.Map;
import com.cloud.utils.exception.CloudRuntimeException;
import com.google.gson.Gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
public class InterfaceTypeAdaptor<T> implements JsonDeserializer<T>, JsonSerializer<T> {
protected Gson _gson = null;
public InterfaceTypeAdaptor() {
}
public void initGson(Gson gson) {
_gson = gson;
}
@Override
public JsonElement serialize(T src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject obj = new JsonObject();
obj.add(src.getClass().getName(), _gson.toJsonTree(src));
return obj;
}
@Override
@SuppressWarnings("unchecked")
public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
JsonObject element = (JsonObject) json;
Map.Entry<String, JsonElement> entry = element.entrySet().iterator().next();
String name = entry.getKey();
Class<?> clazz;
try {
clazz = Class.forName(name);
} catch (ClassNotFoundException e) {
throw new CloudRuntimeException("can't find " + name);
}
return (T) _gson.fromJson(entry.getValue(), clazz);
}
}

View File

@ -105,7 +105,7 @@ import com.cloud.resource.ServerResource;
import com.cloud.resource.ServerResourceBase;
import com.cloud.serializer.GsonHelper;
import com.cloud.storage.Volume;
import com.cloud.storage.template.TemplateInfo;
import com.cloud.storage.template.TemplateProp;
import com.cloud.utils.Pair;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.DiskProfile;
@ -765,7 +765,7 @@ public class HypervResource extends ServerResourceBase implements ServerResource
try {
StorageFilerTO pool = cmd.getPool();
s_logger.info("Primary storage pool details: " + pool.getHost() + " " + pool.getPath());
Map<String, TemplateInfo> tInfo = new HashMap<String, TemplateInfo>();
Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
// FIXME: get the actual storage capacity and storage stats of CSV volume
// by running powershell cmdlet. This hardcoding just for prototype.
ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd,

View File

@ -25,7 +25,10 @@ import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.SecStorageFirewallCfgCommand.PortConfig;
import com.cloud.agent.api.to.DataStoreTO;
import com.cloud.agent.api.to.DataTO;
import com.cloud.agent.transport.ArrayTypeAdaptor;
import com.cloud.agent.transport.InterfaceTypeAdaptor;
import com.cloud.agent.transport.LoggingExclusionStrategy;
import com.cloud.agent.transport.Request.NwGroupsCommandTypeAdaptor;
import com.cloud.agent.transport.Request.PortConfigListTypeAdaptor;
@ -52,6 +55,10 @@ public class GsonHelper {
static Gson setDefaultGsonConfig(GsonBuilder builder) {
builder.setVersion(1.5);
InterfaceTypeAdaptor<DataStoreTO> dsAdaptor = new InterfaceTypeAdaptor<DataStoreTO>();
builder.registerTypeAdapter(DataStoreTO.class, dsAdaptor);
InterfaceTypeAdaptor<DataTO> dtAdaptor = new InterfaceTypeAdaptor<DataTO>();
builder.registerTypeAdapter(DataTO.class, dtAdaptor);
ArrayTypeAdaptor<Command> cmdAdaptor = new ArrayTypeAdaptor<Command>();
builder.registerTypeAdapter(Command[].class, cmdAdaptor);
ArrayTypeAdaptor<Answer> ansAdaptor = new ArrayTypeAdaptor<Answer>();
@ -61,6 +68,8 @@ public class GsonHelper {
builder.registerTypeAdapter(new TypeToken<Pair<Long, Long>>() {
}.getType(), new NwGroupsCommandTypeAdaptor());
Gson gson = builder.create();
dsAdaptor.initGson(gson);
dtAdaptor.initGson(gson);
cmdAdaptor.initGson(gson);
ansAdaptor.initGson(gson);
return gson;

View File

@ -0,0 +1,73 @@
// 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.storage;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="guest_os_hypervisor")
public class GuestOSHypervisorVO implements GuestOSHypervisor {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
long id;
@Column(name="guest_os_id")
private long guestOsId;
@Column(name="guest_os_name")
String guestOsName;
@Column(name="hypervisor_type")
String hypervisorType;
@Override
public long getId() {
return id;
}
@Override
public String getHypervisorType() {
return hypervisorType;
}
@Override
public String getGuestOsName() {
return guestOsName;
}
@Override
public long getGuestOsId() {
return guestOsId;
}
}

View File

@ -0,0 +1,45 @@
/*
* 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.storage.resource;
import org.apache.cloudstack.storage.command.AttachCommand;
import org.apache.cloudstack.storage.command.CopyCommand;
import org.apache.cloudstack.storage.command.CreateObjectCommand;
import org.apache.cloudstack.storage.command.DeleteCommand;
import org.apache.cloudstack.storage.command.DettachCommand;
import com.cloud.agent.api.Answer;
public interface StorageProcessor {
public Answer copyTemplateToPrimaryStorage(CopyCommand cmd);
public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd);
public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd);
public Answer copyVolumeFromPrimaryToSecondary(CopyCommand cmd);
public Answer createTemplateFromVolume(CopyCommand cmd);
public Answer backupSnasphot(CopyCommand cmd);
public Answer attachIso(AttachCommand cmd);
public Answer attachVolume(AttachCommand cmd);
public Answer dettachIso(DettachCommand cmd);
public Answer dettachVolume(DettachCommand cmd);
public Answer createVolume(CreateObjectCommand cmd);
public Answer createSnapshot(CreateObjectCommand cmd);
public Answer deleteVolume(DeleteCommand cmd);
public Answer createVolumeFromSnapshot(CopyCommand cmd);
public Answer deleteSnapshot(DeleteCommand cmd);
}

View File

@ -16,14 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.storage.image;
package com.cloud.storage.resource;
public interface ImageOrchestrator {
void registerTemplate(long templateId);
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
void registerSnapshot(long snapshotId);
import com.cloud.agent.api.Answer;
void registerVolume(long volumeId);
void registerIso(long isoId);
public interface StorageSubsystemCommandHandler {
public Answer handleStorageCommands(StorageSubSystemCommand command);
}

View File

@ -0,0 +1,139 @@
/*
* 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.storage.resource;
import org.apache.cloudstack.storage.command.AttachCommand;
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.DettachCommand;
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.to.DataObjectType;
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.storage.DataStoreRole;
import com.cloud.storage.Volume;
public class StorageSubsystemCommandHandlerBase implements StorageSubsystemCommandHandler {
private static final Logger s_logger = Logger.getLogger(StorageSubsystemCommandHandlerBase.class);
private StorageProcessor processor;
public StorageSubsystemCommandHandlerBase(StorageProcessor processor) {
this.processor = processor;
}
@Override
public Answer handleStorageCommands(StorageSubSystemCommand command) {
if (command instanceof CopyCommand) {
return this.execute((CopyCommand)command);
} else if (command instanceof CreateObjectCommand) {
return execute((CreateObjectCommand) command);
} else if (command instanceof DeleteCommand) {
return execute((DeleteCommand)command);
} else if (command instanceof AttachCommand) {
return execute((AttachCommand)command);
} else if (command instanceof DettachCommand) {
return execute((DettachCommand)command);
}
return new Answer((Command)command, false, "not implemented yet");
}
protected Answer execute(CopyCommand cmd) {
DataTO srcData = cmd.getSrcTO();
DataTO destData = cmd.getDestTO();
DataStoreTO srcDataStore = srcData.getDataStore();
DataStoreTO destDataStore = destData.getDataStore();
if ((srcData.getObjectType() == DataObjectType.TEMPLATE) && (srcDataStore instanceof NfsTO) && (destData.getDataStore().getRole() == DataStoreRole.Primary)) {
//copy template to primary storage
return processor.copyTemplateToPrimaryStorage(cmd);
} else if (srcData.getObjectType() == DataObjectType.TEMPLATE && srcDataStore.getRole() == DataStoreRole.Primary && destDataStore.getRole() == DataStoreRole.Primary) {
//clone template to a volume
return processor.cloneVolumeFromBaseTemplate(cmd);
} else if (srcData.getObjectType() == DataObjectType.VOLUME && (srcData.getDataStore().getRole() == DataStoreRole.ImageCache || srcDataStore.getRole() == DataStoreRole.Image)) {
//copy volume from image cache to primary
return processor.copyVolumeFromImageCacheToPrimary(cmd);
} else if (srcData.getObjectType() == DataObjectType.VOLUME && srcData.getDataStore().getRole() == DataStoreRole.Primary) {
if (destData.getObjectType() == DataObjectType.VOLUME) {
return processor.copyVolumeFromPrimaryToSecondary(cmd);
} else if (destData.getObjectType() == DataObjectType.TEMPLATE) {
return processor.createTemplateFromVolume(cmd);
}
} else if (srcData.getObjectType() == DataObjectType.SNAPSHOT && srcData.getDataStore().getRole() == DataStoreRole.Primary) {
return processor.backupSnasphot(cmd);
} else if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.VOLUME) {
return processor.createVolumeFromSnapshot(cmd);
}
return new Answer(cmd, false, "not implemented yet");
}
protected Answer execute(CreateObjectCommand cmd) {
DataTO data = cmd.getData();
try {
if (data.getObjectType() == DataObjectType.VOLUME) {
return processor.createVolume(cmd);
} else if (data.getObjectType() == DataObjectType.SNAPSHOT) {
return processor.createSnapshot(cmd);
}
return new CreateObjectAnswer("not supported type");
} catch (Exception e) {
s_logger.debug("Failed to create object: " + data.getObjectType() + ": " + e.toString());
return new CreateObjectAnswer(e.toString());
}
}
protected Answer execute(DeleteCommand cmd) {
DataTO data = cmd.getData();
Answer answer = null;
if (data.getObjectType() == DataObjectType.VOLUME) {
answer = processor.deleteVolume(cmd);
} else if (data.getObjectType() == DataObjectType.SNAPSHOT) {
answer = processor.deleteSnapshot(cmd);
} else {
answer = new Answer(cmd, false, "unsupported type");
}
return answer;
}
protected Answer execute(AttachCommand cmd) {
DiskTO disk = cmd.getDisk();
if (disk.getType() == Volume.Type.ISO) {
return processor.attachIso(cmd);
} else {
return processor.attachVolume(cmd);
}
}
protected Answer execute(DettachCommand cmd) {
DiskTO disk = cmd.getDisk();
if (disk.getType() == Volume.Type.ISO) {
return processor.dettachIso(cmd);
} else {
return processor.dettachVolume(cmd);
}
}
}

Some files were not shown because too many files have changed in this diff Show More