Copilot commented on code in PR #13775:
URL: https://github.com/apache/cloudstack/pull/13775#discussion_r4549143486


##########
engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java:
##########
@@ -1259,13 +1261,16 @@ protected boolean 
handleDisconnectWithInvestigation(final AgentAttache attache,
                 logger.info("The agent from host {} state determined is {}", 
host, determinedState);
 
                 if (determinedState == Status.Down) {
-                    final String message = String.format("Host %s is down. 
Starting HA on the VMs", host);
+                    final DataCenterVO dcVO = 
_dcDao.findById(host.getDataCenterId());
+                    final HostPodVO podVO = _podDao.findById(host.getPodId());
+                    final String hostDesc = 
AlertFormatUtils.describeHostLocation(host, dcVO, podVO);
+                    final String message = String.format("Host %s is down. 
Starting HA on the VMs", hostDesc);
                     logger.error(message);
                     if (Status.Down.equals(host.getStatus())) {
                         logger.debug(String.format("Skipping sending alert for 
%s as it already in %s state",
                                 host, host.getStatus()));
                     } else if 
(!HOST_DOWN_ALERT_UNSUPPORTED_HOST_TYPES.contains(host.getType())) {
-                        
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, 
host.getDataCenterId(), host.getPodId(), "Host down, " + host.getId(), message);
+                        
_alertMgr.sendAlert(AlertService.AlertType.ALERT_TYPE_HOST, 
host.getDataCenterId(), host.getPodId(), "Host down, " + hostDesc, message);

Review Comment:
   This file switches several calls from `AlertManager.AlertType` to 
`AlertService.AlertType`. Unless `AlertManager#sendAlert(...)` / 
`clearAlert(...)` are defined to accept `AlertService.AlertType`, this is a 
hard compile-time type mismatch. Please align the enum type with the 
`AlertManager` method signatures; if the intent is to migrate to 
`AlertService.AlertType`, it should be done consistently across modules and 
with the corresponding API change in `AlertManager`.



##########
engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java:
##########
@@ -1287,9 +1292,9 @@ protected boolean handleDisconnectWithInvestigation(final 
AgentAttache attache,
                     } else if (currentStatus == Status.Up) {
                         final DataCenterVO dcVO = 
_dcDao.findById(host.getDataCenterId());
                         final HostPodVO podVO = 
_podDao.findById(host.getPodId());
-                        final String hostDesc = "name: " + host.getName() + " 
(id:" + host.getUuid() + "), availability zone: " + dcVO.getName() + ", pod: " 
+ podVO.getName();
+                        final String hostDesc = 
AlertFormatUtils.describeHostLocation(host, dcVO, podVO);
                         if (host.getType() != Host.Type.SecondaryStorage && 
host.getType() != Host.Type.ConsoleProxy) {
-                            
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, 
host.getDataCenterId(), host.getPodId(), "Host disconnected, " + hostDesc,
+                            
_alertMgr.sendAlert(AlertService.AlertType.ALERT_TYPE_HOST, 
host.getDataCenterId(), host.getPodId(), "Host disconnected, " + hostDesc,

Review Comment:
   This file switches several calls from `AlertManager.AlertType` to 
`AlertService.AlertType`. Unless `AlertManager#sendAlert(...)` / 
`clearAlert(...)` are defined to accept `AlertService.AlertType`, this is a 
hard compile-time type mismatch. Please align the enum type with the 
`AlertManager` method signatures; if the intent is to migrate to 
`AlertService.AlertType`, it should be done consistently across modules and 
with the corresponding API change in `AlertManager`.



##########
engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java:
##########
@@ -1298,12 +1303,11 @@ protected boolean 
handleDisconnectWithInvestigation(final AgentAttache attache,
                     // if we end up here we are in alert state, send an alert
                     final DataCenterVO dcVO = 
_dcDao.findById(host.getDataCenterId());
                     final HostPodVO podVO = _podDao.findById(host.getPodId());
-                    final String podName = podVO != null ? podVO.getName() : 
"NO POD";
-                    final String hostDesc = String.format("%s, availability 
zone: %s, pod: %s", host, dcVO, podName);
-                    _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST,
+                    final String hostDesc = 
AlertFormatUtils.describeHostLocation(host, dcVO, podVO);
+                    _alertMgr.sendAlert(AlertService.AlertType.ALERT_TYPE_HOST,

Review Comment:
   This file switches several calls from `AlertManager.AlertType` to 
`AlertService.AlertType`. Unless `AlertManager#sendAlert(...)` / 
`clearAlert(...)` are defined to accept `AlertService.AlertType`, this is a 
hard compile-time type mismatch. Please align the enum type with the 
`AlertManager` method signatures; if the intent is to migrate to 
`AlertService.AlertType`, it should be done consistently across modules and 
with the corresponding API change in `AlertManager`.



##########
engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java:
##########
@@ -1818,10 +1822,10 @@ protected void processRequest(final Link link, final 
Request request) {
                                         final HostPodVO podVO = 
_podDao.findById(host.getPodId());
                                         final String hostDesc = 
String.format("%s, availability zone: %s, pod: %s", host, dcVO, podVO);
 
-                                        
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_ROUTING, 
host.getDataCenterId(), host.getPodId(), "Host lost connection to gateway, " + 
hostDesc,
+                                        
_alertMgr.sendAlert(AlertService.AlertType.ALERT_TYPE_ROUTING, 
host.getDataCenterId(), host.getPodId(), "Host lost connection to gateway, " + 
hostDesc,
                                                 "Host [" + hostDesc + "] lost 
connection to gateway (default route) and is possibly having network connection 
issues.");
                                     } else {
-                                        
_alertMgr.clearAlert(AlertManager.AlertType.ALERT_TYPE_ROUTING, 
host.getDataCenterId(), host.getPodId());
+                                        
_alertMgr.clearAlert(AlertService.AlertType.ALERT_TYPE_ROUTING, 
host.getDataCenterId(), host.getPodId());

Review Comment:
   This file switches several calls from `AlertManager.AlertType` to 
`AlertService.AlertType`. Unless `AlertManager#sendAlert(...)` / 
`clearAlert(...)` are defined to accept `AlertService.AlertType`, this is a 
hard compile-time type mismatch. Please align the enum type with the 
`AlertManager` method signatures; if the intent is to migrate to 
`AlertService.AlertType`, it should be done consistently across modules and 
with the corresponding API change in `AlertManager`.



##########
engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java:
##########
@@ -2119,8 +2123,8 @@ protected void runInContext() {
                     if (_resourceMgr.checkAndMaintain(host.getId())) {
                         final DataCenterVO dcVO = 
_dcDao.findById(host.getDataCenterId());
                         final HostPodVO podVO = 
_podDao.findById(host.getPodId());
-                        final String hostDesc = "name: " + host.getName() + " 
(id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + 
podVO.getName();
-                        
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, 
host.getDataCenterId(), host.getPodId(), "Migration Complete for host " + 
hostDesc,
+                        final String hostDesc = 
AlertFormatUtils.describeHostLocation(host, dcVO, podVO);
+                        
_alertMgr.sendAlert(AlertService.AlertType.ALERT_TYPE_HOST, 
host.getDataCenterId(), host.getPodId(), "Migration Complete for host " + 
hostDesc,

Review Comment:
   This file switches several calls from `AlertManager.AlertType` to 
`AlertService.AlertType`. Unless `AlertManager#sendAlert(...)` / 
`clearAlert(...)` are defined to accept `AlertService.AlertType`, this is a 
hard compile-time type mismatch. Please align the enum type with the 
`AlertManager` method signatures; if the intent is to migrate to 
`AlertService.AlertType`, it should be done consistently across modules and 
with the corresponding API change in `AlertManager`.



##########
plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/provider/ScaleIOHostListener.java:
##########
@@ -138,16 +138,16 @@ private String getSdcIdOfHost(HostVO host, DataStore 
dataStore) {
         if (StringUtils.isBlank(sdcId)) {
             String msg = String.format("Couldn't retrieve PowerFlex storage 
SDC details from the host: %s, add MDMs if On-demand connect disabled or try 
(re)install SDC & restart agent", host);
             logger.warn(msg);
-            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, 
host.getDataCenterId(), host.getPodId(), "SDC details not found on host: " + 
host.getUuid(), msg);
+            _alertMgr.sendAlert(AlertService.AlertType.ALERT_TYPE_HOST, 
host.getDataCenterId(), host.getPodId(), "SDC details not found on host: " + 
host, msg);

Review Comment:
   `ScaleIOHostListener` uses `AlertService.AlertType` when calling 
`_alertMgr.sendAlert(...)`, while the rest of the codebase (including other 
touched call sites in this PR) predominantly uses `AlertManager.AlertType`. If 
`AlertManager#sendAlert` is typed to `AlertManager.AlertType` (as commonly in 
CloudStack), this will not compile. Prefer switching these calls back to 
`AlertManager.AlertType` (or, if the API truly moved to 
`AlertService.AlertType`, update consistently and ensure the `AlertManager` 
interface method signatures match everywhere).



##########
plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/provider/ScaleIOHostListener.java:
##########
@@ -138,16 +138,16 @@ private String getSdcIdOfHost(HostVO host, DataStore 
dataStore) {
         if (StringUtils.isBlank(sdcId)) {
             String msg = String.format("Couldn't retrieve PowerFlex storage 
SDC details from the host: %s, add MDMs if On-demand connect disabled or try 
(re)install SDC & restart agent", host);
             logger.warn(msg);
-            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, 
host.getDataCenterId(), host.getPodId(), "SDC details not found on host: " + 
host.getUuid(), msg);
+            _alertMgr.sendAlert(AlertService.AlertType.ALERT_TYPE_HOST, 
host.getDataCenterId(), host.getPodId(), "SDC details not found on host: " + 
host, msg);
             return null;
         }
 
         if (details.containsKey(ScaleIOSDCManager.ConnectOnDemand.key())) {
             String connectOnDemand = 
details.get(ScaleIOSDCManager.ConnectOnDemand.key());
             if (connectOnDemand != null && 
!Boolean.parseBoolean(connectOnDemand) && 
!_sdcManager.isHostSdcConnected(sdcId, dataStore, 15)) {
-                logger.warn("SDC not connected on the host: " + hostId);
-                String msg = "SDC not connected on the host: " + hostId + ", 
reconnect the SDC to MDM and restart agent";
-                _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, 
host.getDataCenterId(), host.getPodId(), "SDC not connected on host: " + 
host.getUuid(), msg);
+                logger.warn("SDC not connected on the host: {}", host);
+                String msg = "SDC not connected on host: " + host + ", 
reconnect the SDC to MDM and restart agent";
+                _alertMgr.sendAlert(AlertService.AlertType.ALERT_TYPE_HOST, 
host.getDataCenterId(), host.getPodId(), "SDC not connected on host: " + host, 
msg);

Review Comment:
   `ScaleIOHostListener` uses `AlertService.AlertType` when calling 
`_alertMgr.sendAlert(...)`, while the rest of the codebase (including other 
touched call sites in this PR) predominantly uses `AlertManager.AlertType`. If 
`AlertManager#sendAlert` is typed to `AlertManager.AlertType` (as commonly in 
CloudStack), this will not compile. Prefer switching these calls back to 
`AlertManager.AlertType` (or, if the API truly moved to 
`AlertService.AlertType`, update consistently and ensure the `AlertManager` 
interface method signatures match everywhere).



##########
engine/components-api/src/main/java/com/cloud/alert/AlertFormatUtils.java:
##########
@@ -0,0 +1,47 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.alert;
+
+import com.cloud.dc.DataCenter;
+import com.cloud.dc.Pod;
+import com.cloud.host.Host;
+
+/**
+ * Shared formatting for the host/zone/pod description that recurs, 
independently
+ * hand-rolled and inconsistently worded (and occasionally mislabelled), 
across the
+ * HA and agent-management alert call sites.

Review Comment:
   The PR description is currently left as the default template (no functional 
description or testing notes filled in), but it states automation relies on the 
description for labeling/docs. Please update the PR description to summarize 
the alert message restructuring and explicitly list how it was tested (the 
new/updated unit tests added by this PR are a good start to mention).



##########
plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/provider/ScaleIOHostListener.java:
##########
@@ -123,7 +123,7 @@ private String getSdcIdOfHost(HostVO host, DataStore 
dataStore) {
         if (MapUtils.isEmpty(poolDetails)) {
             String msg = String.format("PowerFlex storage SDC details not 
found on the host: %s, (re)install SDC and restart agent", host);
             logger.warn(msg);
-            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, 
host.getDataCenterId(), host.getPodId(), "SDC details not found on host: " + 
host.getUuid(), msg);
+            _alertMgr.sendAlert(AlertService.AlertType.ALERT_TYPE_HOST, 
host.getDataCenterId(), host.getPodId(), "SDC details not found on host: " + 
host, msg);

Review Comment:
   `ScaleIOHostListener` uses `AlertService.AlertType` when calling 
`_alertMgr.sendAlert(...)`, while the rest of the codebase (including other 
touched call sites in this PR) predominantly uses `AlertManager.AlertType`. If 
`AlertManager#sendAlert` is typed to `AlertManager.AlertType` (as commonly in 
CloudStack), this will not compile. Prefer switching these calls back to 
`AlertManager.AlertType` (or, if the API truly moved to 
`AlertService.AlertType`, update consistently and ensure the `AlertManager` 
interface method signatures match everywhere).



##########
plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/listener/OntapHostListenerTest.java:
##########
@@ -0,0 +1,360 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.listener;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyLong;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import com.cloud.agent.AgentManager;
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.ModifyStoragePoolAnswer;
+import com.cloud.agent.api.StoragePoolInfo;
+import com.cloud.alert.AlertManager;
+import com.cloud.host.HostVO;
+import com.cloud.host.dao.HostDao;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.StoragePoolHostVO;
+import com.cloud.storage.dao.StoragePoolHostDao;
+import com.cloud.utils.exception.CloudRuntimeException;
+import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
+import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.cloudstack.storage.service.model.ProtocolType;
+import org.apache.cloudstack.storage.utils.OntapStorageConstants;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)

Review Comment:
   Using `Strictness.LENIENT` can hide unintended stubbings and make tests pass 
while masking regressions. If possible, remove this and fix any strict-stubbing 
violations by only stubbing what’s exercised (or by using `lenient()` on the 
specific stubbings that are truly hard to avoid).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to