-
Notifications
You must be signed in to change notification settings - Fork 0
WIP: Add Coffee management plugin for HackerBook training #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7eea001
e4ff60f
b14b726
72b9ca7
364cd4c
5dacb24
cd7acf5
e06880f
5e72ab6
3319d2d
f7cfda9
c1cdfd6
ff437da
6f8f8c5
5a2404e
1356b58
5bfc52c
ebacdbc
e67c234
f9fc8ba
027a1c4
1a9a1d2
efd6a02
155f23a
d517c7e
ff504ac
1380c08
e0523c1
e75c4f9
b951b3a
d7d073f
9ec07cf
73f9dcb
5fb8b1c
a77127a
0e11495
e6660dc
0584c02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <!-- | ||
| 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. | ||
| --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <artifactId>cloud-plugin-hackerbook-feature</artifactId> | ||
| <name>Apache CloudStack Plugin - HackerBook Coffee Feature</name> | ||
| <parent> | ||
| <groupId>org.apache.cloudstack</groupId> | ||
| <artifactId>cloudstack-plugins</artifactId> | ||
| <version>4.23.0.0-SNAPSHOT</version> | ||
| <relativePath>../../pom.xml</relativePath> | ||
| </parent> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.cloudstack</groupId> | ||
| <artifactId>cloud-api</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.cloudstack</groupId> | ||
| <artifactId>cloud-utils</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| </dependencies> | ||
| <properties> | ||
| <maven.compiler.source>11</maven.compiler.source> | ||
| <maven.compiler.target>11</maven.compiler.target> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| </properties> | ||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| /** | ||
| * 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 | ||
| } | ||
|
|
||
| /** | ||
| * Lifecycle states for a coffee order. | ||
| */ | ||
| enum State { | ||
| 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(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| 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.cloudstack.api.response.CoffeeResponse; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface CoffeeManager { | ||
| Coffee createCoffee(CreateCoffeeCmd cmd); | ||
|
|
||
| List<Coffee> listCoffees(ListCoffeeCmd cmd); | ||
|
|
||
| Coffee updateCoffee(UpdateCoffeeCmd cmd); | ||
|
|
||
| boolean removeCoffee(RemoveCoffeeCmd cmd); | ||
|
|
||
| CoffeeResponse createCoffeeResponse(Coffee coffee); | ||
|
|
||
| List<CoffeeResponse> createCoffeeResponses(List<Coffee> coffees); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /* | ||
| * 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.Coffee; | ||
| 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; | ||
|
|
||
| @APICommand( | ||
| name = CreateCoffeeCmd.APINAME, | ||
| 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 { | ||
| public static final String APINAME = "createCoffee"; | ||
|
|
||
| @Inject | ||
| private CoffeeManager coffeeManager; | ||
|
|
||
| private Coffee coffee; | ||
|
|
||
| ///////////////////////////////////////////////////// | ||
| //////////////// API parameters ///////////////////// | ||
| ///////////////////////////////////////////////////// | ||
|
|
||
| @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; | ||
|
|
||
| ///////////////////////////////////////////////////// | ||
| /////////////////// Accessors /////////////////////// | ||
| ///////////////////////////////////////////////////// | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public String getOffering() { | ||
| return offering; | ||
| } | ||
|
|
||
| public String getSize() { | ||
| return size; | ||
| } | ||
|
|
||
| ///////////////////////////////////////////////////// | ||
| /////////////// API Implementation/////////////////// | ||
| ///////////////////////////////////////////////////// | ||
|
|
||
| @Override | ||
| public void create() { | ||
| coffee = coffeeManager.createCoffee(this); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think coffee can be defined as a local variable to this method and not outside of it
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
| if (coffee != null) { | ||
| setEntityId(coffee.getId()); | ||
| setEntityUuid(coffee.getUuid()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| CoffeeResponse response = coffeeManager.createCoffeeResponse(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 CallContext.current().getCallingAccountId(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revisit these properties? We are currently using JDK 17