Skip to content

Commit

Permalink
merge master to 3.1.9 (#1037)
Browse files Browse the repository at this point in the history
* add stop biz state (#1026)

* add stop biz state

* update ark version

* fix test

(cherry picked from commit 7ab39b4)

* add error stack in biz history record message (#1028)

(cherry picked from commit 96f5fc2)

* update to 3.1.9-SNAPSHOT

* add get for bizstate record
  • Loading branch information
lvjing2 authored Nov 27, 2024
1 parent c9ddc88 commit 42a8cb8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
</modules>

<properties>
<sofa.ark.version>3.1.8</sofa.ark.version>
<sofa.ark.version.old>3.1.7</sofa.ark.version.old>
<sofa.ark.version>3.1.9-SNAPSHOT</sofa.ark.version>
<sofa.ark.version.old>3.1.8</sofa.ark.version.old>
<project.encoding>UTF-8</project.encoding>
<java.version>17</java.version>
<license.maven.plugin>3.0</license.maven.plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand Down Expand Up @@ -343,7 +345,7 @@ private void doStart(String[] args, Map<String, String> envs) throws Throwable {
getIdentity(), (System.currentTimeMillis() - start));
}
} catch (Throwable e) {
setBizState(BizState.BROKEN, StateChangeReason.INSTALL_FAILED, e.getMessage());
setBizState(BizState.BROKEN, StateChangeReason.INSTALL_FAILED, getStackTraceAsString(e));
eventAdminService.sendEvent(new AfterBizStartupFailedEvent(this, e));
throw e;
} finally {
Expand Down Expand Up @@ -421,7 +423,7 @@ public void stop() {
BizManagerService bizManagerService = ArkServiceContainerHolder.getContainer()
.getService(BizManagerService.class);
bizManagerService.unRegisterBiz(bizName, bizVersion);
setBizState(BizState.UNRESOLVED, StateChangeReason.STOPPED);
setBizState(BizState.STOPPED, StateChangeReason.STOPPED);
eventAdminService.sendEvent(new BeforeBizRecycleEvent(this));
urls = null;
denyImportPackages = null;
Expand Down Expand Up @@ -642,4 +644,11 @@ private static String markBizTempWorkDirRecycled(File bizTempWorkDir) throws IOE

return targetPath;
}

private static String getStackTraceAsString(Throwable throwable) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
throwable.printStackTrace(pw);
return sw.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void testStopFailedWithClean() {
bizModel.stop();
} catch (RuntimeException e) {
}
assertEquals(BizState.UNRESOLVED, bizModel.getBizState());
assertEquals(BizState.STOPPED, bizModel.getBizState());
}

bizModel.setBizState(BizState.ACTIVATED);
Expand Down Expand Up @@ -186,7 +186,7 @@ public void testStopSucceedWithClean() {
mockedStatic.when(ArkServiceContainerHolder::getContainer).thenReturn(arkServiceContainer);
bizModel.stop();

assertEquals(BizState.UNRESOLVED, bizModel.getBizState());
assertEquals(BizState.STOPPED, bizModel.getBizState());
}

bizModel.setBizState(BizState.ACTIVATED);
Expand All @@ -201,7 +201,7 @@ public void testStopSucceedWithClean() {
mockedStatic.when(ArkServiceContainerHolder::getContainer).thenReturn(arkServiceContainer);
bizModel.stop();

assertEquals(BizState.UNRESOLVED, bizModel.getBizState());
assertEquals(BizState.STOPPED, bizModel.getBizState());
} finally {
ArkConfigs.putStringValue(AUTO_UNINSTALL_WHEN_FAILED_ENABLE, "true");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,22 @@ public String toString() {
return String.format("%s -> %s with reason: %s and message: %s", date, state, reason,
message);
}

public Date getChangeTime() {
return changeTime;
}

public BizState getState() {
return state;
}

public StateChangeReason getReason() {
return reason;
}

public String getMessage() {
return message;
}
}

enum StateChangeReason {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
*/
public enum BizState {
/**
* init but not start install yet
* or
* uninstalled
* not init or not start install yet
*/
UNRESOLVED("unresolved"),
/**
Expand All @@ -45,9 +43,14 @@ public enum BizState {
DEACTIVATED("deactivated"),

/**
* install failed.
* install or uninstall failed.
*/
BROKEN("broken");
BROKEN("broken"),

/**
* uninstall succeed
*/
STOPPED("stopped");

private String state;

Expand All @@ -73,6 +76,8 @@ public static BizState of(String state) {
return ACTIVATED;
} else if (DEACTIVATED.name().equalsIgnoreCase(state)) {
return DEACTIVATED;
} else if (STOPPED.name().equalsIgnoreCase(state)) {
return STOPPED;
} else {
return BROKEN;
}
Expand Down

0 comments on commit 42a8cb8

Please sign in to comment.