Fixup main build error (#9314)

This commit is contained in:
Vishesh 2024-06-29 14:25:53 +05:30 committed by GitHub
parent 90fe1d5fdc
commit e010c9be93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 28 deletions

View File

@ -378,12 +378,12 @@ public class VeeamClient {
if (session.getResult().equalsIgnoreCase("Failed")) { if (session.getResult().equalsIgnoreCase("Failed")) {
String sessionUid = session.getUid(); String sessionUid = session.getUid();
LOG.error(String.format("Failed to restore backup [%s] of VM [%s] due to [%s].", logger.error(String.format("Failed to restore backup [%s] of VM [%s] due to [%s].",
sessionUid, session.getVmDisplayName(), sessionUid, session.getVmDisplayName(),
getRestoreVmErrorDescription(StringUtils.substringAfterLast(sessionUid, ":")))); getRestoreVmErrorDescription(StringUtils.substringAfterLast(sessionUid, ":"))));
throw new CloudRuntimeException(String.format("Restore job [%s] failed.", sessionUid)); throw new CloudRuntimeException(String.format("Restore job [%s] failed.", sessionUid));
} }
LOG.debug(String.format("Waiting %s seconds, out of a total of %s seconds, for the restore backup process to finish.", j, restoreTimeout)); logger.debug(String.format("Waiting %s seconds, out of a total of %s seconds, for the restore backup process to finish.", j, restoreTimeout));
try { try {
Thread.sleep(1000); Thread.sleep(1000);
@ -949,7 +949,7 @@ public class VeeamClient {
* @return the description found in Veeam about the cause of error in the restore process. * @return the description found in Veeam about the cause of error in the restore process.
*/ */
protected String getRestoreVmErrorDescription(String uid) { protected String getRestoreVmErrorDescription(String uid) {
LOG.debug(String.format("Trying to find the cause of error in the restore process [%s].", uid)); logger.debug(String.format("Trying to find the cause of error in the restore process [%s].", uid));
List<String> cmds = Arrays.asList( List<String> cmds = Arrays.asList(
String.format("$restoreUid = '%s'", uid), String.format("$restoreUid = '%s'", uid),
"$restore = Get-VBRRestoreSession -Id $restoreUid", "$restore = Get-VBRRestoreSession -Id $restoreUid",

View File

@ -38,7 +38,7 @@ import org.apache.cloudstack.backup.Backup;
import org.apache.cloudstack.backup.BackupOffering; import org.apache.cloudstack.backup.BackupOffering;
import org.apache.cloudstack.backup.veeam.api.RestoreSession; import org.apache.cloudstack.backup.veeam.api.RestoreSession;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.logging.log4j.core.Logger; import org.apache.logging.log4j.Logger;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
@ -59,8 +59,6 @@ public class VeeamClientTest {
private VeeamClient mockClient; private VeeamClient mockClient;
private static final SimpleDateFormat newDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static final SimpleDateFormat newDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private VeeamClient mock = Mockito.mock(VeeamClient.class);
@Rule @Rule
public WireMockRule wireMockRule = new WireMockRule(9399); public WireMockRule wireMockRule = new WireMockRule(9399);
@ -177,35 +175,35 @@ public class VeeamClientTest {
@Test @Test
public void getRestoreVmErrorDescriptionTestFindErrorDescription() { public void getRestoreVmErrorDescriptionTestFindErrorDescription() {
Pair<Boolean, String> response = new Pair<>(true, "Example of error description found in Veeam."); Pair<Boolean, String> response = new Pair<>(true, "Example of error description found in Veeam.");
Mockito.when(mock.getRestoreVmErrorDescription("uuid")).thenCallRealMethod(); Mockito.when(mockClient.getRestoreVmErrorDescription("uuid")).thenCallRealMethod();
Mockito.when(mock.executePowerShellCommands(Mockito.any())).thenReturn(response); Mockito.when(mockClient.executePowerShellCommands(Mockito.any())).thenReturn(response);
String result = mock.getRestoreVmErrorDescription("uuid"); String result = mockClient.getRestoreVmErrorDescription("uuid");
Assert.assertEquals("Example of error description found in Veeam.", result); Assert.assertEquals("Example of error description found in Veeam.", result);
} }
@Test @Test
public void getRestoreVmErrorDescriptionTestNotFindErrorDescription() { public void getRestoreVmErrorDescriptionTestNotFindErrorDescription() {
Pair<Boolean, String> response = new Pair<>(true, "Cannot find restore session with provided uid uuid"); Pair<Boolean, String> response = new Pair<>(true, "Cannot find restore session with provided uid uuid");
Mockito.when(mock.getRestoreVmErrorDescription("uuid")).thenCallRealMethod(); Mockito.when(mockClient.getRestoreVmErrorDescription("uuid")).thenCallRealMethod();
Mockito.when(mock.executePowerShellCommands(Mockito.any())).thenReturn(response); Mockito.when(mockClient.executePowerShellCommands(Mockito.any())).thenReturn(response);
String result = mock.getRestoreVmErrorDescription("uuid"); String result = mockClient.getRestoreVmErrorDescription("uuid");
Assert.assertEquals("Cannot find restore session with provided uid uuid", result); Assert.assertEquals("Cannot find restore session with provided uid uuid", result);
} }
@Test @Test
public void getRestoreVmErrorDescriptionTestWhenPowerShellOutputIsNull() { public void getRestoreVmErrorDescriptionTestWhenPowerShellOutputIsNull() {
Mockito.when(mock.getRestoreVmErrorDescription("uuid")).thenCallRealMethod(); Mockito.when(mockClient.getRestoreVmErrorDescription("uuid")).thenCallRealMethod();
Mockito.when(mock.executePowerShellCommands(Mockito.any())).thenReturn(null); Mockito.when(mockClient.executePowerShellCommands(Mockito.any())).thenReturn(null);
String result = mock.getRestoreVmErrorDescription("uuid"); String result = mockClient.getRestoreVmErrorDescription("uuid");
Assert.assertEquals("Failed to get the description of the failed restore session [uuid]. Please contact an administrator.", result); Assert.assertEquals("Failed to get the description of the failed restore session [uuid]. Please contact an administrator.", result);
} }
@Test @Test
public void getRestoreVmErrorDescriptionTestWhenPowerShellOutputIsFalse() { public void getRestoreVmErrorDescriptionTestWhenPowerShellOutputIsFalse() {
Pair<Boolean, String> response = new Pair<>(false, null); Pair<Boolean, String> response = new Pair<>(false, null);
Mockito.when(mock.getRestoreVmErrorDescription("uuid")).thenCallRealMethod(); Mockito.when(mockClient.getRestoreVmErrorDescription("uuid")).thenCallRealMethod();
Mockito.when(mock.executePowerShellCommands(Mockito.any())).thenReturn(response); Mockito.when(mockClient.executePowerShellCommands(Mockito.any())).thenReturn(response);
String result = mock.getRestoreVmErrorDescription("uuid"); String result = mockClient.getRestoreVmErrorDescription("uuid");
Assert.assertEquals("Failed to get the description of the failed restore session [uuid]. Please contact an administrator.", result); Assert.assertEquals("Failed to get the description of the failed restore session [uuid]. Please contact an administrator.", result);
} }

View File

@ -548,18 +548,18 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru, Co
StoragePoolVO pool = null; StoragePoolVO pool = null;
try { try {
String poolUuid = UuidUtils.normalize(datastoreUuid); String poolUuid = UuidUtils.normalize(datastoreUuid);
s_logger.info("Trying to find pool by UUID: " + poolUuid); logger.info("Trying to find pool by UUID: " + poolUuid);
pool = _storagePoolDao.findByUuid(poolUuid); pool = _storagePoolDao.findByUuid(poolUuid);
} catch (CloudRuntimeException ex) { } catch (CloudRuntimeException ex) {
s_logger.warn("Unable to get pool by datastore UUID: " + ex.getMessage()); logger.warn("Unable to get pool by datastore UUID: " + ex.getMessage());
} }
if (pool == null) { if (pool == null) {
s_logger.info("Trying to find pool by path: " + datastoreUuid); logger.info("Trying to find pool by path: " + datastoreUuid);
pool = _storagePoolDao.findPoolByZoneAndPath(zoneId, datastoreUuid); pool = _storagePoolDao.findPoolByZoneAndPath(zoneId, datastoreUuid);
} }
if (pool == null && datastoreUuid.startsWith("-iqn") && datastoreUuid.endsWith("-0")) { if (pool == null && datastoreUuid.startsWith("-iqn") && datastoreUuid.endsWith("-0")) {
String iScsiName = "/iqn" + datastoreUuid.substring(4, datastoreUuid.length() - 2) + "/0"; String iScsiName = "/iqn" + datastoreUuid.substring(4, datastoreUuid.length() - 2) + "/0";
s_logger.info("Trying to find volume by iScsi name: " + iScsiName); logger.info("Trying to find volume by iScsi name: " + iScsiName);
VolumeVO volumeVO = _volumeDao.findOneByIScsiName(iScsiName); VolumeVO volumeVO = _volumeDao.findOneByIScsiName(iScsiName);
if (volumeVO != null) { if (volumeVO != null) {
pool = _storagePoolDao.findById(volumeVO.getPoolId()); pool = _storagePoolDao.findById(volumeVO.getPoolId());
@ -1009,11 +1009,11 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru, Co
} }
VMwareDVSPortSetting settings = (VMwareDVSPortSetting) dvPort.getConfig().getSetting(); VMwareDVSPortSetting settings = (VMwareDVSPortSetting) dvPort.getConfig().getSetting();
VmwareDistributedVirtualSwitchVlanIdSpec vlanId = (VmwareDistributedVirtualSwitchVlanIdSpec) settings.getVlan(); VmwareDistributedVirtualSwitchVlanIdSpec vlanId = (VmwareDistributedVirtualSwitchVlanIdSpec) settings.getVlan();
s_logger.debug("Found port " + dvPort.getKey() + " with vlan " + vlanId.getVlanId()); logger.debug("Found port " + dvPort.getKey() + " with vlan " + vlanId.getVlanId());
return String.valueOf(vlanId.getVlanId()); return String.valueOf(vlanId.getVlanId());
} }
} catch (Exception ex) { } catch (Exception ex) {
s_logger.error("Got exception while get vlan from DVS port: " + ex.getMessage()); logger.error("Got exception while get vlan from DVS port: " + ex.getMessage());
} }
return null; return null;
} }
@ -1026,12 +1026,12 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru, Co
String macAddress = pair.first(); String macAddress = pair.first();
String vlanId = pair.second(); String vlanId = pair.second();
if (vlanId == null) { if (vlanId == null) {
s_logger.warn(String.format("vlanId for MAC address [%s] is null", macAddress)); logger.warn(String.format("vlanId for MAC address [%s] is null", macAddress));
continue; continue;
} }
NetworkVO networkVO = networksMapping.get(vlanId); NetworkVO networkVO = networksMapping.get(vlanId);
if (networkVO == null) { if (networkVO == null) {
s_logger.warn(String.format("Cannot find network for MAC address [%s] and vlanId [%s]", macAddress, vlanId)); logger.warn(String.format("Cannot find network for MAC address [%s] and vlanId [%s]", macAddress, vlanId));
continue; continue;
} }
NicVO nicVO = nicDao.findByNetworkIdAndMacAddressIncludingRemoved(networkVO.getId(), macAddress); NicVO nicVO = nicDao.findByNetworkIdAndMacAddressIncludingRemoved(networkVO.getId(), macAddress);
@ -1349,7 +1349,7 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru, Co
List<DatastoreMO> vmDatastores = vmMo.getAllDatastores(); List<DatastoreMO> vmDatastores = vmMo.getAllDatastores();
if (CollectionUtils.isEmpty(vmDatastores)) { if (CollectionUtils.isEmpty(vmDatastores)) {
String err = String.format("Unable to fetch datastores, could not clone VM %s for migration from VMware", vmName); String err = String.format("Unable to fetch datastores, could not clone VM %s for migration from VMware", vmName);
s_logger.error(err); logger.error(err);
throw new CloudRuntimeException(err); throw new CloudRuntimeException(err);
} }
DatastoreMO datastoreMO = vmDatastores.get(0); //pick the first datastore DatastoreMO datastoreMO = vmDatastores.get(0); //pick the first datastore

View File

@ -812,7 +812,7 @@ public class VmwareHelper {
ClusterMO clusterMo = new ClusterMO(hyperHost.getContext(), hyperHost.getHyperHostCluster()); ClusterMO clusterMo = new ClusterMO(hyperHost.getContext(), hyperHost.getHyperHostCluster());
instance.setClusterName(clusterMo.getName()); instance.setClusterName(clusterMo.getName());
} catch (Exception e) { } catch (Exception e) {
s_logger.warn("Unable to get unmanaged instance cluster info, due to: " + e.getMessage()); LOGGER.warn("Unable to get unmanaged instance cluster info, due to: " + e.getMessage());
} }
instance.setHostName(hyperHost.getHyperHostName()); instance.setHostName(hyperHost.getHyperHostName());