Skip to content

Commit fbba17e

Browse files
author
Alena Prokharchyk
committed
Resource metadata support for cloudStack user
1 parent 79e64aa commit fbba17e

8 files changed

Lines changed: 159 additions & 10 deletions

File tree

‎api/src/com/cloud/server/ResourceTag.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public enum ResourceObjectType {
2727
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(
2828
true, true), FirewallRule(true, true), SecurityGroup(true, false), PublicIpAddress(true, true), Project(true, false), Vpc(true, true), NetworkACL(true, true), StaticRoute(
2929
true, false), VMSnapshot(true, false), RemoteAccessVpn(true, true), Zone(false, true), ServiceOffering(false, true), Storage(false, true), PrivateGateway(false,
30-
true), NetworkACLList(false, true), VpnGateway(false, true), CustomerGateway(false, true), VpnConnection(false, true), User(true, false), DiskOffering(false, true);
30+
true), NetworkACLList(false, true), VpnGateway(false, true), CustomerGateway(false, true), VpnConnection(false, true), User(true, true), DiskOffering(false, true);
3131

3232
ResourceObjectType(boolean resourceTagsSupport, boolean resourceMetadataSupport) {
3333
this.resourceTagsSupport = resourceTagsSupport;

‎api/src/org/apache/cloudstack/api/command/user/volume/AddResourceDetailCmd.java‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,20 @@
2121
import java.util.Iterator;
2222
import java.util.Map;
2323

24-
import org.apache.log4j.Logger;
25-
2624
import org.apache.cloudstack.api.APICommand;
2725
import org.apache.cloudstack.api.ApiConstants;
2826
import org.apache.cloudstack.api.BaseAsyncCmd;
2927
import org.apache.cloudstack.api.Parameter;
3028
import org.apache.cloudstack.api.response.SuccessResponse;
29+
import org.apache.log4j.Logger;
3130

3231
import com.cloud.event.EventTypes;
3332
import com.cloud.server.ResourceTag;
3433

3534
@APICommand(name = "addResourceDetail", description = "Adds detail for the Resource.", responseObject = SuccessResponse.class)
3635
public class AddResourceDetailCmd extends BaseAsyncCmd {
3736
public static final Logger s_logger = Logger.getLogger(AddResourceDetailCmd.class.getName());
38-
private static final String s_name = "addResourceDetailresponse";
37+
private static final String s_name = "addresourcedetailresponse";
3938

4039
/////////////////////////////////////////////////////
4140
//////////////// API parameters /////////////////////
@@ -47,11 +46,7 @@ public class AddResourceDetailCmd extends BaseAsyncCmd {
4746
@Parameter(name = ApiConstants.RESOURCE_TYPE, type = CommandType.STRING, required = true, description = "type of the resource")
4847
private String resourceType;
4948

50-
@Parameter(name = ApiConstants.RESOURCE_ID,
51-
type = CommandType.STRING,
52-
required = true,
53-
collectionType = CommandType.STRING,
54-
description = "resource id to create the details for")
49+
@Parameter(name = ApiConstants.RESOURCE_ID, type = CommandType.STRING, required = true, collectionType = CommandType.STRING, description = "resource id to create the details for")
5550
private String resourceId;
5651

5752
/////////////////////////////////////////////////////

‎engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@
332332
<bean id="Site2SiteCustomerGatewayDetailsDaoImpl" class="org.apache.cloudstack.resourcedetail.dao.Site2SiteCustomerGatewayDetailsDaoImpl" />
333333
<bean id="Site2SiteVpnConnectionDetailsDaoImpl" class="org.apache.cloudstack.resourcedetail.dao.Site2SiteVpnConnectionDetailsDaoImpl" />
334334
<bean id="DiskOfferingDetailsDaoImpl" class="org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDaoImpl" />
335+
<bean id="UserDetailsDaoImpl" class="org.apache.cloudstack.resourcedetail.dao.UserDetailsDaoImpl" />
335336
<bean id="databaseIntegrityChecker" class="com.cloud.upgrade.DatabaseIntegrityChecker" />
336337

337338
</beans>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.resourcedetail;
18+
19+
import javax.persistence.Column;
20+
import javax.persistence.Entity;
21+
import javax.persistence.GeneratedValue;
22+
import javax.persistence.GenerationType;
23+
import javax.persistence.Id;
24+
import javax.persistence.Table;
25+
26+
import org.apache.cloudstack.api.ResourceDetail;
27+
28+
@Entity
29+
@Table(name = "user_details")
30+
public class UserDetailVO implements ResourceDetail {
31+
@Id
32+
@GeneratedValue(strategy = GenerationType.IDENTITY)
33+
@Column(name = "id")
34+
private long id;
35+
36+
@Column(name = "user_id")
37+
private long resourceId;
38+
39+
@Column(name = "name")
40+
private String name;
41+
42+
@Column(name = "value", length = 1024)
43+
private String value;
44+
45+
@Column(name = "display")
46+
private boolean display;
47+
48+
public UserDetailVO() {
49+
}
50+
51+
public UserDetailVO(long id, String name, String value) {
52+
this.resourceId = id;
53+
this.name = name;
54+
this.value = value;
55+
}
56+
57+
@Override
58+
public long getId() {
59+
return id;
60+
}
61+
62+
@Override
63+
public String getName() {
64+
return name;
65+
}
66+
67+
@Override
68+
public String getValue() {
69+
return value;
70+
}
71+
72+
@Override
73+
public long getResourceId() {
74+
return resourceId;
75+
}
76+
77+
@Override
78+
public boolean isDisplay() {
79+
return display;
80+
}
81+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.resourcedetail.dao;
18+
19+
import org.apache.cloudstack.resourcedetail.UserDetailVO;
20+
import org.apache.cloudstack.resourcedetail.ResourceDetailsDao;
21+
22+
import com.cloud.utils.db.GenericDao;
23+
24+
public interface UserDetailsDao extends GenericDao<UserDetailVO, Long>, ResourceDetailsDao<UserDetailVO> {
25+
26+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.resourcedetail.dao;
18+
19+
import javax.ejb.Local;
20+
21+
import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase;
22+
import org.apache.cloudstack.resourcedetail.UserDetailVO;
23+
import org.springframework.stereotype.Component;
24+
25+
@Component
26+
@Local(value = {UserDetailsDao.class})
27+
public class UserDetailsDaoImpl extends ResourceDetailsDaoBase<UserDetailVO> implements UserDetailsDao {
28+
29+
@Override
30+
public void addDetail(long resourceId, String key, String value) {
31+
super.addDetail(new UserDetailVO(resourceId, key, value));
32+
}
33+
}

‎server/src/com/cloud/metadata/ResourceMetaDataManagerImpl.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.apache.cloudstack.resourcedetail.dao.Site2SiteCustomerGatewayDetailsDao;
3535
import org.apache.cloudstack.resourcedetail.dao.Site2SiteVpnConnectionDetailsDao;
3636
import org.apache.cloudstack.resourcedetail.dao.Site2SiteVpnGatewayDetailsDao;
37+
import org.apache.cloudstack.resourcedetail.dao.UserDetailsDao;
3738
import org.apache.cloudstack.resourcedetail.dao.UserIpAddressDetailsDao;
3839
import org.apache.cloudstack.resourcedetail.dao.VpcDetailsDao;
3940
import org.apache.cloudstack.resourcedetail.dao.VpcGatewayDetailsDao;
@@ -104,6 +105,8 @@ public class ResourceMetaDataManagerImpl extends ManagerBase implements Resource
104105
Site2SiteVpnConnectionDetailsDao _vpnConnectionDetailsDao;
105106
@Inject
106107
DiskOfferingDetailsDao _diskOfferingDetailsDao;
108+
@Inject
109+
UserDetailsDao _userDetailsDao;
107110

108111
private static Map<ResourceObjectType, ResourceDetailsDao<? extends ResourceDetail>> s_daoMap = new HashMap<ResourceObjectType, ResourceDetailsDao<? extends ResourceDetail>>();
109112

@@ -130,6 +133,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
130133
s_daoMap.put(ResourceObjectType.CustomerGateway, _customerGatewayDetailsDao);
131134
s_daoMap.put(ResourceObjectType.VpnConnection, _vpnConnectionDetailsDao);
132135
s_daoMap.put(ResourceObjectType.DiskOffering, _diskOfferingDetailsDao);
136+
s_daoMap.put(ResourceObjectType.User, _userDetailsDao);
133137

134138
return true;
135139
}

‎setup/db/db/schema-430to440.sql‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,5 +214,14 @@ CREATE VIEW `cloud`.`volume_view` AS
214214
and async_job.job_status = 0;
215215

216216
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';
217+
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';
217218

218-
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';
219+
CREATE TABLE `cloud`.`user_details` (
220+
`id` bigint unsigned NOT NULL auto_increment,
221+
`user_id` bigint unsigned NOT NULL COMMENT 'VPC gateway id',
222+
`name` varchar(255) NOT NULL,
223+
`value` varchar(1024) NOT NULL,
224+
`display` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'True if the detail can be displayed to the end user',
225+
PRIMARY KEY (`id`),
226+
CONSTRAINT `fk_user_details__user_id` FOREIGN KEY `fk_user_details__user_id`(`user_id`) REFERENCES `user`(`id`) ON DELETE CASCADE
227+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

0 commit comments

Comments
 (0)