From 79e64aa535f9a21af743b9cb49f7a4cefcc938ea Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Mon, 23 Dec 2013 11:48:45 -0800 Subject: [PATCH] Resource metadata support for Disk Offering --- api/src/com/cloud/server/ResourceTag.java | 8 +- ...spring-engine-schema-core-daos-context.xml | 1 + .../resourcedetail/DiskOfferingDetailVO.java | 81 +++++++++++++++++++ .../dao/DiskOfferingDetailsDao.java | 26 ++++++ .../dao/DiskOfferingDetailsDaoImpl.java | 33 ++++++++ .../metadata/ResourceMetaDataManagerImpl.java | 4 + .../cloud/tags/TaggedResourceManagerImpl.java | 8 ++ setup/db/db/schema-430to440.sql | 2 + 8 files changed, 158 insertions(+), 5 deletions(-) create mode 100644 engine/schema/src/org/apache/cloudstack/resourcedetail/DiskOfferingDetailVO.java create mode 100644 engine/schema/src/org/apache/cloudstack/resourcedetail/dao/DiskOfferingDetailsDao.java create mode 100644 engine/schema/src/org/apache/cloudstack/resourcedetail/dao/DiskOfferingDetailsDaoImpl.java diff --git a/api/src/com/cloud/server/ResourceTag.java b/api/src/com/cloud/server/ResourceTag.java index 93dccbadb79..5aee11425da 100644 --- a/api/src/com/cloud/server/ResourceTag.java +++ b/api/src/com/cloud/server/ResourceTag.java @@ -25,11 +25,9 @@ public interface ResourceTag extends ControlledEntity, Identity, InternalIdentit // FIXME - extract enum to another interface as its used both by resourceTags and resourceMetaData code public enum ResourceObjectType { UserVm(true, true), Template(true, true), ISO(true, false), Volume(true, true), Snapshot(true, false), Network(true, true), Nic(false, true), LoadBalancer(true, true), PortForwardingRule( - true, true), FirewallRule(true, true), - - SecurityGroup(true, false), PublicIpAddress(true, true), Project(true, false), Vpc(true, true), NetworkACL(true, true), StaticRoute(true, false), VMSnapshot(true, false), RemoteAccessVpn( - true, true), Zone(false, true), ServiceOffering(false, true), Storage(false, true), PrivateGateway(false, true), NetworkACLList(false, true), VpnGateway(false, - true), CustomerGateway(false, true), VpnConnection(false, true); + true, true), FirewallRule(true, true), SecurityGroup(true, false), PublicIpAddress(true, true), Project(true, false), Vpc(true, true), NetworkACL(true, true), StaticRoute( + true, false), VMSnapshot(true, false), RemoteAccessVpn(true, true), Zone(false, true), ServiceOffering(false, true), Storage(false, true), PrivateGateway(false, + true), NetworkACLList(false, true), VpnGateway(false, true), CustomerGateway(false, true), VpnConnection(false, true), User(true, false), DiskOffering(false, true); ResourceObjectType(boolean resourceTagsSupport, boolean resourceMetadataSupport) { this.resourceTagsSupport = resourceTagsSupport; diff --git a/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml b/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml index 6ec63bce032..5aa91c0231a 100644 --- a/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml +++ b/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml @@ -331,6 +331,7 @@ + diff --git a/engine/schema/src/org/apache/cloudstack/resourcedetail/DiskOfferingDetailVO.java b/engine/schema/src/org/apache/cloudstack/resourcedetail/DiskOfferingDetailVO.java new file mode 100644 index 00000000000..bdee3c14db0 --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/resourcedetail/DiskOfferingDetailVO.java @@ -0,0 +1,81 @@ +// 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.resourcedetail; + +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.ResourceDetail; + +@Entity +@Table(name = "disk_offering_details") +public class DiskOfferingDetailVO implements ResourceDetail { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "offering_id") + private long resourceId; + + @Column(name = "name") + private String name; + + @Column(name = "value", length = 1024) + private String value; + + @Column(name = "display") + private boolean display; + + public DiskOfferingDetailVO() { + } + + public DiskOfferingDetailVO(long id, String name, String value) { + this.resourceId = id; + this.name = name; + this.value = value; + } + + @Override + public long getId() { + return id; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getValue() { + return value; + } + + @Override + public long getResourceId() { + return resourceId; + } + + @Override + public boolean isDisplay() { + return display; + } +} \ No newline at end of file diff --git a/engine/schema/src/org/apache/cloudstack/resourcedetail/dao/DiskOfferingDetailsDao.java b/engine/schema/src/org/apache/cloudstack/resourcedetail/dao/DiskOfferingDetailsDao.java new file mode 100644 index 00000000000..68a8614c93b --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/resourcedetail/dao/DiskOfferingDetailsDao.java @@ -0,0 +1,26 @@ +// 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.resourcedetail.dao; + +import org.apache.cloudstack.resourcedetail.DiskOfferingDetailVO; +import org.apache.cloudstack.resourcedetail.ResourceDetailsDao; + +import com.cloud.utils.db.GenericDao; + +public interface DiskOfferingDetailsDao extends GenericDao, ResourceDetailsDao { + +} \ No newline at end of file diff --git a/engine/schema/src/org/apache/cloudstack/resourcedetail/dao/DiskOfferingDetailsDaoImpl.java b/engine/schema/src/org/apache/cloudstack/resourcedetail/dao/DiskOfferingDetailsDaoImpl.java new file mode 100644 index 00000000000..e2fc26e722a --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/resourcedetail/dao/DiskOfferingDetailsDaoImpl.java @@ -0,0 +1,33 @@ +// 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.resourcedetail.dao; + +import javax.ejb.Local; + +import org.apache.cloudstack.resourcedetail.DiskOfferingDetailVO; +import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase; +import org.springframework.stereotype.Component; + +@Component +@Local(value = {DiskOfferingDetailsDao.class}) +public class DiskOfferingDetailsDaoImpl extends ResourceDetailsDaoBase implements DiskOfferingDetailsDao { + + @Override + public void addDetail(long resourceId, String key, String value) { + super.addDetail(new DiskOfferingDetailVO(resourceId, key, value)); + } +} \ No newline at end of file diff --git a/server/src/com/cloud/metadata/ResourceMetaDataManagerImpl.java b/server/src/com/cloud/metadata/ResourceMetaDataManagerImpl.java index 4cd98402a56..df082ec43ec 100644 --- a/server/src/com/cloud/metadata/ResourceMetaDataManagerImpl.java +++ b/server/src/com/cloud/metadata/ResourceMetaDataManagerImpl.java @@ -26,6 +26,7 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.api.ResourceDetail; import org.apache.cloudstack.resourcedetail.ResourceDetailsDao; +import org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDao; import org.apache.cloudstack.resourcedetail.dao.FirewallRuleDetailsDao; import org.apache.cloudstack.resourcedetail.dao.NetworkACLItemDetailsDao; import org.apache.cloudstack.resourcedetail.dao.NetworkACLListDetailsDao; @@ -101,6 +102,8 @@ public class ResourceMetaDataManagerImpl extends ManagerBase implements Resource Site2SiteCustomerGatewayDetailsDao _customerGatewayDetailsDao; @Inject Site2SiteVpnConnectionDetailsDao _vpnConnectionDetailsDao; + @Inject + DiskOfferingDetailsDao _diskOfferingDetailsDao; private static Map> s_daoMap = new HashMap>(); @@ -126,6 +129,7 @@ public class ResourceMetaDataManagerImpl extends ManagerBase implements Resource s_daoMap.put(ResourceObjectType.VpnGateway, _vpnGatewayDetailsDao); s_daoMap.put(ResourceObjectType.CustomerGateway, _customerGatewayDetailsDao); s_daoMap.put(ResourceObjectType.VpnConnection, _vpnConnectionDetailsDao); + s_daoMap.put(ResourceObjectType.DiskOffering, _diskOfferingDetailsDao); return true; } diff --git a/server/src/com/cloud/tags/TaggedResourceManagerImpl.java b/server/src/com/cloud/tags/TaggedResourceManagerImpl.java index 3dd90ff6a82..a202ad28517 100644 --- a/server/src/com/cloud/tags/TaggedResourceManagerImpl.java +++ b/server/src/com/cloud/tags/TaggedResourceManagerImpl.java @@ -57,6 +57,7 @@ import com.cloud.server.ResourceTag; import com.cloud.server.ResourceTag.ResourceObjectType; import com.cloud.server.TaggedResourceService; import com.cloud.service.dao.ServiceOfferingDao; +import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.SnapshotDao; import com.cloud.storage.dao.VMTemplateDao; import com.cloud.storage.dao.VolumeDao; @@ -64,6 +65,7 @@ import com.cloud.tags.dao.ResourceTagDao; import com.cloud.user.Account; import com.cloud.user.AccountManager; import com.cloud.user.DomainManager; +import com.cloud.user.dao.UserDao; import com.cloud.utils.Pair; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.db.DB; @@ -147,6 +149,10 @@ public class TaggedResourceManagerImpl extends ManagerBase implements TaggedReso Site2SiteCustomerGatewayDao _customerGatewayDao; @Inject Site2SiteVpnConnectionDao _vpnConnectionDao; + @Inject + UserDao _userDao; + @Inject + DiskOfferingDao _diskOffDao; @Override public boolean configure(String name, Map params) throws ConfigurationException { @@ -176,6 +182,8 @@ public class TaggedResourceManagerImpl extends ManagerBase implements TaggedReso s_daoMap.put(ResourceObjectType.VpnGateway, _vpnGatewayDao); s_daoMap.put(ResourceObjectType.CustomerGateway, _customerGatewayDao); s_daoMap.put(ResourceObjectType.VpnConnection, _vpnConnectionDao); + s_daoMap.put(ResourceObjectType.User, _userDao); + s_daoMap.put(ResourceObjectType.DiskOffering, _diskOffDao); return true; } diff --git a/setup/db/db/schema-430to440.sql b/setup/db/db/schema-430to440.sql index f4dc2e6721d..0dd2c39674b 100644 --- a/setup/db/db/schema-430to440.sql +++ b/setup/db/db/schema-430to440.sql @@ -214,3 +214,5 @@ CREATE VIEW `cloud`.`volume_view` AS and async_job.job_status = 0; UPDATE `cloud`.`configuration` SET `description` = 'If set to true, StartCommand, StopCommand, CopyCommand, MigrateCommand will be synchronized on the agent side. If set to false, these commands become asynchronous. Default value is true.' WHERE `name` = 'execute.in.sequence.hypervisor.commands'; + +ALTER TABLE `cloud`.`disk_offering_details` CHANGE `display_detail` `display` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'True if the detail can be displayed to the end user'; \ No newline at end of file