Allow admin/users to add comments to Management Servers (#7379)

* UI changes for management server comments

* Added support for mgmt server comments in annotations framework

* Added test for mgmt server annotation

* changed annotation to be unique for mgmt server test
This commit is contained in:
kishankavala 2023-04-18 14:16:55 +05:30 committed by GitHub
parent 514df7b3a0
commit 69be0af32d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 51 additions and 3 deletions

View File

@ -45,7 +45,7 @@ public interface AnnotationService {
SERVICE_OFFERING(false), DISK_OFFERING(false), NETWORK_OFFERING(false), SERVICE_OFFERING(false), DISK_OFFERING(false), NETWORK_OFFERING(false),
ZONE(false), POD(false), CLUSTER(false), HOST(false), DOMAIN(false), ZONE(false), POD(false), CLUSTER(false), HOST(false), DOMAIN(false),
PRIMARY_STORAGE(false), SECONDARY_STORAGE(false), VR(false), SYSTEM_VM(false), PRIMARY_STORAGE(false), SECONDARY_STORAGE(false), VR(false), SYSTEM_VM(false),
AUTOSCALE_VM_GROUP(true); AUTOSCALE_VM_GROUP(true), MANAGEMENT_SERVER(false),;
private final boolean usersAllowed; private final boolean usersAllowed;

View File

@ -77,7 +77,8 @@ public enum ApiCommandResourceType {
Pod(com.cloud.dc.Pod.class), Pod(com.cloud.dc.Pod.class),
VmSnapshot(com.cloud.vm.snapshot.VMSnapshot.class), VmSnapshot(com.cloud.vm.snapshot.VMSnapshot.class),
Role(org.apache.cloudstack.acl.Role.class), Role(org.apache.cloudstack.acl.Role.class),
VpnCustomerGateway(com.cloud.network.Site2SiteCustomerGateway.class); VpnCustomerGateway(com.cloud.network.Site2SiteCustomerGateway.class),
ManagementServer(org.apache.cloudstack.management.ManagementServerHost.class);
private final Class<?> clazz; private final Class<?> clazz;

View File

@ -16,10 +16,11 @@
// under the License. // under the License.
package org.apache.cloudstack.management; package org.apache.cloudstack.management;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.api.Identity; import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity; import org.apache.cloudstack.api.InternalIdentity;
public interface ManagementServerHost extends InternalIdentity, Identity { public interface ManagementServerHost extends InternalIdentity, Identity, ControlledEntity {
enum State { enum State {
Up, Down, PreparingToShutDown, ReadyToShutDown, ShuttingDown Up, Down, PreparingToShutDown, ReadyToShutDown, ShuttingDown
} }

View File

@ -124,6 +124,11 @@ public class ManagementServerHostVO implements ManagementServerHost {
this.msid = msid; this.msid = msid;
} }
@Override
public Class<?> getEntityType() {
return ManagementServerHost.class;
}
@Override @Override
public String getName() { public String getName() {
return name; return name;
@ -196,4 +201,14 @@ public class ManagementServerHostVO implements ManagementServerHost {
public String toString() { public String toString() {
return new StringBuilder("ManagementServer[").append("-").append(id).append("-").append(msid).append("-").append(state).append("]").toString(); return new StringBuilder("ManagementServer[").append("-").append(id).append("-").append(msid).append("-").append(state).append("]").toString();
} }
@Override
public long getDomainId() {
return 1L;
}
@Override
public long getAccountId() {
return 1L;
}
} }

View File

@ -26,6 +26,7 @@ import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import com.cloud.cluster.ManagementServerHostVO;
import com.cloud.user.dao.UserDataDao; import com.cloud.user.dao.UserDataDao;
import org.apache.cloudstack.acl.ControlledEntity; import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.Role; import org.apache.cloudstack.acl.Role;
@ -50,6 +51,7 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.cloud.cluster.dao.ManagementServerHostDao;
import com.cloud.dc.ClusterVO; import com.cloud.dc.ClusterVO;
import com.cloud.dc.DataCenterVO; import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO; import com.cloud.dc.HostPodVO;
@ -158,6 +160,8 @@ public final class AnnotationManagerImpl extends ManagerBase implements Annotati
@Inject @Inject
private UserDataDao userDataDao; private UserDataDao userDataDao;
@Inject @Inject
private ManagementServerHostDao managementServerHostDao;
@Inject
EntityManager entityManager; EntityManager entityManager;
private static final List<RoleType> adminRoles = Collections.singletonList(RoleType.Admin); private static final List<RoleType> adminRoles = Collections.singletonList(RoleType.Admin);
@ -192,6 +196,7 @@ public final class AnnotationManagerImpl extends ManagerBase implements Annotati
s_typeMap.put(EntityType.VR, ApiCommandResourceType.DomainRouter); s_typeMap.put(EntityType.VR, ApiCommandResourceType.DomainRouter);
s_typeMap.put(EntityType.SYSTEM_VM, ApiCommandResourceType.SystemVm); s_typeMap.put(EntityType.SYSTEM_VM, ApiCommandResourceType.SystemVm);
s_typeMap.put(EntityType.AUTOSCALE_VM_GROUP, ApiCommandResourceType.AutoScaleVmGroup); s_typeMap.put(EntityType.AUTOSCALE_VM_GROUP, ApiCommandResourceType.AutoScaleVmGroup);
s_typeMap.put(EntityType.MANAGEMENT_SERVER, ApiCommandResourceType.Host);
} }
public List<KubernetesClusterHelper> getKubernetesClusterHelpers() { public List<KubernetesClusterHelper> getKubernetesClusterHelpers() {
@ -532,6 +537,8 @@ public final class AnnotationManagerImpl extends ManagerBase implements Annotati
return kubernetesClusterHelpers.get(0).findByUuid(entityUuid); return kubernetesClusterHelpers.get(0).findByUuid(entityUuid);
case AUTOSCALE_VM_GROUP: case AUTOSCALE_VM_GROUP:
return autoScaleVmGroupDao.findByUuid(entityUuid); return autoScaleVmGroupDao.findByUuid(entityUuid);
case MANAGEMENT_SERVER:
return managementServerHostDao.findByUuid(entityUuid);
default: default:
throw new CloudRuntimeException("Invalid entity type " + type); throw new CloudRuntimeException("Invalid entity type " + type);
} }
@ -607,6 +614,9 @@ public final class AnnotationManagerImpl extends ManagerBase implements Annotati
case SYSTEM_VM: case SYSTEM_VM:
VMInstanceVO instance = vmInstanceDao.findByUuid(entityUuid); VMInstanceVO instance = vmInstanceDao.findByUuid(entityUuid);
return instance != null ? instance.getInstanceName() : null; return instance != null ? instance.getInstanceName() : null;
case MANAGEMENT_SERVER:
ManagementServerHostVO mgmtServer = managementServerHostDao.findByUuid(entityUuid);
return mgmtServer != null ? mgmtServer.getName() : null;
default: default:
return null; return null;
} }

View File

@ -83,6 +83,7 @@ class TestAnnotations(cloudstackTestCase):
cls.host = list_hosts(cls.apiclient, cls.host = list_hosts(cls.apiclient,
zoneid=cls.zone.id, zoneid=cls.zone.id,
type='Routing')[0] type='Routing')[0]
cls.mgmt_server = list_mgmt_servers(cls.apiclient)[0]
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
@ -135,6 +136,12 @@ class TestAnnotations(cloudstackTestCase):
self.addAnnotation("annotation1", self.host.id, "HOST") self.addAnnotation("annotation1", self.host.id, "HOST")
self.assertEqual(self.added_annotations[-1].annotation.annotation, "annotation1") self.assertEqual(self.added_annotations[-1].annotation.annotation, "annotation1")
@attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="false")
def test_01_add_ms_annotation(self):
"""Testing the addAnnotations API ability to add an annoatation per management server"""
self.addAnnotation("mgmt-server-annotation1", self.mgmt_server.id, "MANAGEMENT_SERVER")
self.assertEqual(self.added_annotations[-1].annotation.annotation, "mgmt-server-annotation1")
@attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="false") @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="false")
def test_02_add_multiple_annotations(self): def test_02_add_multiple_annotations(self):
"""Testing the addAnnotations API ability to add an annoatation per host """Testing the addAnnotations API ability to add an annoatation per host

View File

@ -58,6 +58,7 @@ from marvin.cloudstackAPI import (listConfigurations,
listNetworkOfferings, listNetworkOfferings,
listResourceLimits, listResourceLimits,
listVPCOfferings, listVPCOfferings,
listManagementServers,
migrateSystemVm) migrateSystemVm)
from marvin.sshClient import SshClient from marvin.sshClient import SshClient
from marvin.codes import (PASS, FAILED, ISOLATED_NETWORK, VPC_NETWORK, from marvin.codes import (PASS, FAILED, ISOLATED_NETWORK, VPC_NETWORK,
@ -1056,6 +1057,14 @@ def list_vpc_offerings(apiclient, **kwargs):
cmd.listall=True cmd.listall=True
return(apiclient.listVPCOfferings(cmd)) return(apiclient.listVPCOfferings(cmd))
def list_mgmt_servers(apiclient, **kwargs):
""" Lists Management Servers """
cmd = listManagementServers.listManagementServersCmd()
[setattr(cmd, k, v) for k, v in list(kwargs.items())]
if 'account' in list(kwargs.keys()) and 'domainid' in list(kwargs.keys()):
cmd.listall=True
return(apiclient.listManagementServers(cmd))
def update_resource_count(apiclient, domainid, accountid=None, def update_resource_count(apiclient, domainid, accountid=None,
projectid=None, rtype=None): projectid=None, rtype=None):

View File

@ -192,6 +192,7 @@ export default {
case 'SystemVm': return 'SYSTEM_VM' case 'SystemVm': return 'SYSTEM_VM'
case 'VirtualRouter': return 'VR' case 'VirtualRouter': return 'VR'
case 'AutoScaleVmGroup': return 'AUTOSCALE_VM_GROUP' case 'AutoScaleVmGroup': return 'AUTOSCALE_VM_GROUP'
case 'ManagementServer': return 'MANAGEMENT_SERVER'
default: return '' default: return ''
} }
}, },

View File

@ -24,6 +24,7 @@ export default {
icon: 'CloudServerOutlined', icon: 'CloudServerOutlined',
docHelp: 'conceptsandterminology/concepts.html#management-server-overview', docHelp: 'conceptsandterminology/concepts.html#management-server-overview',
permission: ['listManagementServersMetrics'], permission: ['listManagementServersMetrics'],
resourceType: 'ManagementServer',
columns: () => { columns: () => {
const fields = ['name', 'state', 'version'] const fields = ['name', 'state', 'version']
const metricsFields = ['collectiontime', 'availableprocessors', 'cpuload', 'heapmemoryused', 'agentcount'] const metricsFields = ['collectiontime', 'availableprocessors', 'cpuload', 'heapmemoryused', 'agentcount']
@ -80,6 +81,9 @@ export default {
value: (record, params) => { return record.id } value: (record, params) => { return record.id }
} }
} }
}, {
name: 'comments',
component: shallowRef(defineAsyncComponent(() => import('@/components/view/AnnotationsTab.vue')))
} }
] ]
} }