Skip to content

Commit 551ec47

Browse files
committed
events for os category
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent d96afd6 commit 551ec47

File tree

15 files changed

+87
-16
lines changed

15 files changed

+87
-16
lines changed

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,9 @@ public class EventTypes {
687687
public static final String EVENT_EXTERNAL_OPENDAYLIGHT_CONFIGURE_CONTROLLER = "PHYSICAL.ODLCONTROLLER.CONFIGURE";
688688

689689
//Guest OS related events
690+
public static final String EVENT_GUEST_OS_CATEGORY_ADD = "GUEST.OS.CATEGORY.ADD";
691+
public static final String EVENT_GUEST_OS_CATEGORY_DELETE = "GUEST.OS.CATEGORY.DELETE";
692+
public static final String EVENT_GUEST_OS_CATEGORY_UPDATE = "GUEST.OS.CATEGORY.UPDATE";
690693
public static final String EVENT_GUEST_OS_ADD = "GUEST.OS.ADD";
691694
public static final String EVENT_GUEST_OS_REMOVE = "GUEST.OS.REMOVE";
692695
public static final String EVENT_GUEST_OS_UPDATE = "GUEST.OS.UPDATE";

api/src/main/java/com/cloud/storage/GuestOsCategory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// under the License.
1717
package com.cloud.storage;
1818

19+
import java.util.Date;
20+
1921
import org.apache.cloudstack.api.Identity;
2022
import org.apache.cloudstack.api.InternalIdentity;
2123

@@ -29,4 +31,5 @@ public interface GuestOsCategory extends Identity, InternalIdentity {
2931

3032
boolean isFeatured();
3133

34+
Date getCreated();
3235
}

api/src/main/java/org/apache/cloudstack/api/ApiCommandResourceType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public enum ApiCommandResourceType {
6161
AffinityGroup(org.apache.cloudstack.affinity.AffinityGroup.class),
6262
InternalLbVm(com.cloud.network.router.VirtualRouter.class),
6363
DedicatedGuestVlanRange(com.cloud.network.GuestVlan.class),
64+
GuestOsCategory(com.cloud.storage.GuestOsCategory.class),
6465
GuestOs(com.cloud.storage.GuestOS.class),
6566
GuestOsMapping(com.cloud.storage.GuestOSHypervisor.class),
6667
Network(com.cloud.network.Network.class),

api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsCategoryCmd.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.apache.cloudstack.acl.RoleType;
2121
import org.apache.cloudstack.api.APICommand;
22+
import org.apache.cloudstack.api.ApiCommandResourceType;
2223
import org.apache.cloudstack.api.ApiConstants;
2324
import org.apache.cloudstack.api.ApiErrorCode;
2425
import org.apache.cloudstack.api.BaseCmd;
@@ -84,4 +85,9 @@ public void execute() {
8485
public long getEntityOwnerId() {
8586
return Account.ACCOUNT_ID_SYSTEM;
8687
}
88+
89+
@Override
90+
public ApiCommandResourceType getApiResourceType() {
91+
return ApiCommandResourceType.GuestOsCategory;
92+
}
8793
}

api/src/main/java/org/apache/cloudstack/api/command/admin/guest/DeleteGuestOsCategoryCmd.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.apache.cloudstack.acl.RoleType;
2121
import org.apache.cloudstack.api.APICommand;
22+
import org.apache.cloudstack.api.ApiCommandResourceType;
2223
import org.apache.cloudstack.api.ApiConstants;
2324
import org.apache.cloudstack.api.ApiErrorCode;
2425
import org.apache.cloudstack.api.BaseCmd;
@@ -75,4 +76,14 @@ public void execute() {
7576
public long getEntityOwnerId() {
7677
return Account.ACCOUNT_ID_SYSTEM;
7778
}
79+
80+
@Override
81+
public ApiCommandResourceType getApiResourceType() {
82+
return ApiCommandResourceType.GuestOsCategory;
83+
}
84+
85+
@Override
86+
public Long getApiResourceId() {
87+
return getId();
88+
}
7889
}

api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsCategoryCmd.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.apache.cloudstack.acl.RoleType;
2121
import org.apache.cloudstack.api.APICommand;
22+
import org.apache.cloudstack.api.ApiCommandResourceType;
2223
import org.apache.cloudstack.api.ApiConstants;
2324
import org.apache.cloudstack.api.ApiErrorCode;
2425
import org.apache.cloudstack.api.BaseCmd;
@@ -99,4 +100,14 @@ public void execute() {
99100
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update OS category");
100101
}
101102
}
103+
104+
@Override
105+
public ApiCommandResourceType getApiResourceType() {
106+
return ApiCommandResourceType.GuestOsCategory;
107+
}
108+
109+
@Override
110+
public Long getApiResourceId() {
111+
return getId();
112+
}
102113
}

api/src/main/java/org/apache/cloudstack/api/response/GuestOSCategoryResponse.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.response;
1818

19+
import java.util.Date;
20+
1921
import com.google.gson.annotations.SerializedName;
2022

2123
import org.apache.cloudstack.api.ApiConstants;
@@ -43,6 +45,10 @@ public class GuestOSCategoryResponse extends BaseResponse implements SetResource
4345
@Param(description = "Base64 string representation of the resource icon", since = "4.20.1")
4446
private ResourceIconResponse resourceIconResponse;
4547

48+
@SerializedName(ApiConstants.CREATED)
49+
@Param(description = "Date when the OS category was created." )
50+
private Date created;
51+
4652
public String getId() {
4753
return id;
4854
}
@@ -67,4 +73,8 @@ public void setFeatured(Boolean featured) {
6773
public void setResourceIconResponse(ResourceIconResponse resourceIconResponse) {
6874
this.resourceIconResponse = resourceIconResponse;
6975
}
76+
77+
public void setCreated(Date created) {
78+
this.created = created;
79+
}
7080
}

engine/schema/src/main/java/com/cloud/storage/GuestOSCategoryVO.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package com.cloud.storage;
1818

19+
import java.util.Date;
1920
import java.util.UUID;
2021

2122
import javax.persistence.Column;
@@ -25,6 +26,8 @@
2526
import javax.persistence.Id;
2627
import javax.persistence.Table;
2728

29+
import com.cloud.utils.db.GenericDao;
30+
2831
@Entity
2932
@Table(name = "guest_os_category")
3033
public class GuestOSCategoryVO implements GuestOsCategory {
@@ -45,6 +48,20 @@ public class GuestOSCategoryVO implements GuestOsCategory {
4548
@Column(name = "sort_key")
4649
private int sortKey;
4750

51+
@Column(name = GenericDao.CREATED_COLUMN)
52+
private Date created;
53+
54+
@Column(name = GenericDao.REMOVED_COLUMN)
55+
private Date removed;
56+
57+
public GuestOSCategoryVO() {
58+
}
59+
60+
public GuestOSCategoryVO(String name, boolean featured) {
61+
this.name = name;
62+
this.featured = featured;
63+
}
64+
4865
@Override
4966
public long getId() {
5067
return id;
@@ -65,10 +82,6 @@ public String getUuid() {
6582
return this.uuid;
6683
}
6784

68-
public void setUuid(String uuid) {
69-
this.uuid = uuid;
70-
}
71-
7285
@Override
7386
public boolean isFeatured() {
7487
return featured;
@@ -85,4 +98,9 @@ public void setSortKey(int key) {
8598
public int getSortKey() {
8699
return sortKey;
87100
}
101+
102+
@Override
103+
public Date getCreated() {
104+
return created;
105+
}
88106
}

engine/schema/src/main/resources/META-INF/db/schema-42000to42010.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ UPDATE `cloud`.`network_offerings` SET conserve_mode=1 WHERE name='DefaultIsolat
8282
-- Add featured column for guest_os_category
8383
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.guest_os_category', 'featured', 'tinyint(1) NOT NULL DEFAULT 0 COMMENT "whether the category is featured or not" AFTER `uuid`');
8484
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.guest_os_category', 'sort_key', 'int NOT NULL DEFAULT 0 COMMENT "sort key used for customising sort method" AFTER `featured`');
85+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.guest_os_category', 'created', 'date COMMENT "date on which the category was created" AFTER `sort_key`');
86+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.guest_os_category', 'removed', 'date COMMENT "date removed if not null" AFTER `created`');
8587
UPDATE `cloud`.`guest_os_category` SET `featured` = 1 WHERE `name` NOT IN ('Novel', 'None');
8688

8789
-- Begin: Changes for Guest OS category cleanup
@@ -136,7 +138,7 @@ BEGIN
136138
; UPDATE `cloud`.`guest_os`
137139
SET `category_id` = to_category_id
138140
WHERE `category_id` = (SELECT `id` FROM `cloud`.`guest_os_category` WHERE `name` = from_category_name)
139-
; DELETE FROM `cloud`.`guest_os_category` WHERE `name` = from_category_name
141+
; UPDATE `cloud`.`guest_os_category` SET `removed``=now() WHERE `name` = from_category_name
140142
; END;
141143
CALL `cloud`.`UPDATE_NEW_AND_DELETE_OLD_CATEGORY_FOR_GUEST_OS`('Other', 'Novel');
142144
CALL `cloud`.`UPDATE_NEW_AND_DELETE_OLD_CATEGORY_FOR_GUEST_OS`('Other', 'None');

server/src/main/java/com/cloud/api/ApiResponseHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3891,6 +3891,7 @@ public GuestOSCategoryResponse createGuestOSCategoryResponse(GuestOsCategory gue
38913891
categoryResponse.setId(guestOsCategory.getUuid());
38923892
categoryResponse.setName(guestOsCategory.getName());
38933893
categoryResponse.setFeatured(guestOsCategory.isFeatured());
3894+
categoryResponse.setCreated(guestOsCategory.getCreated());
38943895
if (showIcon) {
38953896
ResourceIconVO resourceIcon = ApiDBUtils.getResourceIconByResourceUUID(guestOsCategory.getUuid(),
38963897
ResourceObjectType.GuestOsCategory);

0 commit comments

Comments
 (0)