Skip to content

Commit ae9629a

Browse files
support reloading profile/connections/resources/deployment targets.
1 parent 08a7c98 commit ae9629a

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-resource-connector-lib/src/main/java/com/microsoft/azure/toolkit/intellij/connector/dotazure/ConnectionManager.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public class ConnectionManager {
5656

5757
public ConnectionManager(@Nonnull final Profile profile) {
5858
this.profile = profile;
59+
this.reload();
60+
}
61+
62+
public void reload() {
5963
try {
6064
this.load();
6165
} catch (final Exception e) {
@@ -142,7 +146,7 @@ public VirtualFile getConnectionsFile() {
142146

143147
@ExceptionNotification
144148
@AzureOperation(name = "boundary/connector.save_connections")
145-
void save() throws IOException {
149+
synchronized void save() throws IOException {
146150
final Element connectionsEle = new Element(ELEMENT_NAME_CONNECTIONS);
147151
for (final Connection<?, ?> connection : this.connections) {
148152
final Element connectionEle = new Element(ELEMENT_NAME_CONNECTION);
@@ -159,7 +163,7 @@ void save() throws IOException {
159163

160164
@ExceptionNotification
161165
@AzureOperation(name = "boundary/connector.load_connections")
162-
void load() throws Exception {
166+
synchronized void load() throws Exception {
163167
this.connectionsFile = getConnectionsFile();
164168
if (Objects.isNull(connectionsFile) || connectionsFile.contentsToByteArray().length < 1) {
165169
return;

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-resource-connector-lib/src/main/java/com/microsoft/azure/toolkit/intellij/connector/dotazure/DeploymentTargetManager.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public class DeploymentTargetManager {
3636

3737
public DeploymentTargetManager(@Nonnull final Profile profile) {
3838
this.profile = profile;
39+
this.reload();
40+
}
41+
42+
public void reload() {
3943
try {
4044
this.load();
4145
} catch (final Exception e) {
@@ -62,7 +66,7 @@ public List<String> getTargets() {
6266

6367
@ExceptionNotification
6468
@AzureOperation("boundary/connector.save_target_apps")
65-
void save() throws IOException {
69+
synchronized void save() throws IOException {
6670
final Element appsEle = new Element(ELEMENT_NAME_APPS);
6771
this.targetAppIds.stream().map(id -> new Element(ELEMENT_NAME_APP).setAttribute("id", id)).forEach(appsEle::addContent);
6872
final VirtualFile appsFile = this.profile.getProfileDir().findOrCreateChildData(this, TARGETS_FILE);
@@ -71,7 +75,7 @@ void save() throws IOException {
7175

7276
@ExceptionNotification
7377
@AzureOperation(name = "boundary/connector.load_target_apps")
74-
void load() throws Exception {
78+
synchronized void load() throws Exception {
7579
final VirtualFile appsFile = this.profile.getProfileDir().findChild(TARGETS_FILE);
7680
if (Objects.isNull(appsFile) || appsFile.contentsToByteArray().length < 1) {
7781
return;

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-resource-connector-lib/src/main/java/com/microsoft/azure/toolkit/intellij/connector/dotazure/Profile.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,13 @@ public synchronized Future<?> createOrUpdateConnection(@Nonnull Connection<?, ?>
117117
return this.addConnection(connection);
118118
}
119119

120-
public void save() {
120+
public synchronized void reload() {
121+
this.resourceManager.reload();
122+
this.deploymentTargetManager.reload();
123+
this.connectionManager.reload();
124+
}
125+
126+
public synchronized void save() {
121127
try {
122128
this.connectionManager.save();
123129
this.resourceManager.save();

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-resource-connector-lib/src/main/java/com/microsoft/azure/toolkit/intellij/connector/dotazure/ResourceManager.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public class ResourceManager {
4949

5050
public ResourceManager(@Nonnull final Profile profile) {
5151
this.profile = profile;
52+
this.reload();
53+
}
54+
55+
public void reload() {
5256
try {
5357
this.load();
5458
} catch (final Exception e) {
@@ -100,10 +104,10 @@ public Resource<?> getResourceById(String id) {
100104

101105
@ExceptionNotification
102106
@AzureOperation("boundary/connector.save_resources")
103-
void save() throws IOException {
107+
synchronized void save() throws IOException {
104108
final Element resourcesEle = new Element(ELEMENT_NAME_RESOURCES);
105109
// todo: whether to save invalid resources?
106-
this.resources.stream().forEach(resource -> {
110+
for (final Resource<?> resource : this.resources) {
107111
final Element resourceEle = new Element(ELEMENT_NAME_RESOURCE);
108112
try {
109113
if (resource.writeTo(resourceEle)) {
@@ -113,14 +117,14 @@ void save() throws IOException {
113117
} catch (final Exception e) {
114118
log.warn(String.format("error occurs when persist resource of type '%s'", resource.getDefinition().getName()), e);
115119
}
116-
});
120+
}
117121
final VirtualFile resourcesFile = this.profile.getProfileDir().findOrCreateChildData(this, RESOURCES_FILE);
118122
JDOMUtil.write(resourcesEle, resourcesFile.toNioPath());
119123
}
120124

121125
@ExceptionNotification
122126
@AzureOperation(name = "boundary/connector.load_resources")
123-
void load() throws Exception {
127+
synchronized void load() throws Exception {
124128
final VirtualFile resourcesFile = this.profile.getProfileDir().findChild(RESOURCES_FILE);
125129
if (Objects.isNull(resourcesFile) || resourcesFile.contentsToByteArray().length < 1) {
126130
return;

0 commit comments

Comments
 (0)