Skip to content
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

merge master to 2.1.8-SNAPSHOT #214

Merged
merged 4 commits into from
Nov 27, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@
package com.alipay.sofa.koupleless.arklet.tunnel.mqtt.model;

import com.alipay.sofa.ark.spi.model.BizState;
import com.alipay.sofa.ark.spi.model.BizInfo.BizStateRecord;
import com.alipay.sofa.koupleless.arklet.core.command.builtin.model.BizInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
* <p>SimpleBizInfo class.</p>
Expand All @@ -28,6 +34,7 @@
* @since 2024/10/10
* @version 1.0.0
*/
@Data
public class SimpleBizInfo implements Serializable {
// 序列化版本号
private static final long serialVersionUID = 1L;
Expand All @@ -39,65 +46,22 @@ public class SimpleBizInfo implements Serializable {
private String version;

/**
* Getter method for property <tt>state</tt>.
*
* @return property value of state
* laster state record
*/
public String getState() {
return state;
}

/**
* Setter method for property <tt>state</tt>.
*
* @param state value to be assigned to property state
*/
public void setState(BizState state) {
this.state = state.getBizState();
}

/**
* Getter method for property <tt>name</tt>.
*
* @return property value of name
*/
public String getName() {
return name;
}

/**
* Setter method for property <tt>name</tt>.
*
* @param name value to be assigned to property name
*/
public void setName(String name) {
this.name = name;
}

/**
* Getter method for property <tt>v</tt>.
*
* @return property value of v
*/
public String getVersion() {
return version;
}

/**
* Setter method for property <tt>v</tt>.
*
* @param version value to be assigned to property v
*/
public void setVersion(String version) {
this.version = version;
}
private BizStateRecord latestStateRecord;

public static SimpleBizInfo constructFromBizInfo(BizInfo info) {
SimpleBizInfo simpleBizInfo = new SimpleBizInfo();
simpleBizInfo.setState(info.getBizState());
simpleBizInfo.setState(info.getBizState().getBizState());
simpleBizInfo.setName(info.getBizName());
simpleBizInfo.setVersion(info.getBizVersion());

List<BizStateRecord> bizStateRecords = info.getBizStateRecords();

if (bizStateRecords != null && !bizStateRecords.isEmpty()) {
simpleBizInfo.setLatestStateRecord(bizStateRecords.get(bizStateRecords.size() - 1));
}

return simpleBizInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,28 +185,22 @@ public void handleCommand(String cmd, MqttMessage msg) throws ArkletRuntimeExcep
ArkletLoggerFactory.getDefaultLogger().info("mqtt handle command {} with content {}", cmd,
msg);
Output<?> output;
Map<String, Object> bizOperationResponse = new HashMap<>();
try {
if (cmd.equals(BuiltinCommand.INSTALL_BIZ.getId())
|| cmd.equals(BuiltinCommand.UNINSTALL_BIZ.getId())) {
Map<String, Object> cmdContent = JSONObject.parseObject(msg.toString(),
HashMap.class);
output = commandService.process(cmd, cmdContent);
// install or uninstall command, send result to biz operation response topic
Map<String, Object> bizOperationResponse = new HashMap<>();
bizOperationResponse.put(Constants.COMMAND, cmd);
bizOperationResponse.put(BIZ_NAME, cmdContent.get(BIZ_NAME));
bizOperationResponse.put(BIZ_VERSION, cmdContent.get(BIZ_VERSION));

output = commandService.process(cmd, cmdContent);
// install or uninstall command, send result to biz operation response topic
bizOperationResponse.put(Constants.COMMAND_RESPONSE, output);
mqttClient.publish(getBizOperationResponseTopic(),
JSONObject.toJSONString(MqttResponse.withData(bizOperationResponse)).getBytes(),
1, false);
// sync biz status after operation, queryAllBiz and send result to biz topic
Output<?> allBizOutput = commandService
.process(BuiltinCommand.QUERY_ALL_BIZ.getId(), null);
mqttClient.publish(getBizTopic(), JSONObject
.toJSONString(MqttResponse.withData(getSimpleAllBizInfo(allBizOutput)),
SerializerFeature.SkipTransientField, SerializerFeature.WriteMapNullValue)
.getBytes(), 1, false);
} else if (cmd.equals("baseline")) {
List<Map<String, Object>> cmdContents = JSONObject.parseObject(msg.toString(),
List.class);
Expand Down Expand Up @@ -239,7 +233,7 @@ public void handleCommand(String cmd, MqttMessage msg) throws ArkletRuntimeExcep
1, false);
} else {
throw new ArkletRuntimeException(
String.format("unsupported command %s or content %s", cmd, msg));
String.format("unsupported command %s with content: %s", cmd, msg));
}
} catch (Throwable e) {
ClientResponse data = new ClientResponse();
Expand All @@ -248,7 +242,6 @@ public void handleCommand(String cmd, MqttMessage msg) throws ArkletRuntimeExcep
output = Output.ofFailed(data, e.getMessage());

// install or uninstall command, send result to biz operation response topic
Map<String, Object> bizOperationResponse = new HashMap<>();
bizOperationResponse.put(Constants.COMMAND, cmd);
bizOperationResponse.put(Constants.COMMAND_RESPONSE, output);
try {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<properties>
<revision>2.1.8-SNAPSHOT</revision>
<sofa.ark.version>3.1.8</sofa.ark.version>
<sofa.ark.version>3.1.9-SNAPSHOT</sofa.ark.version>
<koupleless.runtime.version>${revision}</koupleless.runtime.version>
<spring.boot.version>3.2.1</spring.boot.version>
<project.encoding>UTF-8</project.encoding>
Expand Down