From 7eea0010dba9e94e7dc23a0dd7e294cfcabb9b5b Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Sat, 15 Nov 2025 14:52:54 -0500 Subject: [PATCH 01/38] add new and update existing maven modules using respective pom.xml Signed-off-by: Daman Arora --- client/pom.xml | 5 ++++ plugins/hackerbook/feature/pom.xml | 48 ++++++++++++++++++++++++++++++ plugins/pom.xml | 1 + 3 files changed, 54 insertions(+) create mode 100644 plugins/hackerbook/feature/pom.xml diff --git a/client/pom.xml b/client/pom.xml index d8fa433d5be3..0eb77389e9d5 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -28,6 +28,11 @@ 4.23.0.0-SNAPSHOT + + org.apache.cloudstack + cloud-plugin-hackerbook-feature + ${project.version} + javax.servlet javax.servlet-api diff --git a/plugins/hackerbook/feature/pom.xml b/plugins/hackerbook/feature/pom.xml new file mode 100644 index 000000000000..a109105dc81b --- /dev/null +++ b/plugins/hackerbook/feature/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + cloud-plugin-hackerbook-feature + Apache CloudStack Plugin - HackerBook Coffee Feature + + org.apache.cloudstack + cloudstack-plugins + 4.23.0.0-SNAPSHOT + ../../pom.xml + + + + org.apache.cloudstack + cloud-api + ${project.version} + + + org.apache.cloudstack + cloud-utils + ${project.version} + + + + 11 + 11 + UTF-8 + + \ No newline at end of file diff --git a/plugins/pom.xml b/plugins/pom.xml index e7d13871285e..c95e4651f269 100755 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -140,6 +140,7 @@ storage/object/ceph storage/object/cloudian storage/object/simulator + hackerbook/feature storage-allocators/random From e4ff60f045fe2279f56da9e9d832411fc924e25e Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Sat, 15 Nov 2025 14:54:14 -0500 Subject: [PATCH 02/38] add module.properties Signed-off-by: Daman Arora --- .../resources/META-INF/cloudstack/feature/module.properties | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/module.properties diff --git a/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/module.properties b/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/module.properties new file mode 100644 index 000000000000..5b90727c9f76 --- /dev/null +++ b/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/module.properties @@ -0,0 +1,2 @@ +name=feature +parent=api From b14b7269edcbb0bb80c6a2b463f4d186a9522d6c Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Sat, 15 Nov 2025 15:06:51 -0500 Subject: [PATCH 03/38] add list and response class Signed-off-by: Daman Arora --- .../cloudstack/api/command/ListCoffeeCmd.java | 74 +++++++++++++++++++ .../api/response/CoffeeResponse.java | 53 +++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java create mode 100644 plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/response/CoffeeResponse.java diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java new file mode 100644 index 000000000000..348a8cce448f --- /dev/null +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java @@ -0,0 +1,74 @@ +/* + * 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; + +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.BaseListCmd; +import org.apache.cloudstack.api.response.CoffeeResponse; +import org.apache.cloudstack.api.response.ListResponse; + +import java.util.ArrayList; +import java.util.List; + +@APICommand( + name = "listCoffees", + description = "Lists all coffees", + responseObject = CoffeeResponse.class, + since = "4.23.0.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false +) +public class ListCoffeeCmd extends BaseListCmd { + + @Override + public void execute() { + List coffeeList = new ArrayList<>(); + + CoffeeResponse espresso = new CoffeeResponse(); + espresso.setId("1"); + espresso.setName("Morning Espresso"); + espresso.setOffering("Espresso"); + espresso.setSize("SMALL"); + espresso.setState("Brewed"); + espresso.setObjectName("coffee"); + + CoffeeResponse latte = new CoffeeResponse(); + latte.setId("2"); + latte.setName("Cloud Latte"); + latte.setOffering("Latte"); + latte.setSize("LARGE"); + latte.setState("Created"); + latte.setObjectName("coffee"); + + coffeeList.add(espresso); + coffeeList.add(latte); + + ListResponse response = new ListResponse<>(); + response.setResponses(coffeeList, coffeeList.size()); + response.setResponseName(getCommandName()); + response.setObjectName("coffee"); + setResponseObject(response); + } + + @Override + public long getEntityOwnerId() { + return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/response/CoffeeResponse.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/response/CoffeeResponse.java new file mode 100644 index 000000000000..71b67a140394 --- /dev/null +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/response/CoffeeResponse.java @@ -0,0 +1,53 @@ +/* + * 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 com.google.gson.annotations.SerializedName; +import org.apache.cloudstack.api.BaseResponse; +import com.cloud.serializer.Param; + +public class CoffeeResponse extends BaseResponse { + + @SerializedName("id") + @Param(description = "the coffee ID") + private String id; + + @SerializedName("name") + @Param(description = "the coffee name") + private String name; + + @SerializedName("offering") + @Param(description = "the type of coffee") + private String offering; + + @SerializedName("size") + @Param(description = "the size of coffee") + private String size; + + @SerializedName("state") + @Param(description = "current coffee state") + private String state; + + public void setId(String id) { this.id = id; } + public void setName(String name) { this.name = name; } + public void setOffering(String offering) { this.offering = offering; } + public void setSize(String size) { this.size = size; } + public void setState(String state) { this.state = state; } +} From 72b9ca7e01d93302c870334ea1e41e25d6fa110a Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Sat, 15 Nov 2025 15:08:15 -0500 Subject: [PATCH 04/38] add service and inject it as a bean Signed-off-by: Daman Arora --- .../cloudstack/coffee/CoffeeService.java | 36 +++++++++++++++++++ .../feature/spring-feature-context.xml | 25 +++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java create mode 100644 plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java new file mode 100644 index 000000000000..01bf89b9bd02 --- /dev/null +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java @@ -0,0 +1,36 @@ +/* + * 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.coffee; + +import com.cloud.utils.component.PluggableService; +import org.apache.cloudstack.api.command.ListCoffeeCmd; + +import java.util.ArrayList; +import java.util.List; + +public class CoffeeService implements PluggableService { + + @Override + public List> getCommands() { + List> cmdList = new ArrayList<>(); + cmdList.add(ListCoffeeCmd.class); + return cmdList; + } +} diff --git a/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml b/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml new file mode 100644 index 000000000000..d1debec43a7c --- /dev/null +++ b/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml @@ -0,0 +1,25 @@ + + + + + + From 364cd4cb14371ac010f9339668bbd6bf8751d1cc Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Sat, 15 Nov 2025 16:52:49 -0500 Subject: [PATCH 05/38] update apidocs Signed-off-by: Daman Arora --- tools/apidoc/gen_toc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/apidoc/gen_toc.py b/tools/apidoc/gen_toc.py index e41a04ff2e1b..34970180e542 100644 --- a/tools/apidoc/gen_toc.py +++ b/tools/apidoc/gen_toc.py @@ -273,7 +273,8 @@ 'Extensions' : 'Extension', 'CustomAction' : 'Extension', 'CustomActions' : 'Extension', - 'ImportVmTask': 'Import VM Task' + 'ImportVmTask': 'Import VM Task', + 'Coffee': 'Coffee' } From 5dacb244c12732b908439f2d8df964fc781154d4 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Mon, 24 Nov 2025 10:57:43 -0500 Subject: [PATCH 06/38] add CreateCoffeeCmd Signed-off-by: Daman Arora --- .../api/command/CreateCoffeeCmd.java | 121 ++++++++++++++++++ .../cloudstack/coffee/CoffeeService.java | 2 + 2 files changed, 123 insertions(+) create mode 100644 plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java new file mode 100644 index 000000000000..3734a1d64db6 --- /dev/null +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java @@ -0,0 +1,121 @@ +/* + * 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; + +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseAsyncCreateCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.CoffeeResponse; +import org.apache.cloudstack.acl.RoleType; + +import java.util.Map; + +@APICommand( + name = "createCoffee", + description = "Creates a new coffee order", + responseObject = CoffeeResponse.class, + since = "4.23.0.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User} +) +public class CreateCoffeeCmd extends BaseAsyncCreateCmd { + + @Parameter(name = ApiConstants.NAME, + type = CommandType.STRING, + required = true, + description = "name of the coffee order") + private String name; + + @Parameter(name = "offering", + type = CommandType.STRING, + required = true, + description = "type of coffee (Espresso, Cappuccino, Mocha, Latte)") + private String offering; + + @Parameter(name = "size", + type = CommandType.STRING, + required = true, + description = "size of coffee (SMALL, MEDIUM, LARGE)") + private String size; + + @Parameter(name = "details", + type = CommandType.MAP, + required = false, + description = "details for the coffee order") + private Map details; + + private Long coffeeId; + + @Override + public void create() { + // Just set a fake ID for now + coffeeId = 3L; + setEntityId(coffeeId); + setEntityUuid("fake-uuid-" + coffeeId); + } + + @Override + public void execute() { + // Hardcoded response for now + CoffeeResponse response = new CoffeeResponse(); + response.setId(String.valueOf(coffeeId)); + response.setName(name); + response.setOffering(offering); + response.setSize(size); + response.setState("Created"); + response.setObjectName("coffee"); + response.setResponseName(getCommandName()); + + setResponseObject(response); + } + + @Override + public String getEventType() { + return "COFFEE.CREATE"; + } + + @Override + public String getEventDescription() { + return "Creating coffee: " + name; + } + + @Override + public long getEntityOwnerId() { + return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; + } + + public String getName() { + return name; + } + + public String getOffering() { + return offering; + } + + public String getSize() { + return size; + } + + public Map getDetails() { + return details; + } +} \ No newline at end of file diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java index 01bf89b9bd02..6c3d3d36906d 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java @@ -21,6 +21,7 @@ import com.cloud.utils.component.PluggableService; import org.apache.cloudstack.api.command.ListCoffeeCmd; +import org.apache.cloudstack.api.command.CreateCoffeeCmd; import java.util.ArrayList; import java.util.List; @@ -30,6 +31,7 @@ public class CoffeeService implements PluggableService { @Override public List> getCommands() { List> cmdList = new ArrayList<>(); + cmdList.add(CreateCoffeeCmd.class); cmdList.add(ListCoffeeCmd.class); return cmdList; } From cd7acf5b1c7a4b64be5d468a9244ba077e13c98f Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Mon, 24 Nov 2025 11:25:43 -0500 Subject: [PATCH 07/38] add UpdateCoffeeCmd Signed-off-by: Daman Arora --- .../api/command/UpdateCoffeeCmd.java | 101 ++++++++++++++++++ .../cloudstack/coffee/CoffeeService.java | 2 + 2 files changed, 103 insertions(+) create mode 100644 plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java new file mode 100644 index 000000000000..39e6f3a44b2f --- /dev/null +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java @@ -0,0 +1,101 @@ +/* + * 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; + +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.CoffeeResponse; +import org.apache.cloudstack.acl.RoleType; + +import java.util.Map; + +@APICommand( + name = "updateCoffee", + description = "Updates an existing coffee order", + responseObject = CoffeeResponse.class, + since = "4.23.0.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User} +) +public class UpdateCoffeeCmd extends BaseAsyncCmd { + + @Parameter(name = ApiConstants.ID, + type = CommandType.STRING, + required = true, + description = "the ID of the coffee order") + private String id; + + @Parameter(name = "size", + type = CommandType.STRING, + required = false, + description = "new size of coffee (SMALL, MEDIUM, LARGE)") + private String size; + + @Parameter(name = "details", + type = CommandType.MAP, + required = false, + description = "updated details for the coffee order") + private Map details; + + @Override + public void execute() { + // Hardcoded response for now + CoffeeResponse response = new CoffeeResponse(); + response.setId(id); + response.setName("Updated Coffee Order"); + response.setOffering("Espresso"); + response.setSize(size != null ? size : "MEDIUM"); + response.setState("Created"); + response.setObjectName("coffee"); + response.setResponseName(getCommandName()); + + setResponseObject(response); + } + + @Override + public String getEventType() { + return "COFFEE.UPDATE"; + } + + @Override + public String getEventDescription() { + return "Updating coffee: " + id; + } + + @Override + public long getEntityOwnerId() { + return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; + } + + public String getId() { + return id; + } + + public String getSize() { + return size; + } + + public Map getDetails() { + return details; + } +} \ No newline at end of file diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java index 6c3d3d36906d..1629a5d543ef 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java @@ -22,6 +22,7 @@ import com.cloud.utils.component.PluggableService; import org.apache.cloudstack.api.command.ListCoffeeCmd; import org.apache.cloudstack.api.command.CreateCoffeeCmd; +import org.apache.cloudstack.api.command.UpdateCoffeeCmd; import java.util.ArrayList; import java.util.List; @@ -33,6 +34,7 @@ public List> getCommands() { List> cmdList = new ArrayList<>(); cmdList.add(CreateCoffeeCmd.class); cmdList.add(ListCoffeeCmd.class); + cmdList.add(UpdateCoffeeCmd.class); return cmdList; } } From e06880f80278d1c93c8831342a47ea92cda17763 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Mon, 24 Nov 2025 11:31:32 -0500 Subject: [PATCH 08/38] add RemoveCoffeeCmd Signed-off-by: Daman Arora --- .../api/command/RemoveCoffeeCmd.java | 102 ++++++++++++++++++ .../cloudstack/coffee/CoffeeService.java | 2 + 2 files changed, 104 insertions(+) create mode 100644 plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java new file mode 100644 index 000000000000..33e711649cbe --- /dev/null +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java @@ -0,0 +1,102 @@ +/* + * 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; + +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.acl.RoleType; + +import java.util.List; + +@APICommand( + name = "removeCoffee", + description = "Removes a coffee order or multiple coffee orders", + responseObject = SuccessResponse.class, + since = "4.23.0.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User} +) +public class RemoveCoffeeCmd extends BaseAsyncCmd { + + @Parameter(name = ApiConstants.ID, + type = CommandType.STRING, + required = false, + description = "the ID of the coffee order to remove") + private String id; + + @Parameter(name = "ids", + type = CommandType.LIST, + collectionType = CommandType.STRING, + required = false, + description = "the IDs of coffee orders to remove") + private List ids; + + @Override + public void execute() { + // Hardcoded success response for now + SuccessResponse response = new SuccessResponse(); + + if (id != null) { + response.setSuccess(true); + response.setDisplayText("Successfully removed coffee order: " + id); + } else if (ids != null && !ids.isEmpty()) { + response.setSuccess(true); + response.setDisplayText("Successfully removed " + ids.size() + " coffee orders"); + } else { + response.setSuccess(false); + response.setDisplayText("No coffee ID provided"); + } + + response.setResponseName(getCommandName()); + setResponseObject(response); + } + + @Override + public String getEventType() { + return "COFFEE.REMOVE"; + } + + @Override + public String getEventDescription() { + if (id != null) { + return "Removing coffee: " + id; + } else if (ids != null) { + return "Removing " + ids.size() + " coffees"; + } + return "Removing coffee"; + } + + @Override + public long getEntityOwnerId() { + return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; + } + + public String getId() { + return id; + } + + public List getIds() { + return ids; + } +} \ No newline at end of file diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java index 1629a5d543ef..c1f6df2cb68d 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java @@ -23,6 +23,7 @@ import org.apache.cloudstack.api.command.ListCoffeeCmd; import org.apache.cloudstack.api.command.CreateCoffeeCmd; import org.apache.cloudstack.api.command.UpdateCoffeeCmd; +import org.apache.cloudstack.api.command.RemoveCoffeeCmd; import java.util.ArrayList; import java.util.List; @@ -35,6 +36,7 @@ public List> getCommands() { cmdList.add(CreateCoffeeCmd.class); cmdList.add(ListCoffeeCmd.class); cmdList.add(UpdateCoffeeCmd.class); + cmdList.add(RemoveCoffeeCmd.class); return cmdList; } } From 5e72ab61566a1340f7699f40e228348f698d50ab Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Mon, 24 Nov 2025 14:29:56 -0500 Subject: [PATCH 09/38] load feature after backend by making it a child of backend. Signed-off-by: Daman Arora --- .../resources/META-INF/cloudstack/feature/module.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/module.properties b/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/module.properties index 5b90727c9f76..f23537394bea 100644 --- a/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/module.properties +++ b/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/module.properties @@ -1,2 +1,2 @@ name=feature -parent=api +parent=backend \ No newline at end of file From 3319d2d037642dedb5772b01ddf07ec316e754fa Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Mon, 24 Nov 2025 15:33:33 -0500 Subject: [PATCH 10/38] use coffeeManager and it's implementation instead of service Signed-off-by: Daman Arora --- .../CoffeeManager.java} | 27 +-- .../cloudstack/feature/CoffeeManagerImpl.java | 195 ++++++++++++++++++ .../feature/spring-feature-context.xml | 6 +- 3 files changed, 210 insertions(+), 18 deletions(-) rename plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/{coffee/CoffeeService.java => api/CoffeeManager.java} (68%) create mode 100644 plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/CoffeeManager.java similarity index 68% rename from plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java rename to plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/CoffeeManager.java index c1f6df2cb68d..e26a4a3afc8f 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/CoffeeManager.java @@ -17,26 +17,21 @@ * under the License. */ -package org.apache.cloudstack.coffee; +package org.apache.cloudstack.api; -import com.cloud.utils.component.PluggableService; -import org.apache.cloudstack.api.command.ListCoffeeCmd; import org.apache.cloudstack.api.command.CreateCoffeeCmd; -import org.apache.cloudstack.api.command.UpdateCoffeeCmd; +import org.apache.cloudstack.api.command.ListCoffeeCmd; import org.apache.cloudstack.api.command.RemoveCoffeeCmd; +import org.apache.cloudstack.api.command.UpdateCoffeeCmd; -import java.util.ArrayList; import java.util.List; -public class CoffeeService implements PluggableService { +public interface CoffeeManager { + Coffee createCoffee(CreateCoffeeCmd cmd); + + List listCoffees(ListCoffeeCmd cmd); + + Coffee updateCoffee(UpdateCoffeeCmd cmd); - @Override - public List> getCommands() { - List> cmdList = new ArrayList<>(); - cmdList.add(CreateCoffeeCmd.class); - cmdList.add(ListCoffeeCmd.class); - cmdList.add(UpdateCoffeeCmd.class); - cmdList.add(RemoveCoffeeCmd.class); - return cmdList; - } -} + boolean removeCoffee(RemoveCoffeeCmd cmd); +} \ No newline at end of file diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java new file mode 100644 index 000000000000..4a3b35d35344 --- /dev/null +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java @@ -0,0 +1,195 @@ +/* + * 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.feature; + +import com.cloud.utils.component.ManagerBase; +import com.cloud.utils.component.PluggableService; +import org.apache.cloudstack.api.Coffee; +import org.apache.cloudstack.api.CoffeeManager; +import org.apache.cloudstack.api.command.CreateCoffeeCmd; +import org.apache.cloudstack.api.command.ListCoffeeCmd; +import org.apache.cloudstack.api.command.RemoveCoffeeCmd; +import org.apache.cloudstack.api.command.UpdateCoffeeCmd; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; + +import javax.naming.ConfigurationException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class CoffeeManagerImpl extends ManagerBase implements CoffeeManager, PluggableService { + + private static final Logger LOGGER = LogManager.getLogger(CoffeeManagerImpl.class); + + private static class HardcodedCoffee implements Coffee { + private final long id; + private final String uuid; + private final String name; + private final Offering offering; + private Size size; + private State state; + + public HardcodedCoffee(long id, String uuid, String name, Offering offering, Size size, State state) { + this.id = id; + this.uuid = uuid; + this.name = name; + this.offering = offering; + this.size = size; + this.state = state; + } + + @Override + public long getId() { return id; } + + @Override + public String getUuid() { return uuid; } + + @Override + public String getName() { return name; } + + @Override + public Offering getOffering() { return offering; } + + @Override + public Size getSize() { return size; } + + public void setSize(Size size) { this.size = size; } + + @Override + public State getState() { return state; } + + public void setState(State state) { this.state = state; } + } + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + super.configure(name, params); + LOGGER.info("CoffeeManager is being configured"); + return true; + } + + @Override + public boolean start() { + LOGGER.info("CoffeeManager is starting"); + return true; + } + + @Override + public boolean stop() { + LOGGER.info("CoffeeManager is stopping"); + return true; + } + + @Override + public List> getCommands() { + final List> cmdList = new ArrayList<>(); + cmdList.add(CreateCoffeeCmd.class); + cmdList.add(ListCoffeeCmd.class); + cmdList.add(UpdateCoffeeCmd.class); + cmdList.add(RemoveCoffeeCmd.class); + return cmdList; + } + + @Override + public Coffee createCoffee(CreateCoffeeCmd cmd) { + LOGGER.info("Creating coffee: " + cmd.getName()); + Coffee coffee = new HardcodedCoffee( + 3L, + "fake-uuid-3", + cmd.getName(), + Coffee.Offering.valueOf(cmd.getOffering()), + Coffee.Size.valueOf(cmd.getSize()), + Coffee.State.Created + ); + + LOGGER.debug("Created coffee with ID: " + coffee.getId()); + return coffee; + } + + @Override + public List listCoffees(ListCoffeeCmd cmd) { + LOGGER.info("Listing coffees"); + List coffees = new ArrayList<>(); + + coffees.add(new HardcodedCoffee(1L, "uuid-1", "Espresso", + Coffee.Offering.Espresso, Coffee.Size.SMALL, Coffee.State.Brewed)); + + coffees.add(new HardcodedCoffee(2L, "uuid-2", "Latte", + Coffee.Offering.Latte, Coffee.Size.LARGE, Coffee.State.Created)); + + coffees.add(new HardcodedCoffee(3L, "uuid-3", "Cappuccino", + Coffee.Offering.Cappuccino, Coffee.Size.MEDIUM, Coffee.State.Brewing)); + + String id = cmd.getId(); + String offering = cmd.getOffering(); + String size = cmd.getSize(); + + List filtered = new ArrayList<>(); + for (Coffee coffee : coffees) { + boolean match = true; + + if (id != null && !String.valueOf(coffee.getId()).equals(id)) { + match = false; + } + if (offering != null && !coffee.getOffering().name().equalsIgnoreCase(offering)) { + match = false; + } + if (size != null && !coffee.getSize().name().equalsIgnoreCase(size)) { + match = false; + } + + if (match) { + filtered.add(coffee); + } + } + + LOGGER.debug("Returning " + filtered.size() + " coffees"); + return filtered; + } + + @Override + public Coffee updateCoffee(UpdateCoffeeCmd cmd) { + LOGGER.info("Updating coffee with ID: " + cmd.getId()); + + HardcodedCoffee coffee = new HardcodedCoffee( + Long.parseLong(cmd.getId()), + "uuid-" + cmd.getId(), + "Updated Coffee Order", + Coffee.Offering.Espresso, + cmd.getSize() != null ? Coffee.Size.valueOf(cmd.getSize()) : Coffee.Size.MEDIUM, + Coffee.State.Created + ); + + LOGGER.debug("Updated coffee: " + coffee.getName()); + return coffee; + } + + @Override + public boolean removeCoffee(RemoveCoffeeCmd cmd) { + if (cmd.getId() != null) { + LOGGER.info("Removing coffee with ID: " + cmd.getId()); + } else if (cmd.getIds() != null) { + LOGGER.info("Removing " + cmd.getIds().size() + " coffees"); + } + + return true; + } +} \ No newline at end of file diff --git a/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml b/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml index d1debec43a7c..64f74a547abb 100644 --- a/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml +++ b/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml @@ -21,5 +21,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - - + + + + \ No newline at end of file From f7cfda98a1ca154b3942a49ed66486b8a66805bd Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Mon, 24 Nov 2025 15:33:41 -0500 Subject: [PATCH 11/38] add coffee resource Signed-off-by: Daman Arora --- .../org/apache/cloudstack/api/Coffee.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java new file mode 100644 index 000000000000..fe076d2ebedd --- /dev/null +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java @@ -0,0 +1,49 @@ +/* + * 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; + +public interface Coffee extends InternalIdentity, Identity { + + enum Size { + SMALL, + MEDIUM, + LARGE + } + + enum Offering { + Espresso, + Cappuccino, + Mocha, + Latte + } + + enum State { + Created, + Brewing, + Brewed + } + + long getId(); + String getUuid(); + String getName(); + Offering getOffering(); + Size getSize(); + State getState(); +} \ No newline at end of file From c1cdfd6969a351c0a27ed6859b35c6db3a400129 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Mon, 24 Nov 2025 15:34:22 -0500 Subject: [PATCH 12/38] use dependency injection and coffee resource in api commands Signed-off-by: Daman Arora --- .../api/command/CreateCoffeeCmd.java | 29 +++--- .../cloudstack/api/command/ListCoffeeCmd.java | 98 +++++++++++++------ .../api/command/RemoveCoffeeCmd.java | 23 +++-- .../api/command/UpdateCoffeeCmd.java | 19 ++-- 4 files changed, 116 insertions(+), 53 deletions(-) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java index 3734a1d64db6..91e69bb9f402 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java @@ -23,9 +23,12 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.Coffee; +import org.apache.cloudstack.api.CoffeeManager; import org.apache.cloudstack.api.response.CoffeeResponse; import org.apache.cloudstack.acl.RoleType; +import javax.inject.Inject; import java.util.Map; @APICommand( @@ -39,6 +42,9 @@ ) public class CreateCoffeeCmd extends BaseAsyncCreateCmd { + @Inject + private CoffeeManager coffeeManager; + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, @@ -63,25 +69,26 @@ public class CreateCoffeeCmd extends BaseAsyncCreateCmd { description = "details for the coffee order") private Map details; - private Long coffeeId; + private Coffee coffee; @Override public void create() { - // Just set a fake ID for now - coffeeId = 3L; - setEntityId(coffeeId); - setEntityUuid("fake-uuid-" + coffeeId); + coffee = coffeeManager.createCoffee(this); + + if (coffee != null) { + setEntityId(coffee.getId()); + setEntityUuid(coffee.getUuid()); + } } @Override public void execute() { - // Hardcoded response for now CoffeeResponse response = new CoffeeResponse(); - response.setId(String.valueOf(coffeeId)); - response.setName(name); - response.setOffering(offering); - response.setSize(size); - response.setState("Created"); + response.setId(coffee.getUuid()); + response.setName(coffee.getName()); + response.setOffering(coffee.getOffering().name()); + response.setSize(coffee.getSize().name()); + response.setState(coffee.getState().name()); response.setObjectName("coffee"); response.setResponseName(getCommandName()); diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java index 348a8cce448f..32c58f90be74 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java @@ -20,55 +20,95 @@ package org.apache.cloudstack.api.command; 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.Coffee; +import org.apache.cloudstack.api.CoffeeManager; import org.apache.cloudstack.api.response.CoffeeResponse; import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.acl.RoleType; +import org.jetbrains.annotations.NotNull; +import javax.inject.Inject; import java.util.ArrayList; import java.util.List; @APICommand( name = "listCoffees", - description = "Lists all coffees", + description = "Lists all coffees with optional filters", responseObject = CoffeeResponse.class, since = "4.23.0.0", requestHasSensitiveInfo = false, - responseHasSensitiveInfo = false + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User} ) public class ListCoffeeCmd extends BaseListCmd { + @Inject + private CoffeeManager coffeeManager; + + @Parameter(name = ApiConstants.ID, + type = CommandType.STRING, + required = false, + description = "the ID of the coffee order") + private String id; + + @Parameter(name = "offering", + type = CommandType.STRING, + required = false, + description = "type of coffee (Espresso, Cappuccino, Mocha, Latte)") + private String offering; + + @Parameter(name = "size", + type = CommandType.STRING, + required = false, + description = "size of coffee (SMALL, MEDIUM, LARGE)") + private String size; + @Override public void execute() { - List coffeeList = new ArrayList<>(); - - CoffeeResponse espresso = new CoffeeResponse(); - espresso.setId("1"); - espresso.setName("Morning Espresso"); - espresso.setOffering("Espresso"); - espresso.setSize("SMALL"); - espresso.setState("Brewed"); - espresso.setObjectName("coffee"); - - CoffeeResponse latte = new CoffeeResponse(); - latte.setId("2"); - latte.setName("Cloud Latte"); - latte.setOffering("Latte"); - latte.setSize("LARGE"); - latte.setState("Created"); - latte.setObjectName("coffee"); - - coffeeList.add(espresso); - coffeeList.add(latte); - - ListResponse response = new ListResponse<>(); - response.setResponses(coffeeList, coffeeList.size()); - response.setResponseName(getCommandName()); - response.setObjectName("coffee"); - setResponseObject(response); + List coffees = coffeeManager.listCoffees(this); + + List responseList = getCoffeeResponses(coffees); + + ListResponse listResponse = new ListResponse<>(); + listResponse.setResponses(responseList, responseList.size()); + listResponse.setResponseName(getCommandName()); + listResponse.setObjectName("coffee"); + setResponseObject(listResponse); + } + + @NotNull + private static List getCoffeeResponses(List coffees) { + List responseList = new ArrayList<>(); + for (Coffee coffee : coffees) { + CoffeeResponse response = new CoffeeResponse(); + response.setId(coffee.getUuid()); + response.setName(coffee.getName()); + response.setOffering(coffee.getOffering().name()); + response.setSize(coffee.getSize().name()); + response.setState(coffee.getState().name()); + response.setObjectName("coffee"); + responseList.add(response); + } + return responseList; } @Override public long getEntityOwnerId() { return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; } -} + + public String getId() { + return id; + } + + public String getOffering() { + return offering; + } + + public String getSize() { + return size; + } +} \ No newline at end of file diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java index 33e711649cbe..ce8d8d489427 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java @@ -23,9 +23,11 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.CoffeeManager; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.acl.RoleType; +import javax.inject.Inject; import java.util.List; @APICommand( @@ -39,6 +41,9 @@ ) public class RemoveCoffeeCmd extends BaseAsyncCmd { + @Inject + private CoffeeManager coffeeManager; + @Parameter(name = ApiConstants.ID, type = CommandType.STRING, required = false, @@ -54,18 +59,22 @@ public class RemoveCoffeeCmd extends BaseAsyncCmd { @Override public void execute() { - // Hardcoded success response for now + boolean result = coffeeManager.removeCoffee(this); + SuccessResponse response = new SuccessResponse(); - if (id != null) { - response.setSuccess(true); - response.setDisplayText("Successfully removed coffee order: " + id); - } else if (ids != null && !ids.isEmpty()) { + if (result) { response.setSuccess(true); - response.setDisplayText("Successfully removed " + ids.size() + " coffee orders"); + if (id != null) { + response.setDisplayText("Successfully removed coffee order: " + id); + } else if (ids != null && !ids.isEmpty()) { + response.setDisplayText("Successfully removed " + ids.size() + " coffee orders"); + } else { + response.setDisplayText("Coffee removal completed"); + } } else { response.setSuccess(false); - response.setDisplayText("No coffee ID provided"); + response.setDisplayText("Failed to remove coffee order"); } response.setResponseName(getCommandName()); diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java index 39e6f3a44b2f..eb142aa2acde 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java @@ -23,9 +23,12 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.Coffee; +import org.apache.cloudstack.api.CoffeeManager; import org.apache.cloudstack.api.response.CoffeeResponse; import org.apache.cloudstack.acl.RoleType; +import javax.inject.Inject; import java.util.Map; @APICommand( @@ -39,6 +42,9 @@ ) public class UpdateCoffeeCmd extends BaseAsyncCmd { + @Inject + private CoffeeManager coffeeManager; + @Parameter(name = ApiConstants.ID, type = CommandType.STRING, required = true, @@ -59,13 +65,14 @@ public class UpdateCoffeeCmd extends BaseAsyncCmd { @Override public void execute() { - // Hardcoded response for now + Coffee coffee = coffeeManager.updateCoffee(this); + CoffeeResponse response = new CoffeeResponse(); - response.setId(id); - response.setName("Updated Coffee Order"); - response.setOffering("Espresso"); - response.setSize(size != null ? size : "MEDIUM"); - response.setState("Created"); + response.setId(coffee.getUuid()); + response.setName(coffee.getName()); + response.setOffering(coffee.getOffering().name()); + response.setSize(coffee.getSize().name()); + response.setState(coffee.getState().name()); response.setObjectName("coffee"); response.setResponseName(getCommandName()); From ff437dae7f6ca946f5e890b4804c546aec6b9061 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Mon, 24 Nov 2025 16:27:20 -0500 Subject: [PATCH 13/38] remove un-needed comment Signed-off-by: Daman Arora --- .../META-INF/cloudstack/feature/spring-feature-context.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml b/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml index 64f74a547abb..ef9d54ad1d30 100644 --- a/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml +++ b/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml @@ -20,8 +20,5 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - - - \ No newline at end of file From 6f8f8c5d00b867792fdcd40f00f990e6ee874341 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Tue, 25 Nov 2025 07:29:48 -0500 Subject: [PATCH 14/38] use naming convention for static variable logger Signed-off-by: Daman Arora --- .../cloudstack/feature/CoffeeManagerImpl.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java index 4a3b35d35344..2fde24d0d17f 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java @@ -37,7 +37,7 @@ public class CoffeeManagerImpl extends ManagerBase implements CoffeeManager, PluggableService { - private static final Logger LOGGER = LogManager.getLogger(CoffeeManagerImpl.class); + private static final Logger s_logger = LogManager.getLogger(CoffeeManagerImpl.class); private static class HardcodedCoffee implements Coffee { private final long id; @@ -82,19 +82,19 @@ public HardcodedCoffee(long id, String uuid, String name, Offering offering, Siz @Override public boolean configure(String name, Map params) throws ConfigurationException { super.configure(name, params); - LOGGER.info("CoffeeManager is being configured"); + s_logger.info("CoffeeManager is being configured"); return true; } @Override public boolean start() { - LOGGER.info("CoffeeManager is starting"); + s_logger.info("CoffeeManager is starting"); return true; } @Override public boolean stop() { - LOGGER.info("CoffeeManager is stopping"); + s_logger.info("CoffeeManager is stopping"); return true; } @@ -110,7 +110,7 @@ public List> getCommands() { @Override public Coffee createCoffee(CreateCoffeeCmd cmd) { - LOGGER.info("Creating coffee: " + cmd.getName()); + s_logger.info("Creating coffee: " + cmd.getName()); Coffee coffee = new HardcodedCoffee( 3L, "fake-uuid-3", @@ -120,13 +120,13 @@ public Coffee createCoffee(CreateCoffeeCmd cmd) { Coffee.State.Created ); - LOGGER.debug("Created coffee with ID: " + coffee.getId()); + s_logger.debug("Created coffee with ID: " + coffee.getId()); return coffee; } @Override public List listCoffees(ListCoffeeCmd cmd) { - LOGGER.info("Listing coffees"); + s_logger.info("Listing coffees"); List coffees = new ArrayList<>(); coffees.add(new HardcodedCoffee(1L, "uuid-1", "Espresso", @@ -161,13 +161,13 @@ public List listCoffees(ListCoffeeCmd cmd) { } } - LOGGER.debug("Returning " + filtered.size() + " coffees"); + s_logger.debug("Returning " + filtered.size() + " coffees"); return filtered; } @Override public Coffee updateCoffee(UpdateCoffeeCmd cmd) { - LOGGER.info("Updating coffee with ID: " + cmd.getId()); + s_logger.info("Updating coffee with ID: " + cmd.getId()); HardcodedCoffee coffee = new HardcodedCoffee( Long.parseLong(cmd.getId()), @@ -178,16 +178,16 @@ public Coffee updateCoffee(UpdateCoffeeCmd cmd) { Coffee.State.Created ); - LOGGER.debug("Updated coffee: " + coffee.getName()); + s_logger.debug("Updated coffee: " + coffee.getName()); return coffee; } @Override public boolean removeCoffee(RemoveCoffeeCmd cmd) { if (cmd.getId() != null) { - LOGGER.info("Removing coffee with ID: " + cmd.getId()); + s_logger.info("Removing coffee with ID: " + cmd.getId()); } else if (cmd.getIds() != null) { - LOGGER.info("Removing " + cmd.getIds().size() + " coffees"); + s_logger.info("Removing " + cmd.getIds().size() + " coffees"); } return true; From 5a2404ef8df165de5e3fd554476018f94d48f7e6 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Tue, 25 Nov 2025 08:49:21 -0500 Subject: [PATCH 15/38] add missing license Signed-off-by: Daman Arora --- .../cloudstack/feature/module.properties | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/module.properties b/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/module.properties index f23537394bea..69a1fd028abd 100644 --- a/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/module.properties +++ b/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/module.properties @@ -1,2 +1,18 @@ +# 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. name=feature -parent=backend \ No newline at end of file +parent=backend From 1356b58f3f6de30359fa25d132439a1b8b8f2a50 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Tue, 25 Nov 2025 10:44:17 -0500 Subject: [PATCH 16/38] add zone scoped coffee.ttl.interval config key Signed-off-by: Daman Arora --- .../cloudstack/feature/CoffeeManagerImpl.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java index 2fde24d0d17f..8d7f636f554e 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java @@ -27,6 +27,8 @@ import org.apache.cloudstack.api.command.ListCoffeeCmd; import org.apache.cloudstack.api.command.RemoveCoffeeCmd; import org.apache.cloudstack.api.command.UpdateCoffeeCmd; +import org.apache.cloudstack.framework.config.Configurable; +import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; @@ -35,10 +37,20 @@ import java.util.List; import java.util.Map; -public class CoffeeManagerImpl extends ManagerBase implements CoffeeManager, PluggableService { +public class CoffeeManagerImpl extends ManagerBase implements CoffeeManager, Configurable, PluggableService { private static final Logger s_logger = LogManager.getLogger(CoffeeManagerImpl.class); + private static final ConfigKey CoffeeTTLInterval = new ConfigKey( + "Advanced", + Long.class, + "coffee.ttl.interval", + "600", + "The max time in seconds after which coffee becomes stale.", + true, + ConfigKey.Scope.Zone + ); + private static class HardcodedCoffee implements Coffee { private final long id; private final String uuid; @@ -108,6 +120,18 @@ public List> getCommands() { return cmdList; } + @Override + public String getConfigComponentName() { + return CoffeeManager.class.getSimpleName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[]{ + CoffeeTTLInterval + }; + } + @Override public Coffee createCoffee(CreateCoffeeCmd cmd) { s_logger.info("Creating coffee: " + cmd.getName()); From 5bfc52ceb452d043fd153585c70dd20dea8eee93 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Tue, 25 Nov 2025 12:54:50 -0500 Subject: [PATCH 17/38] add coffee.gc.interval for running a background task Signed-off-by: Daman Arora --- .../cloudstack/feature/CoffeeManagerImpl.java | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java index 8d7f636f554e..7d54101fa0f8 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java @@ -21,6 +21,9 @@ import com.cloud.utils.component.ManagerBase; import com.cloud.utils.component.PluggableService; +import org.apache.cloudstack.managed.context.ManagedContextRunnable; +import org.apache.cloudstack.poll.BackgroundPollManager; +import org.apache.cloudstack.poll.BackgroundPollTask; import org.apache.cloudstack.api.Coffee; import org.apache.cloudstack.api.CoffeeManager; import org.apache.cloudstack.api.command.CreateCoffeeCmd; @@ -32,6 +35,7 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import javax.inject.Inject; import javax.naming.ConfigurationException; import java.util.ArrayList; import java.util.List; @@ -41,6 +45,9 @@ public class CoffeeManagerImpl extends ManagerBase implements CoffeeManager, Con private static final Logger s_logger = LogManager.getLogger(CoffeeManagerImpl.class); + @Inject + private BackgroundPollManager backgroundPollManager; + private static final ConfigKey CoffeeTTLInterval = new ConfigKey( "Advanced", Long.class, @@ -51,6 +58,16 @@ public class CoffeeManagerImpl extends ManagerBase implements CoffeeManager, Con ConfigKey.Scope.Zone ); + private static final ConfigKey CoffeeGCInterval = new ConfigKey( + "Advanced", + Long.class, + "coffee.gc.interval", + "300", + "The interval in seconds at which the coffee garbage collection task runs.", + true, + ConfigKey.Scope.Zone + ); + private static class HardcodedCoffee implements Coffee { private final long id; private final String uuid; @@ -91,10 +108,41 @@ public HardcodedCoffee(long id, String uuid, String name, Offering offering, Siz public void setState(State state) { this.state = state; } } + private static final class CoffeeGCTask extends ManagedContextRunnable implements BackgroundPollTask { + private CoffeeManager coffeeManager; + + private CoffeeGCTask(CoffeeManager coffeeManager) { + this.coffeeManager = coffeeManager; + } + + @Override + protected void runInContext() { + try { + if (s_logger.isTraceEnabled()) { + s_logger.trace("Coffee GC task is running..."); + } + + final Long ttl = CoffeeTTLInterval.value(); + + s_logger.info("Coffee GC task executed. TTL: " + ttl + " seconds"); + + } catch (final Throwable t) { + s_logger.error("Error trying to run Coffee GC task", t); + } + } + + @Override + public Long getDelay() { + return CoffeeGCInterval.value() * 1000L; + } + } + @Override public boolean configure(String name, Map params) throws ConfigurationException { super.configure(name, params); s_logger.info("CoffeeManager is being configured"); + backgroundPollManager.submitTask(new CoffeeGCTask(this)); + s_logger.info("Coffee GC background task has been scheduled"); return true; } @@ -128,7 +176,8 @@ public String getConfigComponentName() { @Override public ConfigKey[] getConfigKeys() { return new ConfigKey[]{ - CoffeeTTLInterval + CoffeeTTLInterval, + CoffeeGCInterval }; } From ebacdbc2c9598524b1b2765df3025d5e9e4f43b6 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 10:59:17 -0500 Subject: [PATCH 18/38] add coffee table schema Signed-off-by: Daman Arora --- .../resources/META-INF/db/schema-42200to42300.sql | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/engine/schema/src/main/resources/META-INF/db/schema-42200to42300.sql b/engine/schema/src/main/resources/META-INF/db/schema-42200to42300.sql index c1f1bb2c094d..50dbc30512ac 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-42200to42300.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-42200to42300.sql @@ -15,6 +15,15 @@ -- specific language governing permissions and limitations -- under the License. ---; --- Schema upgrade from 4.22.0.0 to 4.23.0.0 ---; +CREATE TABLE IF NOT EXISTS `cloud`.`coffee` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `uuid` varchar(40) UNIQUE, + `name` varchar(255) NOT NULL, + `state` varchar(40) NOT NULL, + `account_id` bigint unsigned NOT NULL, + `created` datetime NOT NULL COMMENT 'date of creation', + `removed` datetime COMMENT 'date of removal', + PRIMARY KEY (`id`), + KEY (`uuid`), + KEY `i_coffee` (`name`, `account_id`, `created`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file From e67c234e9a38bf131a12446bb7e5df972a431305 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 11:03:15 -0500 Subject: [PATCH 19/38] fix typo Signed-off-by: Daman Arora --- .../src/main/resources/META-INF/db/schema-42200to42300.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/engine/schema/src/main/resources/META-INF/db/schema-42200to42300.sql b/engine/schema/src/main/resources/META-INF/db/schema-42200to42300.sql index 50dbc30512ac..c7be029dbd1a 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-42200to42300.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-42200to42300.sql @@ -15,6 +15,9 @@ -- specific language governing permissions and limitations -- under the License. +--; +-- Schema upgrade from 4.22.0.0 to 4.23.0.0 +--; CREATE TABLE IF NOT EXISTS `cloud`.`coffee` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `uuid` varchar(40) UNIQUE, From f9fc8ba0a33b802ca2bb20c23bd6c6cf852f117f Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 11:32:51 -0500 Subject: [PATCH 20/38] add CoffeeVO entity class Signed-off-by: Daman Arora --- .../org/apache/cloudstack/api/Coffee.java | 2 - .../apache/cloudstack/feature/CoffeeVO.java | 144 ++++++++++++++++++ 2 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java index fe076d2ebedd..58ef0ea2280a 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java @@ -43,7 +43,5 @@ enum State { long getId(); String getUuid(); String getName(); - Offering getOffering(); - Size getSize(); State getState(); } \ No newline at end of file diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java new file mode 100644 index 000000000000..7e4e48bafdb1 --- /dev/null +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java @@ -0,0 +1,144 @@ +// 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.feature; + +import org.apache.cloudstack.api.Coffee; + +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 java.util.Date; +import java.util.UUID; + +@Entity +@Table(name = "coffee") +public class CoffeeVO implements Coffee { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "name") + private String name; + + @Column(name = "state") + @Enumerated(value = EnumType.STRING) + private State state = State.Created; + + @Column(name = "account_id") + private long accountId; + + @Column(name = "created") + private Date created; + + @Column(name = "removed") + private Date removed; + + public CoffeeVO() { + this.uuid = UUID.randomUUID().toString(); + } + + public CoffeeVO(String name, long accountId) { + this(); + this.name = name; + this.accountId = accountId; + this.state = State.Created; + } + + @Override + public long getId() { + return id; + } + + @Override + public String getUuid() { + return uuid; + } + + @Override + public String getName() { + return name; + } + + @Override + public State getState() { + return state; + } + + public long getAccountId() { + return accountId; + } + + public Date getCreated() { + return created; + } + + public Date getRemoved() { + return removed; + } + + public void setId(long id) { + this.id = id; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public void setName(String name) { + this.name = name; + } + + public void setState(State state) { + this.state = state; + } + + public void setAccountId(long accountId) { + this.accountId = accountId; + } + + public void setCreated(Date created) { + this.created = created; + } + + public void setRemoved(Date removed) { + this.removed = removed; + } + + @Override + public String toString() { + return "CoffeeVO{" + + "id=" + id + + ", uuid='" + uuid + '\'' + + ", name='" + name + '\'' + + ", state=" + state + + ", accountId=" + accountId + + ", created=" + created + + ", removed=" + removed + + '}'; + } +} \ No newline at end of file From 027a1c4e7ea9bdf77fee9e23799886f0faeb9ece Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 12:16:36 -0500 Subject: [PATCH 21/38] add size and offering getters again Signed-off-by: Daman Arora --- .../feature/src/main/java/org/apache/cloudstack/api/Coffee.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java index 58ef0ea2280a..fe076d2ebedd 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java @@ -43,5 +43,7 @@ enum State { long getId(); String getUuid(); String getName(); + Offering getOffering(); + Size getSize(); State getState(); } \ No newline at end of file From 1a9a1d2303b10c929a50c005f0d028855cb7e703 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 12:17:42 -0500 Subject: [PATCH 22/38] add dao interface and class Signed-off-by: Daman Arora --- .../cloudstack/feature/dao/CoffeeDao.java | 24 +++++++++++++++ .../cloudstack/feature/dao/CoffeeDaoImpl.java | 30 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/dao/CoffeeDao.java create mode 100644 plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/dao/CoffeeDaoImpl.java diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/dao/CoffeeDao.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/dao/CoffeeDao.java new file mode 100644 index 000000000000..1b5124358137 --- /dev/null +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/dao/CoffeeDao.java @@ -0,0 +1,24 @@ +// 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.feature.dao; + +import com.cloud.utils.db.GenericDao; +import org.apache.cloudstack.feature.CoffeeVO; + +public interface CoffeeDao extends GenericDao { +} \ No newline at end of file diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/dao/CoffeeDaoImpl.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/dao/CoffeeDaoImpl.java new file mode 100644 index 000000000000..b330e1b23db5 --- /dev/null +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/dao/CoffeeDaoImpl.java @@ -0,0 +1,30 @@ +// 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.feature.dao; + +import com.cloud.utils.db.GenericDaoBase; +import org.apache.cloudstack.feature.CoffeeVO; +import org.springframework.stereotype.Component; + +@Component +public class CoffeeDaoImpl extends GenericDaoBase implements CoffeeDao { + + public CoffeeDaoImpl() { + super(); + } +} \ No newline at end of file From efd6a02d80421fce30b87aaf5fefbf8c186b70a0 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 12:18:09 -0500 Subject: [PATCH 23/38] update VO with missing getters Signed-off-by: Daman Arora --- .../java/org/apache/cloudstack/feature/CoffeeVO.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java index 7e4e48bafdb1..b8ac724ac6d5 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java @@ -84,6 +84,16 @@ public String getName() { return name; } + @Override + public Offering getOffering() { + return null; + } + + @Override + public Size getSize() { + return null; + } + @Override public State getState() { return state; From 155f23a489097242faf0bf16be5f4b9bf49c87ab Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 12:18:56 -0500 Subject: [PATCH 24/38] register dao class for dependency injection Signed-off-by: Daman Arora --- .../META-INF/cloudstack/feature/spring-feature-context.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml b/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml index ef9d54ad1d30..ec669d96746d 100644 --- a/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml +++ b/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml @@ -21,4 +21,5 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> + \ No newline at end of file From d517c7eacb9374b795549a2d0630af3078b37a5c Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 12:41:28 -0500 Subject: [PATCH 25/38] remove not null - not needed anymore Signed-off-by: Daman Arora --- .../java/org/apache/cloudstack/api/command/ListCoffeeCmd.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java index 32c58f90be74..b2078c0052a4 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.CoffeeResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.acl.RoleType; -import org.jetbrains.annotations.NotNull; import javax.inject.Inject; import java.util.ArrayList; @@ -79,7 +78,6 @@ public void execute() { setResponseObject(listResponse); } - @NotNull private static List getCoffeeResponses(List coffees) { List responseList = new ArrayList<>(); for (Coffee coffee : coffees) { From ff504ac4378f38f31cbbc4f038ddc906243403d2 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 12:41:59 -0500 Subject: [PATCH 26/38] add size and offering to schema Signed-off-by: Daman Arora --- .../META-INF/db/schema-42200to42300.sql | 2 ++ .../apache/cloudstack/feature/CoffeeVO.java | 28 +++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/engine/schema/src/main/resources/META-INF/db/schema-42200to42300.sql b/engine/schema/src/main/resources/META-INF/db/schema-42200to42300.sql index c7be029dbd1a..d9e57194df8e 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-42200to42300.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-42200to42300.sql @@ -22,6 +22,8 @@ CREATE TABLE IF NOT EXISTS `cloud`.`coffee` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `uuid` varchar(40) UNIQUE, `name` varchar(255) NOT NULL, + `offering` varchar(40) NOT NULL, + `size` varchar(40) NOT NULL, `state` varchar(40) NOT NULL, `account_id` bigint unsigned NOT NULL, `created` datetime NOT NULL COMMENT 'date of creation', diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java index b8ac724ac6d5..81457acfa15c 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java @@ -45,6 +45,14 @@ public class CoffeeVO implements Coffee { @Column(name = "name") private String name; + @Column(name = "offering") + @Enumerated(value = EnumType.STRING) + private Offering offering; + + @Column(name = "size") + @Enumerated(value = EnumType.STRING) + private Size size; + @Column(name = "state") @Enumerated(value = EnumType.STRING) private State state = State.Created; @@ -62,9 +70,11 @@ public CoffeeVO() { this.uuid = UUID.randomUUID().toString(); } - public CoffeeVO(String name, long accountId) { + public CoffeeVO(String name, Offering offering, Size size, long accountId) { this(); this.name = name; + this.offering = offering; + this.size = size; this.accountId = accountId; this.state = State.Created; } @@ -86,12 +96,12 @@ public String getName() { @Override public Offering getOffering() { - return null; + return offering; } @Override public Size getSize() { - return null; + return size; } @Override @@ -123,6 +133,14 @@ public void setName(String name) { this.name = name; } + public void setOffering(Offering offering) { + this.offering = offering; + } + + public void setSize(Size size) { + this.size = size; + } + public void setState(State state) { this.state = state; } @@ -145,10 +163,10 @@ public String toString() { "id=" + id + ", uuid='" + uuid + '\'' + ", name='" + name + '\'' + + ", offering=" + offering + + ", size=" + size + ", state=" + state + ", accountId=" + accountId + - ", created=" + created + - ", removed=" + removed + '}'; } } \ No newline at end of file From 1380c08fc45c8266fcf45e7ac0b4ecae5a256124 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 13:04:59 -0500 Subject: [PATCH 27/38] remove hardcoded data and use dao Signed-off-by: Daman Arora --- .../cloudstack/feature/CoffeeManagerImpl.java | 126 +++++++----------- 1 file changed, 47 insertions(+), 79 deletions(-) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java index 7d54101fa0f8..fed06938c33d 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java @@ -21,6 +21,7 @@ import com.cloud.utils.component.ManagerBase; import com.cloud.utils.component.PluggableService; +import com.cloud.utils.exception.CloudRuntimeException; import org.apache.cloudstack.managed.context.ManagedContextRunnable; import org.apache.cloudstack.poll.BackgroundPollManager; import org.apache.cloudstack.poll.BackgroundPollTask; @@ -30,6 +31,7 @@ import org.apache.cloudstack.api.command.ListCoffeeCmd; import org.apache.cloudstack.api.command.RemoveCoffeeCmd; import org.apache.cloudstack.api.command.UpdateCoffeeCmd; +import org.apache.cloudstack.feature.dao.CoffeeDao; import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.logging.log4j.Logger; @@ -45,6 +47,9 @@ public class CoffeeManagerImpl extends ManagerBase implements CoffeeManager, Con private static final Logger s_logger = LogManager.getLogger(CoffeeManagerImpl.class); + @Inject + private CoffeeDao coffeeDao; + @Inject private BackgroundPollManager backgroundPollManager; @@ -68,48 +73,8 @@ public class CoffeeManagerImpl extends ManagerBase implements CoffeeManager, Con ConfigKey.Scope.Zone ); - private static class HardcodedCoffee implements Coffee { - private final long id; - private final String uuid; - private final String name; - private final Offering offering; - private Size size; - private State state; - - public HardcodedCoffee(long id, String uuid, String name, Offering offering, Size size, State state) { - this.id = id; - this.uuid = uuid; - this.name = name; - this.offering = offering; - this.size = size; - this.state = state; - } - - @Override - public long getId() { return id; } - - @Override - public String getUuid() { return uuid; } - - @Override - public String getName() { return name; } - - @Override - public Offering getOffering() { return offering; } - - @Override - public Size getSize() { return size; } - - public void setSize(Size size) { this.size = size; } - - @Override - public State getState() { return state; } - - public void setState(State state) { this.state = state; } - } - private static final class CoffeeGCTask extends ManagedContextRunnable implements BackgroundPollTask { - private CoffeeManager coffeeManager; + private final CoffeeManager coffeeManager; private CoffeeGCTask(CoffeeManager coffeeManager) { this.coffeeManager = coffeeManager; @@ -184,48 +149,34 @@ public ConfigKey[] getConfigKeys() { @Override public Coffee createCoffee(CreateCoffeeCmd cmd) { s_logger.info("Creating coffee: " + cmd.getName()); - Coffee coffee = new HardcodedCoffee( - 3L, - "fake-uuid-3", - cmd.getName(), - Coffee.Offering.valueOf(cmd.getOffering()), - Coffee.Size.valueOf(cmd.getSize()), - Coffee.State.Created - ); - - s_logger.debug("Created coffee with ID: " + coffee.getId()); + + Coffee.Offering offering = Coffee.Offering.valueOf(cmd.getOffering()); + Coffee.Size size = Coffee.Size.valueOf(cmd.getSize()); + + CoffeeVO coffee = new CoffeeVO(cmd.getName(), offering, size, 1L); + coffee = coffeeDao.persist(coffee); + + s_logger.debug("Created coffee with ID: " + coffee.getId() + ", UUID: " + coffee.getUuid()); return coffee; } @Override public List listCoffees(ListCoffeeCmd cmd) { s_logger.info("Listing coffees"); - List coffees = new ArrayList<>(); - - coffees.add(new HardcodedCoffee(1L, "uuid-1", "Espresso", - Coffee.Offering.Espresso, Coffee.Size.SMALL, Coffee.State.Brewed)); - - coffees.add(new HardcodedCoffee(2L, "uuid-2", "Latte", - Coffee.Offering.Latte, Coffee.Size.LARGE, Coffee.State.Created)); - coffees.add(new HardcodedCoffee(3L, "uuid-3", "Cappuccino", - Coffee.Offering.Cappuccino, Coffee.Size.MEDIUM, Coffee.State.Brewing)); + List coffees = coffeeDao.listAll(); String id = cmd.getId(); - String offering = cmd.getOffering(); - String size = cmd.getSize(); List filtered = new ArrayList<>(); - for (Coffee coffee : coffees) { + for (CoffeeVO coffee : coffees) { + if (coffee.getRemoved() != null) { + continue; + } + boolean match = true; - if (id != null && !String.valueOf(coffee.getId()).equals(id)) { - match = false; - } - if (offering != null && !coffee.getOffering().name().equalsIgnoreCase(offering)) { - match = false; - } - if (size != null && !coffee.getSize().name().equalsIgnoreCase(size)) { + if (id != null && coffee.getId() != Long.parseLong(id)) { match = false; } @@ -242,14 +193,18 @@ public List listCoffees(ListCoffeeCmd cmd) { public Coffee updateCoffee(UpdateCoffeeCmd cmd) { s_logger.info("Updating coffee with ID: " + cmd.getId()); - HardcodedCoffee coffee = new HardcodedCoffee( - Long.parseLong(cmd.getId()), - "uuid-" + cmd.getId(), - "Updated Coffee Order", - Coffee.Offering.Espresso, - cmd.getSize() != null ? Coffee.Size.valueOf(cmd.getSize()) : Coffee.Size.MEDIUM, - Coffee.State.Created - ); + long id = Long.parseLong(cmd.getId()); + CoffeeVO coffee = coffeeDao.findById(id); + + if (coffee == null) { + throw new CloudRuntimeException("Coffee with ID " + id + " not found"); + } + + if (cmd.getSize() != null) { + s_logger.debug("Size update requested but not yet supported in minimal schema"); + } + + coffeeDao.update(id, coffee); s_logger.debug("Updated coffee: " + coffee.getName()); return coffee; @@ -259,10 +214,23 @@ public Coffee updateCoffee(UpdateCoffeeCmd cmd) { public boolean removeCoffee(RemoveCoffeeCmd cmd) { if (cmd.getId() != null) { s_logger.info("Removing coffee with ID: " + cmd.getId()); + long id = Long.parseLong(cmd.getId()); + + boolean result = coffeeDao.remove(id); + + if (!result) { + throw new CloudRuntimeException("Failed to remove coffee with ID " + id); + } + + return true; } else if (cmd.getIds() != null) { s_logger.info("Removing " + cmd.getIds().size() + " coffees"); + for (String id : cmd.getIds()) { + coffeeDao.remove(Long.parseLong(id)); + } + return true; } - return true; + return false; } } \ No newline at end of file From e0523c1a28fd949a9f1025e180fb3c1c30f7af50 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 14:59:17 -0500 Subject: [PATCH 28/38] fix filter and update logic Signed-off-by: Daman Arora --- .../cloudstack/feature/CoffeeManagerImpl.java | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java index fed06938c33d..bfa05fbd97a1 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java @@ -166,34 +166,41 @@ public List listCoffees(ListCoffeeCmd cmd) { List coffees = coffeeDao.listAll(); - String id = cmd.getId(); + Long id = cmd.getId(); + String offering = cmd.getOffering(); + String size = cmd.getSize(); + + List filteredCoffeeList = new ArrayList<>(); - List filtered = new ArrayList<>(); for (CoffeeVO coffee : coffees) { - if (coffee.getRemoved() != null) { - continue; + boolean isCoffeeFound = true; + + if (id != null && coffee.getId() != id) { + isCoffeeFound = false; } - boolean match = true; + if (offering != null && !coffee.getOffering().name().equalsIgnoreCase(offering)) { + isCoffeeFound = false; + } - if (id != null && coffee.getId() != Long.parseLong(id)) { - match = false; + if (size != null && !coffee.getSize().name().equalsIgnoreCase(size)) { + isCoffeeFound = false; } - if (match) { - filtered.add(coffee); + if (isCoffeeFound) { + filteredCoffeeList.add(coffee); } } - s_logger.debug("Returning " + filtered.size() + " coffees"); - return filtered; + s_logger.debug("Returning " + filteredCoffeeList.size() + " coffees"); + return filteredCoffeeList; } @Override public Coffee updateCoffee(UpdateCoffeeCmd cmd) { s_logger.info("Updating coffee with ID: " + cmd.getId()); - long id = Long.parseLong(cmd.getId()); + long id = cmd.getId(); CoffeeVO coffee = coffeeDao.findById(id); if (coffee == null) { @@ -201,7 +208,7 @@ public Coffee updateCoffee(UpdateCoffeeCmd cmd) { } if (cmd.getSize() != null) { - s_logger.debug("Size update requested but not yet supported in minimal schema"); + coffee.setSize(Coffee.Size.valueOf(cmd.getSize())); } coffeeDao.update(id, coffee); @@ -214,7 +221,7 @@ public Coffee updateCoffee(UpdateCoffeeCmd cmd) { public boolean removeCoffee(RemoveCoffeeCmd cmd) { if (cmd.getId() != null) { s_logger.info("Removing coffee with ID: " + cmd.getId()); - long id = Long.parseLong(cmd.getId()); + long id = cmd.getId(); boolean result = coffeeDao.remove(id); From e75c4f9698c74fbb60bdd73ec0eb3a877cc30735 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 14:59:38 -0500 Subject: [PATCH 29/38] fix type for id Signed-off-by: Daman Arora --- .../org/apache/cloudstack/api/command/ListCoffeeCmd.java | 6 +++--- .../org/apache/cloudstack/api/command/RemoveCoffeeCmd.java | 6 +++--- .../org/apache/cloudstack/api/command/UpdateCoffeeCmd.java | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java index b2078c0052a4..7b671e05e569 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java @@ -48,10 +48,10 @@ public class ListCoffeeCmd extends BaseListCmd { private CoffeeManager coffeeManager; @Parameter(name = ApiConstants.ID, - type = CommandType.STRING, + type = CommandType.UUID, required = false, description = "the ID of the coffee order") - private String id; + private Long id; @Parameter(name = "offering", type = CommandType.STRING, @@ -98,7 +98,7 @@ public long getEntityOwnerId() { return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; } - public String getId() { + public Long getId() { return id; } diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java index ce8d8d489427..d5ef4aa8b357 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java @@ -45,10 +45,10 @@ public class RemoveCoffeeCmd extends BaseAsyncCmd { private CoffeeManager coffeeManager; @Parameter(name = ApiConstants.ID, - type = CommandType.STRING, + type = CommandType.UUID, required = false, description = "the ID of the coffee order to remove") - private String id; + private Long id; @Parameter(name = "ids", type = CommandType.LIST, @@ -101,7 +101,7 @@ public long getEntityOwnerId() { return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; } - public String getId() { + public Long getId() { return id; } diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java index eb142aa2acde..947e06d02305 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java @@ -46,10 +46,10 @@ public class UpdateCoffeeCmd extends BaseAsyncCmd { private CoffeeManager coffeeManager; @Parameter(name = ApiConstants.ID, - type = CommandType.STRING, + type = CommandType.UUID, required = true, description = "the ID of the coffee order") - private String id; + private Long id; @Parameter(name = "size", type = CommandType.STRING, @@ -94,7 +94,7 @@ public long getEntityOwnerId() { return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; } - public String getId() { + public Long getId() { return id; } From b951b3a1bca5bd40955f1f4d9a1f63c47f01a07b Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 15:08:05 -0500 Subject: [PATCH 30/38] Replace UUID with LONG for id param Signed-off-by: Daman Arora --- .../java/org/apache/cloudstack/api/command/ListCoffeeCmd.java | 2 +- .../java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java | 2 +- .../java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java index 7b671e05e569..59abba16ddd0 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java @@ -48,7 +48,7 @@ public class ListCoffeeCmd extends BaseListCmd { private CoffeeManager coffeeManager; @Parameter(name = ApiConstants.ID, - type = CommandType.UUID, + type = CommandType.LONG, required = false, description = "the ID of the coffee order") private Long id; diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java index d5ef4aa8b357..9e73f8589c7d 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java @@ -45,7 +45,7 @@ public class RemoveCoffeeCmd extends BaseAsyncCmd { private CoffeeManager coffeeManager; @Parameter(name = ApiConstants.ID, - type = CommandType.UUID, + type = CommandType.LONG, required = false, description = "the ID of the coffee order to remove") private Long id; diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java index 947e06d02305..77458b45431f 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java @@ -46,7 +46,7 @@ public class UpdateCoffeeCmd extends BaseAsyncCmd { private CoffeeManager coffeeManager; @Parameter(name = ApiConstants.ID, - type = CommandType.UUID, + type = CommandType.LONG, required = true, description = "the ID of the coffee order") private Long id; From d7d073fd685213618be0f522ad741bd2822a80ea Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 17:00:45 -0500 Subject: [PATCH 31/38] code cleanup for api commands Signed-off-by: Daman Arora --- .../org/apache/cloudstack/api/Coffee.java | 2 - .../api/command/CreateCoffeeCmd.java | 43 +++++++++------ .../cloudstack/api/command/ListCoffeeCmd.java | 53 ++++++++++++------- .../api/command/RemoveCoffeeCmd.java | 31 +++++++---- .../api/command/UpdateCoffeeCmd.java | 35 +++++++----- .../api/response/CoffeeResponse.java | 24 ++------- 6 files changed, 107 insertions(+), 81 deletions(-) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java index fe076d2ebedd..31b85650dc75 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java @@ -40,8 +40,6 @@ enum State { Brewed } - long getId(); - String getUuid(); String getName(); Offering getOffering(); Size getSize(); diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java index 91e69bb9f402..9ad6df1e4a6b 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java @@ -32,7 +32,7 @@ import java.util.Map; @APICommand( - name = "createCoffee", + name = CreateCoffeeCmd.APINAME, description = "Creates a new coffee order", responseObject = CoffeeResponse.class, since = "4.23.0.0", @@ -41,10 +41,15 @@ authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User} ) public class CreateCoffeeCmd extends BaseAsyncCreateCmd { + public static final String APINAME = "createCoffee"; @Inject private CoffeeManager coffeeManager; + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, @@ -71,6 +76,22 @@ public class CreateCoffeeCmd extends BaseAsyncCreateCmd { private Coffee coffee; + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getName() { + return name; + } + + public String getOffering() { + return offering; + } + + public String getSize() { + return size; + } + @Override public void create() { coffee = coffeeManager.createCoffee(this); @@ -81,6 +102,10 @@ public void create() { } } + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override public void execute() { CoffeeResponse response = new CoffeeResponse(); @@ -109,20 +134,4 @@ public String getEventDescription() { public long getEntityOwnerId() { return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; } - - public String getName() { - return name; - } - - public String getOffering() { - return offering; - } - - public String getSize() { - return size; - } - - public Map getDetails() { - return details; - } } \ No newline at end of file diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java index 59abba16ddd0..5cb623fe8564 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java @@ -34,7 +34,7 @@ import java.util.List; @APICommand( - name = "listCoffees", + name = ListCoffeeCmd.APINAME, description = "Lists all coffees with optional filters", responseObject = CoffeeResponse.class, since = "4.23.0.0", @@ -43,10 +43,15 @@ authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User} ) public class ListCoffeeCmd extends BaseListCmd { + public static final String APINAME = "listCoffees"; @Inject private CoffeeManager coffeeManager; + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = false, @@ -65,19 +70,26 @@ public class ListCoffeeCmd extends BaseListCmd { description = "size of coffee (SMALL, MEDIUM, LARGE)") private String size; - @Override - public void execute() { - List coffees = coffeeManager.listCoffees(this); + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// - List responseList = getCoffeeResponses(coffees); + public Long getId() { + return id; + } - ListResponse listResponse = new ListResponse<>(); - listResponse.setResponses(responseList, responseList.size()); - listResponse.setResponseName(getCommandName()); - listResponse.setObjectName("coffee"); - setResponseObject(listResponse); + public String getOffering() { + return offering; + } + + public String getSize() { + return size; } + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + private static List getCoffeeResponses(List coffees) { List responseList = new ArrayList<>(); for (Coffee coffee : coffees) { @@ -94,19 +106,20 @@ private static List getCoffeeResponses(List coffees) { } @Override - public long getEntityOwnerId() { - return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; - } + public void execute() { + List coffees = coffeeManager.listCoffees(this); - public Long getId() { - return id; - } + List responseList = getCoffeeResponses(coffees); - public String getOffering() { - return offering; + ListResponse listResponse = new ListResponse<>(); + listResponse.setResponses(responseList, responseList.size()); + listResponse.setResponseName(getCommandName()); + listResponse.setObjectName("coffee"); + setResponseObject(listResponse); } - public String getSize() { - return size; + @Override + public long getEntityOwnerId() { + return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; } } \ No newline at end of file diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java index 9e73f8589c7d..78f80a6fd4a7 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java @@ -31,7 +31,7 @@ import java.util.List; @APICommand( - name = "removeCoffee", + name = RemoveCoffeeCmd.APINAME, description = "Removes a coffee order or multiple coffee orders", responseObject = SuccessResponse.class, since = "4.23.0.0", @@ -40,10 +40,15 @@ authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User} ) public class RemoveCoffeeCmd extends BaseAsyncCmd { + public static final String APINAME = "removeCoffee"; @Inject private CoffeeManager coffeeManager; + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = false, @@ -57,6 +62,22 @@ public class RemoveCoffeeCmd extends BaseAsyncCmd { description = "the IDs of coffee orders to remove") private List ids; + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + public List getIds() { + return ids; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override public void execute() { boolean result = coffeeManager.removeCoffee(this); @@ -100,12 +121,4 @@ public String getEventDescription() { public long getEntityOwnerId() { return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; } - - public Long getId() { - return id; - } - - public List getIds() { - return ids; - } } \ No newline at end of file diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java index 77458b45431f..c136f74d8f38 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java @@ -32,7 +32,7 @@ import java.util.Map; @APICommand( - name = "updateCoffee", + name = UpdateCoffeeCmd.APINAME, description = "Updates an existing coffee order", responseObject = CoffeeResponse.class, since = "4.23.0.0", @@ -41,10 +41,15 @@ authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User} ) public class UpdateCoffeeCmd extends BaseAsyncCmd { + public static final String APINAME = "updateCoffee"; @Inject private CoffeeManager coffeeManager; + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = true, @@ -63,6 +68,22 @@ public class UpdateCoffeeCmd extends BaseAsyncCmd { description = "updated details for the coffee order") private Map details; + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + public String getSize() { + return size; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override public void execute() { Coffee coffee = coffeeManager.updateCoffee(this); @@ -93,16 +114,4 @@ public String getEventDescription() { public long getEntityOwnerId() { return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; } - - public Long getId() { - return id; - } - - public String getSize() { - return size; - } - - public Map getDetails() { - return details; - } } \ No newline at end of file diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/response/CoffeeResponse.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/response/CoffeeResponse.java index 71b67a140394..bc72b0358dfe 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/response/CoffeeResponse.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/response/CoffeeResponse.java @@ -1,28 +1,12 @@ -/* - * 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 com.google.gson.annotations.SerializedName; import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.EntityReference; +import org.apache.cloudstack.api.Coffee; import com.cloud.serializer.Param; +@EntityReference(value = Coffee.class) public class CoffeeResponse extends BaseResponse { @SerializedName("id") @@ -50,4 +34,4 @@ public class CoffeeResponse extends BaseResponse { public void setOffering(String offering) { this.offering = offering; } public void setSize(String size) { this.size = size; } public void setState(String state) { this.state = state; } -} +} \ No newline at end of file From 9ec07cfa3f75cf7cfe6e710d3958aa7239c80670 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 17:40:05 -0500 Subject: [PATCH 32/38] code cleanup Signed-off-by: Daman Arora --- .../api/response/CoffeeResponse.java | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/response/CoffeeResponse.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/response/CoffeeResponse.java index bc72b0358dfe..f47800574914 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/response/CoffeeResponse.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/response/CoffeeResponse.java @@ -1,31 +1,50 @@ +// 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 com.google.gson.annotations.SerializedName; import org.apache.cloudstack.api.BaseResponse; import org.apache.cloudstack.api.EntityReference; import org.apache.cloudstack.api.Coffee; +import org.apache.cloudstack.api.ApiConstants; import com.cloud.serializer.Param; @EntityReference(value = Coffee.class) public class CoffeeResponse extends BaseResponse { + public static final String OFFERING = "offering"; + public static final String SIZE = "size"; - @SerializedName("id") + @SerializedName(ApiConstants.ID) @Param(description = "the coffee ID") private String id; - @SerializedName("name") + @SerializedName(ApiConstants.NAME) @Param(description = "the coffee name") private String name; - @SerializedName("offering") + @SerializedName(OFFERING) @Param(description = "the type of coffee") private String offering; - @SerializedName("size") + @SerializedName(SIZE) @Param(description = "the size of coffee") private String size; - @SerializedName("state") + @SerializedName(ApiConstants.STATE) @Param(description = "current coffee state") private String state; From 73f9dcb87a0431849d73548c3219dfffefc7de45 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 19:16:25 -0500 Subject: [PATCH 33/38] code cleanup Signed-off-by: Daman Arora --- plugins/hackerbook/feature/pom.xml | 2 +- .../main/java/org/apache/cloudstack/api/Coffee.java | 2 +- .../java/org/apache/cloudstack/api/CoffeeManager.java | 2 +- .../apache/cloudstack/api/command/CreateCoffeeCmd.java | 10 +++++----- .../apache/cloudstack/api/command/ListCoffeeCmd.java | 2 +- .../apache/cloudstack/api/command/RemoveCoffeeCmd.java | 2 +- .../apache/cloudstack/api/command/UpdateCoffeeCmd.java | 2 +- .../apache/cloudstack/api/response/CoffeeResponse.java | 2 +- .../apache/cloudstack/feature/CoffeeManagerImpl.java | 2 +- .../java/org/apache/cloudstack/feature/CoffeeVO.java | 2 +- .../org/apache/cloudstack/feature/dao/CoffeeDao.java | 2 +- .../apache/cloudstack/feature/dao/CoffeeDaoImpl.java | 2 +- .../cloudstack/feature/spring-feature-context.xml | 2 +- 13 files changed, 17 insertions(+), 17 deletions(-) diff --git a/plugins/hackerbook/feature/pom.xml b/plugins/hackerbook/feature/pom.xml index a109105dc81b..a88f5657c4aa 100644 --- a/plugins/hackerbook/feature/pom.xml +++ b/plugins/hackerbook/feature/pom.xml @@ -45,4 +45,4 @@ 11 UTF-8 - \ No newline at end of file + diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java index 31b85650dc75..f67f4b5863ef 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java @@ -44,4 +44,4 @@ enum State { Offering getOffering(); Size getSize(); State getState(); -} \ No newline at end of file +} diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/CoffeeManager.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/CoffeeManager.java index e26a4a3afc8f..12f45684a390 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/CoffeeManager.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/CoffeeManager.java @@ -34,4 +34,4 @@ public interface CoffeeManager { Coffee updateCoffee(UpdateCoffeeCmd cmd); boolean removeCoffee(RemoveCoffeeCmd cmd); -} \ No newline at end of file +} diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java index 9ad6df1e4a6b..e12ed7c566f4 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java @@ -92,6 +92,10 @@ public String getSize() { return size; } + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override public void create() { coffee = coffeeManager.createCoffee(this); @@ -102,10 +106,6 @@ public void create() { } } - ///////////////////////////////////////////////////// - /////////////// API Implementation/////////////////// - ///////////////////////////////////////////////////// - @Override public void execute() { CoffeeResponse response = new CoffeeResponse(); @@ -134,4 +134,4 @@ public String getEventDescription() { public long getEntityOwnerId() { return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; } -} \ No newline at end of file +} diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java index 5cb623fe8564..16b555b416b4 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java @@ -122,4 +122,4 @@ public void execute() { public long getEntityOwnerId() { return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; } -} \ No newline at end of file +} diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java index 78f80a6fd4a7..8fd2a8236694 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java @@ -121,4 +121,4 @@ public String getEventDescription() { public long getEntityOwnerId() { return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; } -} \ No newline at end of file +} diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java index c136f74d8f38..9e2eeace4d79 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java @@ -114,4 +114,4 @@ public String getEventDescription() { public long getEntityOwnerId() { return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; } -} \ No newline at end of file +} diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/response/CoffeeResponse.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/response/CoffeeResponse.java index f47800574914..79ad10d9148c 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/response/CoffeeResponse.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/response/CoffeeResponse.java @@ -53,4 +53,4 @@ public class CoffeeResponse extends BaseResponse { public void setOffering(String offering) { this.offering = offering; } public void setSize(String size) { this.size = size; } public void setState(String state) { this.state = state; } -} \ No newline at end of file +} diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java index bfa05fbd97a1..c07b14b53e88 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java @@ -240,4 +240,4 @@ public boolean removeCoffee(RemoveCoffeeCmd cmd) { return false; } -} \ No newline at end of file +} diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java index 81457acfa15c..ab42a0752b92 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java @@ -169,4 +169,4 @@ public String toString() { ", accountId=" + accountId + '}'; } -} \ No newline at end of file +} diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/dao/CoffeeDao.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/dao/CoffeeDao.java index 1b5124358137..567392c6dcec 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/dao/CoffeeDao.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/dao/CoffeeDao.java @@ -21,4 +21,4 @@ import org.apache.cloudstack.feature.CoffeeVO; public interface CoffeeDao extends GenericDao { -} \ No newline at end of file +} diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/dao/CoffeeDaoImpl.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/dao/CoffeeDaoImpl.java index b330e1b23db5..c584b0221a61 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/dao/CoffeeDaoImpl.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/dao/CoffeeDaoImpl.java @@ -27,4 +27,4 @@ public class CoffeeDaoImpl extends GenericDaoBase implements Cof public CoffeeDaoImpl() { super(); } -} \ No newline at end of file +} diff --git a/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml b/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml index ec669d96746d..75db0aa7c013 100644 --- a/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml +++ b/plugins/hackerbook/feature/src/main/resources/META-INF/cloudstack/feature/spring-feature-context.xml @@ -22,4 +22,4 @@ http://www.springframework.org/schema/beans/spring-beans.xsd"> - \ No newline at end of file + From 5fb8b1c8396880cc7e910002c7cb240eb145ef90 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 19:17:59 -0500 Subject: [PATCH 34/38] code cleanup Signed-off-by: Daman Arora --- .../src/main/resources/META-INF/db/schema-42200to42300.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/schema/src/main/resources/META-INF/db/schema-42200to42300.sql b/engine/schema/src/main/resources/META-INF/db/schema-42200to42300.sql index d9e57194df8e..48b7e9ce640a 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-42200to42300.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-42200to42300.sql @@ -31,4 +31,4 @@ CREATE TABLE IF NOT EXISTS `cloud`.`coffee` ( PRIMARY KEY (`id`), KEY (`uuid`), KEY `i_coffee` (`name`, `account_id`, `created`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=utf8; From a77127a5b5ea4ab4e10a68b29cb6d3a492f28dc9 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 19:28:38 -0500 Subject: [PATCH 35/38] fix spacing Signed-off-by: Daman Arora --- .../org/apache/cloudstack/api/command/CreateCoffeeCmd.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java index e12ed7c566f4..eb657f950f46 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java @@ -46,6 +46,8 @@ public class CreateCoffeeCmd extends BaseAsyncCreateCmd { @Inject private CoffeeManager coffeeManager; + private Coffee coffee; + ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// @@ -74,8 +76,6 @@ public class CreateCoffeeCmd extends BaseAsyncCreateCmd { description = "details for the coffee order") private Map details; - private Coffee coffee; - ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// From 0e11495e1f839843d90fd98d646cab810e802860 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 20:08:53 -0500 Subject: [PATCH 36/38] code cleanup Signed-off-by: Daman Arora --- .../org/apache/cloudstack/api/Coffee.java | 46 +++++++++-- .../apache/cloudstack/api/CoffeeManager.java | 5 ++ .../api/command/CreateCoffeeCmd.java | 14 +--- .../cloudstack/api/command/ListCoffeeCmd.java | 25 +----- .../api/command/RemoveCoffeeCmd.java | 9 ++- .../api/command/UpdateCoffeeCmd.java | 13 +--- .../cloudstack/feature/CoffeeManagerImpl.java | 77 ++++++++++++------- .../apache/cloudstack/feature/CoffeeVO.java | 5 +- 8 files changed, 112 insertions(+), 82 deletions(-) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java index f67f4b5863ef..7fb706f03a5d 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/Coffee.java @@ -19,29 +19,61 @@ package org.apache.cloudstack.api; +/** + * Represents a coffee order in the system. + * @since 4.23.0.0 + */ public interface Coffee extends InternalIdentity, Identity { + /** + * Size options for coffee orders. + */ enum Size { SMALL, MEDIUM, LARGE } + /** + * Available coffee offerings/types. + */ enum Offering { - Espresso, - Cappuccino, - Mocha, - Latte + ESPRESSO, + CAPPUCCINO, + MOCHA, + LATTE } + /** + * Lifecycle states for a coffee order. + */ enum State { - Created, - Brewing, - Brewed + CREATED, + BREWING, + BREWED } + /** + * Returns the name of the coffee order. + * @return the coffee name + */ String getName(); + + /** + * Returns the type of coffee ordered. + * @return the coffee offering type + */ Offering getOffering(); + + /** + * Returns the size of the coffee order. + * @return the coffee size + */ Size getSize(); + + /** + * Returns the current state of the coffee order. + * @return the coffee state + */ State getState(); } diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/CoffeeManager.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/CoffeeManager.java index 12f45684a390..ee97063f3a1a 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/CoffeeManager.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/CoffeeManager.java @@ -23,6 +23,7 @@ import org.apache.cloudstack.api.command.ListCoffeeCmd; import org.apache.cloudstack.api.command.RemoveCoffeeCmd; import org.apache.cloudstack.api.command.UpdateCoffeeCmd; +import org.apache.cloudstack.api.response.CoffeeResponse; import java.util.List; @@ -34,4 +35,8 @@ public interface CoffeeManager { Coffee updateCoffee(UpdateCoffeeCmd cmd); boolean removeCoffee(RemoveCoffeeCmd cmd); + + CoffeeResponse createCoffeeResponse(Coffee coffee); + + List createCoffeeResponses(List coffees); } diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java index eb657f950f46..00319e405ed3 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java @@ -27,6 +27,7 @@ import org.apache.cloudstack.api.CoffeeManager; import org.apache.cloudstack.api.response.CoffeeResponse; import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.context.CallContext; import javax.inject.Inject; import java.util.Map; @@ -61,7 +62,7 @@ public class CreateCoffeeCmd extends BaseAsyncCreateCmd { @Parameter(name = "offering", type = CommandType.STRING, required = true, - description = "type of coffee (Espresso, Cappuccino, Mocha, Latte)") + description = "type of coffee (ESPRESSO, CAPPUCCINO, MOCHA, LATTE)") private String offering; @Parameter(name = "size", @@ -108,15 +109,8 @@ public void create() { @Override public void execute() { - CoffeeResponse response = new CoffeeResponse(); - response.setId(coffee.getUuid()); - response.setName(coffee.getName()); - response.setOffering(coffee.getOffering().name()); - response.setSize(coffee.getSize().name()); - response.setState(coffee.getState().name()); - response.setObjectName("coffee"); + CoffeeResponse response = coffeeManager.createCoffeeResponse(coffee); response.setResponseName(getCommandName()); - setResponseObject(response); } @@ -132,6 +126,6 @@ public String getEventDescription() { @Override public long getEntityOwnerId() { - return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; + return CallContext.current().getCallingAccountId(); } } diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java index 16b555b416b4..1099553e538e 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/ListCoffeeCmd.java @@ -28,9 +28,9 @@ import org.apache.cloudstack.api.response.CoffeeResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.context.CallContext; import javax.inject.Inject; -import java.util.ArrayList; import java.util.List; @APICommand( @@ -61,7 +61,7 @@ public class ListCoffeeCmd extends BaseListCmd { @Parameter(name = "offering", type = CommandType.STRING, required = false, - description = "type of coffee (Espresso, Cappuccino, Mocha, Latte)") + description = "type of coffee (ESPRESSO, CAPPUCCINO, MOCHA, LATTE)") private String offering; @Parameter(name = "size", @@ -90,36 +90,19 @@ public String getSize() { /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// - private static List getCoffeeResponses(List coffees) { - List responseList = new ArrayList<>(); - for (Coffee coffee : coffees) { - CoffeeResponse response = new CoffeeResponse(); - response.setId(coffee.getUuid()); - response.setName(coffee.getName()); - response.setOffering(coffee.getOffering().name()); - response.setSize(coffee.getSize().name()); - response.setState(coffee.getState().name()); - response.setObjectName("coffee"); - responseList.add(response); - } - return responseList; - } - @Override public void execute() { List coffees = coffeeManager.listCoffees(this); - - List responseList = getCoffeeResponses(coffees); + List responseList = coffeeManager.createCoffeeResponses(coffees); ListResponse listResponse = new ListResponse<>(); listResponse.setResponses(responseList, responseList.size()); listResponse.setResponseName(getCommandName()); - listResponse.setObjectName("coffee"); setResponseObject(listResponse); } @Override public long getEntityOwnerId() { - return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; + return CallContext.current().getCallingAccountId(); } } diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java index 8fd2a8236694..05bbeca3e3d9 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/RemoveCoffeeCmd.java @@ -26,6 +26,7 @@ import org.apache.cloudstack.api.CoffeeManager; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.context.CallContext; import javax.inject.Inject; import java.util.List; @@ -57,10 +58,10 @@ public class RemoveCoffeeCmd extends BaseAsyncCmd { @Parameter(name = "ids", type = CommandType.LIST, - collectionType = CommandType.STRING, + collectionType = CommandType.LONG, required = false, description = "the IDs of coffee orders to remove") - private List ids; + private List ids; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -70,7 +71,7 @@ public Long getId() { return id; } - public List getIds() { + public List getIds() { return ids; } @@ -119,6 +120,6 @@ public String getEventDescription() { @Override public long getEntityOwnerId() { - return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; + return CallContext.current().getCallingAccountId(); } } diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java index 9e2eeace4d79..bc45a72eb726 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java @@ -27,6 +27,7 @@ import org.apache.cloudstack.api.CoffeeManager; import org.apache.cloudstack.api.response.CoffeeResponse; import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.context.CallContext; import javax.inject.Inject; import java.util.Map; @@ -87,16 +88,8 @@ public String getSize() { @Override public void execute() { Coffee coffee = coffeeManager.updateCoffee(this); - - CoffeeResponse response = new CoffeeResponse(); - response.setId(coffee.getUuid()); - response.setName(coffee.getName()); - response.setOffering(coffee.getOffering().name()); - response.setSize(coffee.getSize().name()); - response.setState(coffee.getState().name()); - response.setObjectName("coffee"); + CoffeeResponse response = coffeeManager.createCoffeeResponse(coffee); response.setResponseName(getCommandName()); - setResponseObject(response); } @@ -112,6 +105,6 @@ public String getEventDescription() { @Override public long getEntityOwnerId() { - return com.cloud.user.Account.ACCOUNT_ID_SYSTEM; + return CallContext.current().getCallingAccountId(); } } diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java index c07b14b53e88..8835678146d0 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeManagerImpl.java @@ -31,6 +31,7 @@ import org.apache.cloudstack.api.command.ListCoffeeCmd; import org.apache.cloudstack.api.command.RemoveCoffeeCmd; import org.apache.cloudstack.api.command.UpdateCoffeeCmd; +import org.apache.cloudstack.api.response.CoffeeResponse; import org.apache.cloudstack.feature.dao.CoffeeDao; import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.ConfigKey; @@ -44,14 +45,13 @@ import java.util.Map; public class CoffeeManagerImpl extends ManagerBase implements CoffeeManager, Configurable, PluggableService { - - private static final Logger s_logger = LogManager.getLogger(CoffeeManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject - private CoffeeDao coffeeDao; + private CoffeeDao _coffeeDao; @Inject - private BackgroundPollManager backgroundPollManager; + private BackgroundPollManager _backgroundPollManager; private static final ConfigKey CoffeeTTLInterval = new ConfigKey( "Advanced", @@ -83,16 +83,16 @@ private CoffeeGCTask(CoffeeManager coffeeManager) { @Override protected void runInContext() { try { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Coffee GC task is running..."); + if (logger.isTraceEnabled()) { + logger.trace("Coffee GC task is running..."); } final Long ttl = CoffeeTTLInterval.value(); - s_logger.info("Coffee GC task executed. TTL: " + ttl + " seconds"); + logger.info("Coffee GC task executed. TTL: " + ttl + " seconds"); } catch (final Throwable t) { - s_logger.error("Error trying to run Coffee GC task", t); + logger.error("Error trying to run Coffee GC task", t); } } @@ -105,21 +105,21 @@ public Long getDelay() { @Override public boolean configure(String name, Map params) throws ConfigurationException { super.configure(name, params); - s_logger.info("CoffeeManager is being configured"); - backgroundPollManager.submitTask(new CoffeeGCTask(this)); - s_logger.info("Coffee GC background task has been scheduled"); + logger.info("CoffeeManager is being configured"); + _backgroundPollManager.submitTask(new CoffeeGCTask(this)); + logger.info("Coffee GC background task has been scheduled"); return true; } @Override public boolean start() { - s_logger.info("CoffeeManager is starting"); + logger.info("CoffeeManager is starting"); return true; } @Override public boolean stop() { - s_logger.info("CoffeeManager is stopping"); + logger.info("CoffeeManager is stopping"); return true; } @@ -146,25 +146,46 @@ public ConfigKey[] getConfigKeys() { }; } + @Override + public CoffeeResponse createCoffeeResponse(Coffee coffee) { + CoffeeResponse response = new CoffeeResponse(); + response.setId(coffee.getUuid()); + response.setName(coffee.getName()); + response.setOffering(coffee.getOffering().name()); + response.setSize(coffee.getSize().name()); + response.setState(coffee.getState().name()); + response.setObjectName("coffee"); + return response; + } + + @Override + public List createCoffeeResponses(List coffees) { + List responses = new ArrayList<>(); + for (Coffee coffee : coffees) { + responses.add(createCoffeeResponse(coffee)); + } + return responses; + } + @Override public Coffee createCoffee(CreateCoffeeCmd cmd) { - s_logger.info("Creating coffee: " + cmd.getName()); + logger.info("Creating coffee: " + cmd.getName()); Coffee.Offering offering = Coffee.Offering.valueOf(cmd.getOffering()); Coffee.Size size = Coffee.Size.valueOf(cmd.getSize()); CoffeeVO coffee = new CoffeeVO(cmd.getName(), offering, size, 1L); - coffee = coffeeDao.persist(coffee); + coffee = _coffeeDao.persist(coffee); - s_logger.debug("Created coffee with ID: " + coffee.getId() + ", UUID: " + coffee.getUuid()); + logger.debug("Created coffee with ID: " + coffee.getId() + ", UUID: " + coffee.getUuid()); return coffee; } @Override public List listCoffees(ListCoffeeCmd cmd) { - s_logger.info("Listing coffees"); + logger.info("Listing coffees"); - List coffees = coffeeDao.listAll(); + List coffees = _coffeeDao.listAll(); Long id = cmd.getId(); String offering = cmd.getOffering(); @@ -192,16 +213,16 @@ public List listCoffees(ListCoffeeCmd cmd) { } } - s_logger.debug("Returning " + filteredCoffeeList.size() + " coffees"); + logger.debug("Returning " + filteredCoffeeList.size() + " coffees"); return filteredCoffeeList; } @Override public Coffee updateCoffee(UpdateCoffeeCmd cmd) { - s_logger.info("Updating coffee with ID: " + cmd.getId()); + logger.info("Updating coffee with ID: " + cmd.getId()); long id = cmd.getId(); - CoffeeVO coffee = coffeeDao.findById(id); + CoffeeVO coffee = _coffeeDao.findById(id); if (coffee == null) { throw new CloudRuntimeException("Coffee with ID " + id + " not found"); @@ -211,19 +232,19 @@ public Coffee updateCoffee(UpdateCoffeeCmd cmd) { coffee.setSize(Coffee.Size.valueOf(cmd.getSize())); } - coffeeDao.update(id, coffee); + _coffeeDao.update(id, coffee); - s_logger.debug("Updated coffee: " + coffee.getName()); + logger.debug("Updated coffee: " + coffee.getName()); return coffee; } @Override public boolean removeCoffee(RemoveCoffeeCmd cmd) { if (cmd.getId() != null) { - s_logger.info("Removing coffee with ID: " + cmd.getId()); + logger.info("Removing coffee with ID: " + cmd.getId()); long id = cmd.getId(); - boolean result = coffeeDao.remove(id); + boolean result = _coffeeDao.remove(id); if (!result) { throw new CloudRuntimeException("Failed to remove coffee with ID " + id); @@ -231,9 +252,9 @@ public boolean removeCoffee(RemoveCoffeeCmd cmd) { return true; } else if (cmd.getIds() != null) { - s_logger.info("Removing " + cmd.getIds().size() + " coffees"); - for (String id : cmd.getIds()) { - coffeeDao.remove(Long.parseLong(id)); + logger.info("Removing " + cmd.getIds().size() + " coffees"); + for (Long id : cmd.getIds()) { + _coffeeDao.remove(id); } return true; } diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java index ab42a0752b92..850345bbbe3b 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/feature/CoffeeVO.java @@ -55,7 +55,7 @@ public class CoffeeVO implements Coffee { @Column(name = "state") @Enumerated(value = EnumType.STRING) - private State state = State.Created; + private State state = State.CREATED; @Column(name = "account_id") private long accountId; @@ -76,7 +76,8 @@ public CoffeeVO(String name, Offering offering, Size size, long accountId) { this.offering = offering; this.size = size; this.accountId = accountId; - this.state = State.Created; + this.state = State.CREATED; + this.created = new Date(); } @Override From e6660dce7b32afe1b34ed7e0ccd484f2a3d701c8 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 26 Nov 2025 20:17:59 -0500 Subject: [PATCH 37/38] remove unused code Signed-off-by: Daman Arora --- .../org/apache/cloudstack/api/command/CreateCoffeeCmd.java | 6 ------ .../org/apache/cloudstack/api/command/UpdateCoffeeCmd.java | 6 ------ 2 files changed, 12 deletions(-) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java index 00319e405ed3..99b8d8c17b2d 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java @@ -71,12 +71,6 @@ public class CreateCoffeeCmd extends BaseAsyncCreateCmd { description = "size of coffee (SMALL, MEDIUM, LARGE)") private String size; - @Parameter(name = "details", - type = CommandType.MAP, - required = false, - description = "details for the coffee order") - private Map details; - ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java index bc45a72eb726..c5fd059a2fff 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java @@ -63,12 +63,6 @@ public class UpdateCoffeeCmd extends BaseAsyncCmd { description = "new size of coffee (SMALL, MEDIUM, LARGE)") private String size; - @Parameter(name = "details", - type = CommandType.MAP, - required = false, - description = "updated details for the coffee order") - private Map details; - ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// From 0584c0234a3fceadecb54501dfb62224f57effef Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Thu, 27 Nov 2025 05:38:15 -0500 Subject: [PATCH 38/38] remove unused imports Signed-off-by: Daman Arora --- .../java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java | 1 - .../java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java | 1 - 2 files changed, 2 deletions(-) diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java index 99b8d8c17b2d..a98a9209cc51 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/CreateCoffeeCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.context.CallContext; import javax.inject.Inject; -import java.util.Map; @APICommand( name = CreateCoffeeCmd.APINAME, diff --git a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java index c5fd059a2fff..1e450927b4d7 100644 --- a/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java +++ b/plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/api/command/UpdateCoffeeCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.context.CallContext; import javax.inject.Inject; -import java.util.Map; @APICommand( name = UpdateCoffeeCmd.APINAME,