66package com .microsoft .tooling .msservices .serviceexplorer .azure .springcloud ;
77
88import com .microsoft .azure .management .appplatform .v2020_07_01 .DeploymentResourceStatus ;
9- import com .microsoft .azure .management .appplatform .v2020_07_01 .implementation .AppResourceInner ;
10- import com .microsoft .azure .management .appplatform .v2020_07_01 .implementation .DeploymentResourceInner ;
119import com .microsoft .azure .toolkit .lib .common .operation .AzureOperation ;
10+ import com .microsoft .azure .toolkit .lib .springcloud .SpringCloudApp ;
11+ import com .microsoft .azure .toolkit .lib .springcloud .SpringCloudDeployment ;
1212import com .microsoft .azuretools .ActionConstants ;
1313import com .microsoft .azuretools .azurecommons .helpers .Nullable ;
14- import com .microsoft .azuretools .core .mvp .model .springcloud .AzureSpringCloudMvpModel ;
15- import com .microsoft .azuretools .core .mvp .model .springcloud .SpringCloudIdHelper ;
1614import com .microsoft .azuretools .telemetry .TelemetryConstants ;
1715import com .microsoft .azuretools .telemetry .TelemetryProperties ;
1816import com .microsoft .tooling .msservices .components .DefaultLoader ;
19- import com .microsoft .tooling .msservices .serviceexplorer .AzureActionEnum ;
20- import com .microsoft .tooling .msservices .serviceexplorer .AzureIconSymbol ;
21- import com .microsoft .tooling .msservices .serviceexplorer .BasicActionBuilder ;
22- import com .microsoft .tooling .msservices .serviceexplorer .Node ;
23- import com .microsoft .tooling .msservices .serviceexplorer .NodeAction ;
17+ import com .microsoft .tooling .msservices .serviceexplorer .*;
2418import io .reactivex .rxjava3 .disposables .Disposable ;
19+ import lombok .Getter ;
2520import org .apache .commons .lang3 .StringUtils ;
2621
2722import java .util .HashMap ;
2823import java .util .List ;
2924import java .util .Map ;
30- import java .util .Objects ;
3125
32- public class SpringCloudAppNode extends Node implements SpringCloudAppNodeView , TelemetryProperties {
26+ public class SpringCloudAppNode extends Node implements TelemetryProperties {
3327
3428 private static final String ACTION_OPEN_IN_BROWSER = "Open In Browser" ;
29+ private static final DeploymentResourceStatus SERVER_UPDATING = DeploymentResourceStatus .fromString ("Updating" );
3530 private static final Map <DeploymentResourceStatus , AzureIconSymbol > STATUS_TO_ICON_MAP = new HashMap <>();
3631
37- private AppResourceInner app ;
32+ @ Getter
33+ private SpringCloudApp app ;
3834 private DeploymentResourceStatus status ;
39- private DeploymentResourceInner deploy ;
35+ private SpringCloudDeployment deploy ;
4036
41- private final String clusterName ;
42- private final String subscriptionId ;
43- private final String clusterId ;
4437 private final Disposable rxSubscription ;
4538
4639 static {
40+ STATUS_TO_ICON_MAP .put (SERVER_UPDATING , AzureIconSymbol .SpringCloud .UPDATING );
4741 STATUS_TO_ICON_MAP .put (DeploymentResourceStatus .UNKNOWN , AzureIconSymbol .SpringCloud .UNKNOWN );
4842 STATUS_TO_ICON_MAP .put (DeploymentResourceStatus .RUNNING , AzureIconSymbol .SpringCloud .RUNNING );
4943 STATUS_TO_ICON_MAP .put (DeploymentResourceStatus .ALLOCATING , AzureIconSymbol .SpringCloud .PENDING );
@@ -53,27 +47,26 @@ public class SpringCloudAppNode extends Node implements SpringCloudAppNodeView,
5347 STATUS_TO_ICON_MAP .put (DeploymentResourceStatus .FAILED , AzureIconSymbol .SpringCloud .FAILED );
5448 }
5549
56- public SpringCloudAppNode (AppResourceInner app , DeploymentResourceInner deploy , SpringCloudNode parent ) {
57- super (app .id () , app .name (), parent , getIconForStatus ( deploy == null ? DeploymentResourceStatus . UNKNOWN : deploy . properties (). status ()) , true );
50+ public SpringCloudAppNode (SpringCloudApp app , SpringCloudNode parent ) {
51+ super (app .entity (). getId () , app .name (), parent , null , true );
5852 this .app = app ;
59- this .deploy = deploy ;
60- this .clusterName = SpringCloudIdHelper .getClusterName (app .id ());
61- this .clusterId = parent .getClusterId ();
62- this .subscriptionId = SpringCloudIdHelper .getSubscriptionId (app .id ());
53+ if (StringUtils .isNotBlank (app .getActiveDeploymentName ())) {
54+ this .deploy = app .deployment (app .getActiveDeploymentName ());
55+ this .status = DeploymentResourceStatus .fromString (deploy .entity ().getStatus ());
56+ } else {
57+ this .status = DeploymentResourceStatus .UNKNOWN ;
58+ }
6359 fillData (app , deploy );
6460 rxSubscription = SpringCloudStateManager .INSTANCE .subscribeSpringAppEvent (event -> {
6561 if (event .isUpdate ()) {
66- fillData (event .getAppInner (), event .getDeploymentInner ());
62+ fillData (event .getApp (), event .getDeployment ());
6763 }
68- }, this .app .id ());
64+ }, this .app .entity (). getId ());
6965 }
7066
7167 @ Override
7268 public @ Nullable AzureIconSymbol getIconSymbol () {
73- if (Objects .isNull (deploy ) || Objects .isNull (deploy .properties ().status ())) {
74- return AzureIconSymbol .SpringCloud .UNKNOWN ;
75- }
76- return STATUS_TO_ICON_MAP .get (deploy .properties ().status ());
69+ return STATUS_TO_ICON_MAP .get (status );
7770 }
7871
7972 @ Override
@@ -88,30 +81,10 @@ public void unsubscribe() {
8881 }
8982 }
9083
91- public String getClusterName () {
92- return clusterName ;
93- }
94-
95- public String getClusterId () {
96- return clusterId ;
97- }
98-
99- public String getAppName () {
100- return app .name ();
101- }
102-
103- public String getAppId () {
104- return app .id ();
105- }
106-
107- public String getSubscriptionId () {
108- return subscriptionId ;
109- }
110-
11184 @ Override
11285 public Map <String , String > toProperties () {
11386 final Map <String , String > properties = new HashMap <>();
114- properties .put (TelemetryConstants .SUBSCRIPTIONID , this .subscriptionId );
87+ properties .put (TelemetryConstants .SUBSCRIPTIONID , this .app . entity (). getSubscriptionId () );
11588 return properties ;
11689 }
11790
@@ -137,19 +110,13 @@ private static String getStatusDisplay(DeploymentResourceStatus status) {
137110 return status == null ? "Unknown" : status .toString ();
138111 }
139112
140- private static String getIconForStatus (DeploymentResourceStatus statusEnum ) {
141- final String displayText = getStatusDisplay (statusEnum );
142- String simpleStatus = displayText .endsWith ("ing" ) && !StringUtils .equalsIgnoreCase (displayText , "running" ) ? "pending" : displayText .toLowerCase ();
143- return String .format ("azure-springcloud-app-%s.png" , simpleStatus );
144- }
145-
146113 private void syncActionState () {
147114 if (status != null ) {
148115 boolean stopped = DeploymentResourceStatus .STOPPED .equals (status );
149116 boolean running = DeploymentResourceStatus .RUNNING .equals (status );
150117 boolean unknown = DeploymentResourceStatus .UNKNOWN .equals (status );
151118 boolean allocating = DeploymentResourceStatus .ALLOCATING .equals (status );
152- boolean hasURL = StringUtils .isNotEmpty (app .properties ().url ()) && app .properties ().url ().startsWith ("http" );
119+ boolean hasURL = StringUtils .isNotEmpty (app .entity ().getApplicationUrl ()) && app .entity ().getApplicationUrl ().startsWith ("http" );
153120 getNodeActionByName (ACTION_OPEN_IN_BROWSER ).setEnabled (hasURL && running );
154121 getNodeActionByName (AzureActionEnum .START .getName ()).setEnabled (stopped );
155122 getNodeActionByName (AzureActionEnum .STOP .getName ()).setEnabled (!stopped && !unknown && !allocating );
@@ -162,60 +129,70 @@ private void syncActionState() {
162129 }
163130 }
164131
165- private void fillData (AppResourceInner newApp , DeploymentResourceInner deploy ) {
166- this .status = deploy == null ? DeploymentResourceStatus .UNKNOWN : deploy .properties ().status ();
132+ private void fillData (SpringCloudApp newApp , SpringCloudDeployment deploy ) {
167133 this .app = newApp ;
168134 this .deploy = deploy ;
169- this .setIconPath (getIconForStatus (status ));
170135 this .setName (String .format ("%s - %s" , app .name (), getStatusDisplay (status )));
171136 if (getNodeActionByName (AzureActionEnum .START .getName ()) == null ) {
172137 loadActions ();
173138 }
174139 syncActionState ();
175140 }
176141
142+ private void refreshNode () {
143+ if (StringUtils .isBlank (app .getActiveDeploymentName ())) {
144+ this .status = DeploymentResourceStatus .fromString (app .deployment (app .getActiveDeploymentName ()).entity ().getStatus ());
145+ }
146+ }
147+
177148 @ AzureOperation (name = ActionConstants .SpringCloud .DELETE , type = AzureOperation .Type .ACTION )
178149 private void delete () {
179- AzureSpringCloudMvpModel .deleteApp (this .id ).await ();
180- SpringCloudMonitorUtil .awaitAndMonitoringStatus (id , null );
150+ status = SERVER_UPDATING ;
151+ app .remove ();
152+ SpringCloudMonitorUtil .awaitAndMonitoringStatus (app , null );
181153 }
182154
183155 @ AzureOperation (name = ActionConstants .SpringCloud .START , type = AzureOperation .Type .ACTION )
184156 private void start () {
185- AzureSpringCloudMvpModel .startApp (app .id (), app .properties ().activeDeploymentName ()).await ();
186- SpringCloudMonitorUtil .awaitAndMonitoringStatus (app .id (), status );
157+ status = SERVER_UPDATING ;
158+ deploy .start ();
159+ SpringCloudMonitorUtil .awaitAndMonitoringStatus (app , status );
160+ this .refreshNode ();
187161 }
188162
189163 @ AzureOperation (name = ActionConstants .SpringCloud .STOP , type = AzureOperation .Type .ACTION )
190164 private void stop () {
191- AzureSpringCloudMvpModel .stopApp (app .id (), app .properties ().activeDeploymentName ()).await ();
192- SpringCloudMonitorUtil .awaitAndMonitoringStatus (app .id (), status );
165+ status = SERVER_UPDATING ;
166+ deploy .stop ();
167+ SpringCloudMonitorUtil .awaitAndMonitoringStatus (app , status );
168+ this .refreshNode ();
193169 }
194170
195171 @ AzureOperation (name = ActionConstants .SpringCloud .RESTART , type = AzureOperation .Type .ACTION )
196172 private void restart () {
197- AzureSpringCloudMvpModel .restartApp (app .id (), app .properties ().activeDeploymentName ()).await ();
198- SpringCloudMonitorUtil .awaitAndMonitoringStatus (app .id (), status );
173+ status = SERVER_UPDATING ;
174+ deploy .restart ();
175+ SpringCloudMonitorUtil .awaitAndMonitoringStatus (app , status );
176+ this .refreshNode ();
199177 }
200178
201179 @ AzureOperation (name = ActionConstants .SpringCloud .OPEN_IN_PORTAL , type = AzureOperation .Type .ACTION )
202180 private void openInPortal () {
203- openResourcesInPortal (getSubscriptionId (), getAppId ());
181+ openResourcesInPortal (app . entity (). getSubscriptionId (), app . entity (). getId ());
204182 }
205183
206184 @ AzureOperation (name = ActionConstants .SpringCloud .SHOW_PROPERTIES , type = AzureOperation .Type .ACTION )
207185 private void showProperties () {
208186 DefaultLoader .getUIHelper ().openSpringCloudAppPropertyView (SpringCloudAppNode .this );
209187 // add this statement for false updating notice to update Property view
210188 // immediately
211- SpringCloudStateManager .INSTANCE .notifySpringAppUpdate (clusterId ,
212- app , deploy );
189+ SpringCloudStateManager .INSTANCE .notifySpringAppUpdate (app .getCluster ().id (), app );
213190 }
214191
215192 @ AzureOperation (name = ActionConstants .SpringCloud .OPEN_IN_BROWSER , type = AzureOperation .Type .ACTION )
216193 private void openInBrowser () {
217- if (StringUtils .isNotEmpty (app .properties ().url ())) {
218- DefaultLoader .getUIHelper ().openInBrowser (app .properties ().url ());
194+ if (StringUtils .isNotEmpty (app .entity ().getApplicationUrl ())) {
195+ DefaultLoader .getUIHelper ().openInBrowser (app .entity ().getApplicationUrl ());
219196 } else {
220197 DefaultLoader .getUIHelper ().showInfo (this , "Public url is not available for app: " + app .name ());
221198 }
0 commit comments