From e54fc088623710387acc5d55eca67b8a63858ea6 Mon Sep 17 00:00:00 2001 From: Abhinandan Prateek Date: Tue, 1 Nov 2011 17:56:28 +0530 Subject: [PATCH] bug 11791: adding Hypervisor type to list os API --- .../cloud/api/commands/ListGuestOsCmd.java | 16 +++- .../com/cloud/server/ManagementService.java | 3 +- .../cloud/storage/GuestOSHypervisorVO.java | 91 +++++++++++++++++++ .../DefaultComponentLibrary.java | 2 + .../com/cloud/server/ManagementServer.java | 4 + .../cloud/server/ManagementServerImpl.java | 18 +++- .../storage/dao/GuestOSHypervisorDao.java | 33 +++++++ .../storage/dao/GuestOSHypervisorDaoImpl.java | 53 +++++++++++ 8 files changed, 216 insertions(+), 4 deletions(-) create mode 100644 core/src/com/cloud/storage/GuestOSHypervisorVO.java create mode 100644 server/src/com/cloud/storage/dao/GuestOSHypervisorDao.java create mode 100644 server/src/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java diff --git a/api/src/com/cloud/api/commands/ListGuestOsCmd.java b/api/src/com/cloud/api/commands/ListGuestOsCmd.java index 6548de98ddf..8f6e4b076e3 100644 --- a/api/src/com/cloud/api/commands/ListGuestOsCmd.java +++ b/api/src/com/cloud/api/commands/ListGuestOsCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.ApiConstants; import com.cloud.api.BaseListCmd; import com.cloud.api.Implementation; import com.cloud.api.Parameter; +import com.cloud.api.BaseCmd.CommandType; import com.cloud.api.response.GuestOSResponse; import com.cloud.api.response.ListResponse; import com.cloud.storage.GuestOS; @@ -47,6 +48,8 @@ public class ListGuestOsCmd extends BaseListCmd { @Parameter(name=ApiConstants.OS_CATEGORY_ID, type=CommandType.LONG, description="list by Os Category id") private Long osCategoryId; + @Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, description="the hypervisor for which to restrict the search") + private String hypervisor; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -60,7 +63,9 @@ public class ListGuestOsCmd extends BaseListCmd { return osCategoryId; } - + public String getHypervisor() { + return hypervisor; + } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -72,7 +77,14 @@ public class ListGuestOsCmd extends BaseListCmd { @Override public void execute(){ - List result = _mgr.listGuestOSByCriteria(this); + List result = null; + if (getHypervisor() == null){ + result = _mgr.listGuestOSByCriteria(this); + } + else { + result = _mgr.listGuestOSByHypervisor(this); + } + ListResponse response = new ListResponse(); List osResponses = new ArrayList(); for (GuestOS guestOS : result) { diff --git a/api/src/com/cloud/server/ManagementService.java b/api/src/com/cloud/server/ManagementService.java index bdf0646000c..b96ca58681f 100644 --- a/api/src/com/cloud/server/ManagementService.java +++ b/api/src/com/cloud/server/ManagementService.java @@ -221,6 +221,7 @@ public interface ManagementService { * @return list of GuestOS */ List listGuestOSByCriteria(ListGuestOsCmd cmd); + List listGuestOSByHypervisor(ListGuestOsCmd listGuestOsCmd); /** * Obtains a list of all guest OS categories. @@ -489,5 +490,5 @@ public interface ManagementService { String[] listEventTypes(); - + } diff --git a/core/src/com/cloud/storage/GuestOSHypervisorVO.java b/core/src/com/cloud/storage/GuestOSHypervisorVO.java new file mode 100644 index 00000000000..5688a62c631 --- /dev/null +++ b/core/src/com/cloud/storage/GuestOSHypervisorVO.java @@ -0,0 +1,91 @@ +/** + * Copyright (C) 2011 Citrix.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package com.cloud.storage; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.hypervisor.Hypervisor.HypervisorType; + +@Entity +@Table(name="guest_os_hypervisor") +public class GuestOSHypervisorVO implements GuestOS { + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + @Column(name="id") + long id; + + @Column(name="hypervisor_type", updatable = true, nullable=false) + @Enumerated(value=EnumType.STRING) + HypervisorType hypervisorType; + + @Column(name="guest_os_name") + String guest_os_name; + + @Column(name="guest_os_id") + long guest_os_id; + + public long getId() { + return id; + } + + public HypervisorType getHypervisorType() { + return hypervisorType; + } + + public void setHypervisorType(HypervisorType hypervisor_type) { + this.hypervisorType = hypervisor_type; + } + + public String getGuestOsName() { + return guest_os_name; + } + + public void setGuestOsName(String name) { + this.guest_os_name = name; + } + + public long getGuestOsId() { + return guest_os_id; + } + + public void setGuestOsId(long guest_os_id) { + this.guest_os_id = guest_os_id; + } + + @Override + public long getCategoryId() { + return 0; + } + + @Override + public String getDisplayName() { + return guest_os_name; + } + + @Override + public String getName() { + return guest_os_name; + } +} diff --git a/server/src/com/cloud/configuration/DefaultComponentLibrary.java b/server/src/com/cloud/configuration/DefaultComponentLibrary.java index b7e9dd855e9..cf3c8ab0402 100755 --- a/server/src/com/cloud/configuration/DefaultComponentLibrary.java +++ b/server/src/com/cloud/configuration/DefaultComponentLibrary.java @@ -115,6 +115,7 @@ import com.cloud.storage.StorageManagerImpl; import com.cloud.storage.dao.DiskOfferingDaoImpl; import com.cloud.storage.dao.GuestOSCategoryDaoImpl; import com.cloud.storage.dao.GuestOSDaoImpl; +import com.cloud.storage.dao.GuestOSHypervisorDaoImpl; import com.cloud.storage.dao.LaunchPermissionDaoImpl; import com.cloud.storage.dao.SnapshotDaoImpl; import com.cloud.storage.dao.SnapshotPolicyDaoImpl; @@ -234,6 +235,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com addDao("SyncQueueDao", SyncQueueDaoImpl.class); addDao("SyncQueueItemDao", SyncQueueItemDaoImpl.class); addDao("GuestOSDao", GuestOSDaoImpl.class); + addDao("GuestOSHypervisorDao", GuestOSHypervisorDaoImpl.class); addDao("GuestOSCategoryDao", GuestOSCategoryDaoImpl.class); addDao("StoragePoolDao", StoragePoolDaoImpl.class); addDao("StoragePoolHostDao", StoragePoolHostDaoImpl.class); diff --git a/server/src/com/cloud/server/ManagementServer.java b/server/src/com/cloud/server/ManagementServer.java index bd10b957b64..44192e9cfa6 100755 --- a/server/src/com/cloud/server/ManagementServer.java +++ b/server/src/com/cloud/server/ManagementServer.java @@ -21,6 +21,7 @@ import java.util.Date; import java.util.List; import java.util.Map; +import com.cloud.api.commands.ListGuestOsCmd; import com.cloud.async.AsyncJobResult; import com.cloud.async.AsyncJobVO; import com.cloud.configuration.ResourceLimitVO; @@ -39,6 +40,7 @@ import com.cloud.network.IPAddressVO; import com.cloud.network.security.SecurityGroupVO; import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.DiskOfferingVO; +import com.cloud.storage.GuestOSHypervisorVO; import com.cloud.storage.GuestOSVO; import com.cloud.storage.StoragePoolVO; import com.cloud.storage.VMTemplateVO; @@ -570,4 +572,6 @@ public interface ManagementServer extends ManagementService { boolean checkIfMaintenable(long hostId); String getHashKey(); + + List listGuestOSByHypervisor(ListGuestOsCmd cmd); } diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 316827524be..104abb05166 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -186,6 +186,7 @@ import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.GuestOSCategoryVO; +import com.cloud.storage.GuestOSHypervisorVO; import com.cloud.storage.GuestOSVO; import com.cloud.storage.LaunchPermissionVO; import com.cloud.storage.Storage; @@ -204,6 +205,7 @@ import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.GuestOSCategoryDao; import com.cloud.storage.dao.GuestOSDao; +import com.cloud.storage.dao.GuestOSHypervisorDao; import com.cloud.storage.dao.LaunchPermissionDao; import com.cloud.storage.dao.StoragePoolDao; import com.cloud.storage.dao.StoragePoolHostDao; @@ -306,6 +308,7 @@ public class ManagementServerImpl implements ManagementServer { private final AlertDao _alertDao; private final CapacityDao _capacityDao; private final GuestOSDao _guestOSDao; + private final GuestOSHypervisorDao _guestOSHypervisorDao; private final GuestOSCategoryDao _guestOSCategoryDao; private final StoragePoolDao _poolDao; private final StoragePoolHostDao _poolHostDao; @@ -383,6 +386,7 @@ public class ManagementServerImpl implements ManagementServer { _alertDao = locator.getDao(AlertDao.class); _capacityDao = locator.getDao(CapacityDao.class); _guestOSDao = locator.getDao(GuestOSDao.class); + _guestOSHypervisorDao = locator.getDao(GuestOSHypervisorDao.class); _guestOSCategoryDao = locator.getDao(GuestOSCategoryDao.class); _poolDao = locator.getDao(StoragePoolDao.class); _poolHostDao = locator.getDao(StoragePoolHostDao.class); @@ -2738,7 +2742,19 @@ public class ManagementServerImpl implements ManagementServer { return _guestOSDao.search(sc, searchFilter); } - + + + @Override + public List listGuestOSByHypervisor(ListGuestOsCmd cmd) { + String hypervisor = cmd.getHypervisor(); + HypervisorType ht = HypervisorType.getType(hypervisor); + if (ht == HypervisorType.None){ + throw new InvalidParameterValueException("The Hypervisor type is not recognized " + hypervisor); + } + return _guestOSHypervisorDao.findByHypervisorType(ht); + } + + @Override public List listGuestOSCategoriesByCriteria(ListGuestOsCategoriesCmd cmd) { Filter searchFilter = new Filter(GuestOSCategoryVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); diff --git a/server/src/com/cloud/storage/dao/GuestOSHypervisorDao.java b/server/src/com/cloud/storage/dao/GuestOSHypervisorDao.java new file mode 100644 index 00000000000..8710bd2c1a7 --- /dev/null +++ b/server/src/com/cloud/storage/dao/GuestOSHypervisorDao.java @@ -0,0 +1,33 @@ +/** + * Copyright (C) 2011 Citrix.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package com.cloud.storage.dao; + +import java.util.List; + +import com.cloud.host.HostVO; +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.storage.GuestOSHypervisorVO; +import com.cloud.utils.db.GenericDao; + +public interface GuestOSHypervisorDao extends GenericDao { + + + public List findByHypervisorType(HypervisorType hypervisorType); + + +} diff --git a/server/src/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java b/server/src/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java new file mode 100644 index 00000000000..f4955fb7554 --- /dev/null +++ b/server/src/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java @@ -0,0 +1,53 @@ +/** + * Copyright (C) 2011 Citrix.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package com.cloud.storage.dao; + +import java.util.List; + +import javax.ejb.Local; + +import com.cloud.host.HostVO; +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.storage.GuestOSHypervisorVO; +import com.cloud.storage.VMTemplateHostVO; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@Local (value={GuestOSHypervisorDao.class}) +public class GuestOSHypervisorDaoImpl extends GenericDaoBase implements GuestOSHypervisorDao { + + + protected final SearchBuilder hypervisor_search; + + protected GuestOSHypervisorDaoImpl() { + hypervisor_search = createSearchBuilder(); + hypervisor_search.and("hypervisor_type", hypervisor_search.entity().getHypervisorType(), SearchCriteria.Op.EQ); + hypervisor_search.done(); + } + + + @Override + public List findByHypervisorType(HypervisorType hypervisorType) { + SearchCriteria sc = hypervisor_search.create(); + sc.setParameters("hypervisor_type", hypervisorType); + return listBy(sc); + } + + +}