@@ -238,7 +238,8 @@ public class ServerAdapter extends ManagerBase {
238238 Storage .StoragePoolType .NetworkFilesystem ,
239239 Storage .StoragePoolType .SharedMountPoint
240240 );
241- public static final String WORKER_VM_GUEST_CPU_MODE = "host-passthrough" ;
241+ private static final String VM_TA_KEY = "veeam_tag" ;
242+ private static final String WORKER_VM_GUEST_CPU_MODE = "host-passthrough" ;
242243
243244 @ Inject
244245 RoleService roleService ;
@@ -413,22 +414,6 @@ protected Pair<User, Account> getDefaultServiceAccount() {
413414 accountService .getActiveAccountById (userAccount .getAccountId ()));
414415 }
415416
416- protected Pair <User , Account > getServiceAccount () {
417- String serviceAccountUuid = VeeamControlService .ServiceAccountId .value ();
418- if (StringUtils .isEmpty (serviceAccountUuid )) {
419- throw new CloudRuntimeException ("Service account is not configured, unable to proceed" );
420- }
421- Account account = accountService .getActiveAccountByUuid (serviceAccountUuid );
422- if (account == null ) {
423- throw new CloudRuntimeException ("Service account with ID " + serviceAccountUuid + " not found, unable to proceed" );
424- }
425- User user = accountService .getOneActiveUserForAccount (account );
426- if (user == null ) {
427- throw new CloudRuntimeException ("No active user found for service account with ID " + serviceAccountUuid );
428- }
429- return new Pair <>(user , account );
430- }
431-
432417 protected void waitForJobCompletion (long jobId ) {
433418 long timeoutNanos = TimeUnit .MINUTES .toNanos (5 );
434419 final long deadline = System .nanoTime () + timeoutNanos ;
@@ -858,6 +843,22 @@ protected Map<String, String> getDetailsByInstanceId(Long instanceId) {
858843 return vmInstanceDetailsDao .listDetailsKeyPairs (instanceId , true );
859844 }
860845
846+ public Pair <User , Account > getServiceAccount () {
847+ String serviceAccountUuid = VeeamControlService .ServiceAccountId .value ();
848+ if (StringUtils .isEmpty (serviceAccountUuid )) {
849+ throw new CloudRuntimeException ("Service account is not configured, unable to proceed" );
850+ }
851+ Account account = accountService .getActiveAccountByUuid (serviceAccountUuid );
852+ if (account == null ) {
853+ throw new CloudRuntimeException ("Service account with ID " + serviceAccountUuid + " not found, unable to proceed" );
854+ }
855+ User user = accountService .getOneActiveUserForAccount (account );
856+ if (user == null ) {
857+ throw new CloudRuntimeException ("No active user found for service account with ID " + serviceAccountUuid );
858+ }
859+ return new Pair <>(user , account );
860+ }
861+
861862 @ Override
862863 public boolean start () {
863864 getServiceAccount ();
@@ -1185,15 +1186,13 @@ public VmAction shutdownInstance(String uuid, boolean async) {
11851186
11861187 @ ApiAccess (command = ListTagsCmd .class )
11871188 protected List <Tag > listTagsByInstanceId (final long instanceId ) {
1188- List <? extends ResourceTag > vmResourceTags = resourceTagDao .listBy (instanceId ,
1189- ResourceTag .ResourceObjectType .UserVm );
1189+ ResourceTag vmResourceTag = resourceTagDao .findByKey (instanceId ,
1190+ ResourceTag .ResourceObjectType .UserVm , VM_TA_KEY );
11901191 List <ResourceTagVO > tags = new ArrayList <>();
1191- for (ResourceTag t : vmResourceTags ) {
1192- if (t instanceof ResourceTagVO ) {
1193- tags .add ((ResourceTagVO )t );
1194- continue ;
1195- }
1196- tags .add (resourceTagDao .findById (t .getId ()));
1192+ if (vmResourceTag instanceof ResourceTagVO ) {
1193+ tags .add ((ResourceTagVO )vmResourceTag );
1194+ } else {
1195+ tags .add (resourceTagDao .findById (vmResourceTag .getId ()));
11971196 }
11981197 return ResourceTagVOToTagConverter .toTags (tags );
11991198 }
@@ -1760,8 +1759,8 @@ public List<Tag> listAllTags(final Long offset, final Long limit) {
17601759 List <Tag > tags = new ArrayList <>(getDummyTags ().values ());
17611760 Filter filter = new Filter (ResourceTagVO .class , "id" , true , offset , limit );
17621761 Pair <List <Long >, List <Long >> ownerDetails = getResourceOwnerFiltersWithDomainIds ();
1763- List <ResourceTagVO > vmResourceTags = resourceTagDao .listByResourceTypeAndOwners (
1764- ResourceTag .ResourceObjectType .UserVm , ownerDetails .first (), ownerDetails .second (), filter );
1762+ List <ResourceTagVO > vmResourceTags = resourceTagDao .listByResourceTypeKeyAndOwners (
1763+ ResourceTag .ResourceObjectType .UserVm , VM_TA_KEY , ownerDetails .first (), ownerDetails .second (), filter );
17651764 if (CollectionUtils .isNotEmpty (vmResourceTags )) {
17661765 tags .addAll (ResourceTagVOToTagConverter .toTags (vmResourceTags ));
17671766 }
@@ -1775,7 +1774,8 @@ public Tag getTag(String uuid) {
17751774 }
17761775 Tag tag = getDummyTags ().get (uuid );
17771776 if (tag == null ) {
1778- ResourceTagVO resourceTagVO = resourceTagDao .findByUuid (uuid );
1777+ ResourceTagVO resourceTagVO = resourceTagDao .findByResourceTypeKeyAndValue (
1778+ ResourceTag .ResourceObjectType .UserVm , VM_TA_KEY , uuid );
17791779 accountService .checkAccess (CallContext .current ().getCallingAccount (), null , false ,
17801780 resourceTagVO );
17811781 if (resourceTagVO != null ) {
0 commit comments