Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
</build>

<dependencies>
<dependency>
<groupId>org.zstack</groupId>
<artifactId>helloworld</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.zstack</groupId>
<artifactId>core</artifactId>
Expand Down Expand Up @@ -606,6 +611,11 @@
</build>

<dependencies>
<dependency>
<groupId>org.zstack</groupId>
<artifactId>helloworld</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.zstack</groupId>
<artifactId>core</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions conf/db/upgrade/V4.10.26__schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE `GreetingVO` (
`uuid` VARCHAR(32) NOT NULL,
`greeting` VARCHAR(255) NOT NULL,
`lastOpDate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
`createDate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1 change: 1 addition & 0 deletions conf/persistence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,6 @@
<class>org.zstack.header.resourceattribute.entity.ResourceAttributeKeyResourceTypeVO</class>
<class>org.zstack.header.resourceattribute.entity.ResourceAttributeConstraintVO</class>
<class>org.zstack.softwarePackage.header.SoftwarePackageVO</class>
<class>org.zstack.plugin.example.GreetingVO</class>
</persistence-unit>
</persistence>
15 changes: 15 additions & 0 deletions conf/serviceConfig/helloworld.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<service xmlns="http://zstack.org/schema/zstack">
<id>helloworld</id>
<interceptor>HelloWorldApiInterceptor</interceptor>

<message>
<name>org.zstack.plugin.example.APIHelloWorldMsg</name>
</message>
<message>
<name>org.zstack.plugin.example.APICreateGreetingMsg</name>
</message>
<message>
<name>org.zstack.plugin.example.APIDeleteGreetingMsg</name>
</message>
</service>
27 changes: 27 additions & 0 deletions conf/springConfigXml/helloworld.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:zstack="http://zstack.org/schema/zstack"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://zstack.org/schema/zstack
http://zstack.org/schema/zstack/plugin.xsd"
default-init-method="init" default-destroy-method="destroy">

<bean id="HelloWorldApiInterceptor" class="org.zstack.plugin.example.HelloWorldApiInterceptor" >
<zstack:plugin>
<zstack:extension interface="org.zstack.header.apimediator.ApiMessageInterceptor"/>
</zstack:plugin>
</bean>

<bean id="HelloWorldManager" class="org.zstack.plugin.example.HelloWorldManagerImpl" >
<zstack:plugin>
<zstack:extension interface="org.zstack.header.Component" />
<zstack:extension interface="org.zstack.header.Service" />
</zstack:plugin>
</bean>
</beans>
1 change: 1 addition & 0 deletions conf/zstack.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,5 @@
<import resource="springConfigXml/sugonSdnController.xml"/>
<import resource="springConfigXml/TfPortAllocator.xml"/>
<import resource="springConfigXml/HostNetworkManager.xml"/>
<import resource="springConfigXml/helloworld.xml"/>
</beans>
76 changes: 76 additions & 0 deletions plugin/helloworld/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>plugin</artifactId>
<groupId>org.zstack</groupId>
<version>4.10.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>helloworld</artifactId>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${project.compiler.version}</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<source>${project.java.version}</source>
<target>${project.java.version}</target>
<debuglevel>lines,vars,source</debuglevel>
<debug>true</debug>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>${groovy.eclipse.compiler}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>${groovy.eclipse.batch}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>${aspectj.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<source>${project.java.version}</source>
<target>${project.java.version}</target>
<complianceLevel>${project.java.version}</complianceLevel>
<XnoInline>true</XnoInline>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>org.zstack</groupId>
<artifactId>core</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>org.zstack</groupId>
<artifactId>header</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.zstack.plugin.example;

import org.zstack.header.message.APIEvent;
import org.zstack.header.rest.RestResponse;

@RestResponse(allTo = "inventory")
public class APICreateGreetingEvent extends APIEvent {
private GreetingInventory inventory;

public APICreateGreetingEvent() {
}

public APICreateGreetingEvent(String apiId) {
super(apiId);
}

public GreetingInventory getInventory() {
return inventory;
}

public void setInventory(GreetingInventory inventory) {
this.inventory = inventory;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.zstack.plugin.example;

import org.springframework.http.HttpMethod;
import org.zstack.header.message.APICreateMessage;
import org.zstack.header.message.APIParam;
import org.zstack.header.rest.RestRequest;


@RestRequest(path = "/helloworld/greetings", method = HttpMethod.POST, responseClass = APICreateGreetingEvent.class, parameterName = "params")
public class APICreateGreetingMsg extends APICreateMessage {
@APIParam(emptyString = false)
private String greeting;

public String getGreeting() {
return greeting;
}

public void setGreeting(String greeting) {
this.greeting = greeting;
}
}
Comment on lines +9 to +21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

缺少 __example__,API 文档生成会缺口。
Line 10 的 API 消息类需要提供 __example__ 以生成 API 文档与模板。

✅ 建议补充
 public class APICreateGreetingMsg extends APICreateMessage {
@@
     public void setGreeting(String greeting) {
         this.greeting = greeting;
     }
+
+    public static APICreateGreetingMsg __example__() {
+        APICreateGreetingMsg msg = new APICreateGreetingMsg();
+        msg.setGreeting("hello");
+        return msg;
+    }
 }
根据编码规范。
🤖 Prompt for AI Agents
In
`@plugin/helloworld/src/main/java/org/zstack/plugin/example/APICreateGreetingMsg.java`
around lines 9 - 21, APICreateGreetingMsg is missing a static __example__ method
used by the API doc generator; add a public static APICreateGreetingMsg
__example__() method that constructs and returns an instance with the greeting
field populated (e.g., new APICreateGreetingMsg().setGreeting(...)), ensuring
the method uses the class APICreateGreetingMsg and the greeting accessor/mutator
(getGreeting/setGreeting) to produce a representative example object for docs
and templates.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.zstack.plugin.example;

import org.zstack.header.message.APIEvent;
import org.zstack.header.rest.RestResponse;

@RestResponse
public class APIDeleteGreetingEvent extends APIEvent {
public APIDeleteGreetingEvent() {
}

public APIDeleteGreetingEvent(String apiId) {
super(apiId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.zstack.plugin.example;

import org.springframework.http.HttpMethod;
import org.zstack.header.message.APIDeleteMessage;
import org.zstack.header.rest.RestRequest;

@RestRequest(path = "/helloworld/greetings/{uuid}", method = HttpMethod.DELETE, responseClass = APIDeleteGreetingEvent.class)
public class APIDeleteGreetingMsg extends APIDeleteMessage implements GreetingMessage {
private String uuid;

public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

@Override
public String getGreetingUuid() {
return uuid;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.zstack.plugin.example;

import org.zstack.header.message.APIEvent;
import org.zstack.header.rest.RestResponse;

@RestResponse(allTo = "greeting")
public class APIHelloWorldEvent extends APIEvent {
private String greeting;

public APIHelloWorldEvent() {
}

public APIHelloWorldEvent(String apiId) {
super(apiId);
}

public String getGreeting() {
return greeting;
}

public void setGreeting(String greeting) {
this.greeting = greeting;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.zstack.plugin.example;

import org.springframework.http.HttpMethod;
import org.zstack.header.message.APIMessage;
import org.zstack.header.message.APIParam;
import org.zstack.header.rest.RestRequest;

@RestRequest(path = "/helloworld/greetings", method = HttpMethod.GET, responseClass = APIHelloWorldEvent.class)
public class APIHelloWorldMsg extends APIMessage {
@APIParam(maxLength = 255)
private String greeting;

public String getGreeting() {
return greeting;
}

public void setGreeting(String greeting) {
this.greeting = greeting;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.zstack.plugin.example;

import org.zstack.header.message.Message;

public interface Greeting {
void handleMessage(Message msg);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.zstack.plugin.example;

import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.zstack.core.cloudbus.CloudBus;
import org.zstack.core.db.DatabaseFacade;
import org.zstack.header.message.APIMessage;
import org.zstack.header.message.Message;

@Configurable(preConstruction = true, autowire = Autowire.BY_TYPE)
public class GreetingBase implements Greeting {
protected GreetingVO self;

@Autowired
protected CloudBus bus;
@Autowired
protected DatabaseFacade dbf;

public GreetingBase(GreetingVO self) {
this.self = self;
}

@Override
public void handleMessage(Message msg) {
if (msg instanceof APIMessage) {
handleApiMessage((APIMessage) msg);
} else {
handleLocalMessage(msg);
}
}

private void handleLocalMessage(Message msg) {
bus.dealWithUnknownMessage(msg);
}

private void handleApiMessage(APIMessage msg) {
if (msg instanceof APIDeleteGreetingMsg) {
handle((APIDeleteGreetingMsg) msg);
} else {
bus.dealWithUnknownMessage(msg);
}
}

private void handle(APIDeleteGreetingMsg msg) {
dbf.remove(self);

bus.publish(new APIDeleteGreetingEvent(msg.getId()));
}
}
Loading