mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	Merge branch '2.1.refactor' of ssh://git.cloud.com/var/lib/git/cloudstack-oss into 2.1.refactor
This commit is contained in:
		
						commit
						6070948e16
					
				| @ -26,6 +26,8 @@ import java.util.Map; | ||||
| import org.apache.log4j.Logger; | ||||
| 
 | ||||
| import com.cloud.api.BaseCmd; | ||||
| import com.cloud.api.BaseCmd.CommandType; | ||||
| import com.cloud.api.BaseListCmd; | ||||
| import com.cloud.api.Parameter; | ||||
| import com.cloud.api.ServerApiException; | ||||
| import com.cloud.configuration.ResourceCount.ResourceType; | ||||
| @ -38,7 +40,7 @@ import com.cloud.uservm.UserVm; | ||||
| import com.cloud.utils.Pair; | ||||
| import com.cloud.vm.State; | ||||
| 
 | ||||
| public class ListAccountsCmd extends BaseCmd{ | ||||
| public class ListAccountsCmd extends BaseListCmd{ | ||||
| 	public static final Logger s_logger = Logger.getLogger(ListAccountsCmd.class.getName()); | ||||
|     private static final String s_name = "listaccountsresponse"; | ||||
|     private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>(); | ||||
|  | ||||
| @ -20,31 +20,22 @@ package com.cloud.api.commands; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| import org.apache.log4j.Logger; | ||||
| 
 | ||||
| import com.cloud.alert.AlertVO; | ||||
| import com.cloud.api.BaseCmd; | ||||
| import com.cloud.api.BaseListCmd; | ||||
| import com.cloud.api.Implementation; | ||||
| import com.cloud.api.Parameter; | ||||
| import com.cloud.api.ServerApiException; | ||||
| import com.cloud.server.Criteria; | ||||
| import com.cloud.utils.Pair; | ||||
| import com.cloud.api.response.AlertResponse; | ||||
| import com.cloud.serializer.SerializerHelper; | ||||
| 
 | ||||
| 
 | ||||
| public class ListAlertsCmd extends BaseCmd { | ||||
| @Implementation(method="searchForALerts") | ||||
| public class ListAlertsCmd extends BaseListCmd { | ||||
| 
 | ||||
|     public static final Logger s_logger = Logger.getLogger(ListAlertsCmd.class.getName()); | ||||
| 
 | ||||
|     private static final String s_name = "listalertsresponse"; | ||||
|     private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>(); | ||||
| 
 | ||||
|     static { | ||||
|         s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.TYPE, Boolean.FALSE)); | ||||
|         s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.KEYWORD, Boolean.FALSE)); | ||||
|         s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGE, Boolean.FALSE)); | ||||
|         s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGESIZE, Boolean.FALSE)); | ||||
|     } | ||||
| 
 | ||||
|     ///////////////////////////////////////////////////// | ||||
|     //////////////// API parameters ///////////////////// | ||||
| @ -67,60 +58,25 @@ public class ListAlertsCmd extends BaseCmd { | ||||
|     /////////////// API Implementation/////////////////// | ||||
|     ///////////////////////////////////////////////////// | ||||
| 
 | ||||
|     @Override | ||||
|     public String getName() { | ||||
|         return s_name; | ||||
|     } | ||||
| 
 | ||||
|     public List<Pair<Enum, Boolean>> getProperties() { | ||||
|         return s_properties; | ||||
|     } | ||||
|     @Override @SuppressWarnings("unchecked") | ||||
|     public String getResponse() { | ||||
|         List<AlertVO> alertList = (List<AlertVO>)getResponseObject(); | ||||
| 
 | ||||
|     @Override | ||||
|     public List<Pair<String, Object>> execute(Map<String, Object> params) { | ||||
|         String alertType = (String) params.get(BaseCmd.Properties.TYPE.getName()); | ||||
|         String keyword = (String) params.get(BaseCmd.Properties.KEYWORD.getName()); | ||||
|         Integer page = (Integer) params.get(BaseCmd.Properties.PAGE.getName()); | ||||
|         Integer pageSize = (Integer) params.get(BaseCmd.Properties.PAGESIZE.getName()); | ||||
|         List<AlertResponse> alertResponseList = new ArrayList<AlertResponse>(); | ||||
|         for (AlertVO alert : alertList) { | ||||
|             AlertResponse alertResponse = new AlertResponse(); | ||||
|             alertResponse.setAlertType(alert.getType()); | ||||
|             alertResponse.setDescription(alert.getSubject()); | ||||
|             alertResponse.setLastSent(alert.getLastSent()); | ||||
| 
 | ||||
|         Long startIndex = Long.valueOf(0); | ||||
|         int pageSizeNum = 50; | ||||
|         if (pageSize != null) { | ||||
|             pageSizeNum = pageSize.intValue(); | ||||
|         } | ||||
|         if (page != null) { | ||||
|             int pageNum = page.intValue(); | ||||
|             if (pageNum > 0) { | ||||
|                 startIndex = Long.valueOf(pageSizeNum * (pageNum - 1)); | ||||
|             } | ||||
|             alertResponseList.add(alertResponse); | ||||
|         } | ||||
| 
 | ||||
|         Criteria c = new Criteria("lastSent", Boolean.FALSE, startIndex, Long.valueOf(pageSizeNum)); | ||||
|         c.addCriteria(Criteria.KEYWORD, keyword); | ||||
| 
 | ||||
|         if (keyword == null) | ||||
|             c.addCriteria(Criteria.TYPE, alertType); | ||||
| 
 | ||||
|         List<AlertVO> alerts = getManagementServer().searchForAlerts(c); | ||||
| 
 | ||||
|         if (alerts == null) { | ||||
|             throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "unable to find alerts"); | ||||
|         } | ||||
| 
 | ||||
|         List<Pair<String, Object>> alertsTags = new ArrayList<Pair<String, Object>>(); | ||||
|         Object[] aTag = new Object[alerts.size()]; | ||||
|         int i = 0; | ||||
| 
 | ||||
|         for (AlertVO alert : alerts) { | ||||
|             List<Pair<String, Object>> alertData = new ArrayList<Pair<String, Object>>(); | ||||
|             alertData.add(new Pair<String, Object>(BaseCmd.Properties.TYPE.getName(), alert.getType())); | ||||
|             alertData.add(new Pair<String, Object>(BaseCmd.Properties.DESCRIPTION.getName(), alert.getSubject())); | ||||
|             alertData.add(new Pair<String, Object>(BaseCmd.Properties.SENT.getName(), alert.getLastSent())); | ||||
|             aTag[i++] = alertData; | ||||
|         } | ||||
| 
 | ||||
|         Pair<String, Object> alertTag = new Pair<String, Object>("alert", aTag); | ||||
|         alertsTags.add(alertTag); | ||||
|         return alertsTags; | ||||
| 
 | ||||
|         return SerializerHelper.toSerializedString(alertResponseList); | ||||
|     } | ||||
| } | ||||
|  | ||||
							
								
								
									
										41
									
								
								server/src/com/cloud/api/response/AlertResponse.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								server/src/com/cloud/api/response/AlertResponse.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,41 @@ | ||||
| package com.cloud.api.response; | ||||
| 
 | ||||
| import java.util.Date; | ||||
| 
 | ||||
| import com.cloud.api.ResponseObject; | ||||
| import com.cloud.serializer.Param; | ||||
| 
 | ||||
| public class AlertResponse implements ResponseObject { | ||||
|     @Param(name="type") | ||||
|     private Short alertType; | ||||
| 
 | ||||
|     @Param(name="description") | ||||
|     private String description; | ||||
| 
 | ||||
|     @Param(name="sent") | ||||
|     private Date lastSent; | ||||
| 
 | ||||
|     public Short getAlertType() { | ||||
|         return alertType; | ||||
|     } | ||||
| 
 | ||||
|     public void setAlertType(Short alertType) { | ||||
|         this.alertType = alertType; | ||||
|     } | ||||
| 
 | ||||
|     public String getDescription() { | ||||
|         return description; | ||||
|     } | ||||
| 
 | ||||
|     public void setDescription(String description) { | ||||
|         this.description = description; | ||||
|     } | ||||
| 
 | ||||
|     public Date getLastSent() { | ||||
|         return lastSent; | ||||
|     } | ||||
| 
 | ||||
|     public void setLastSent(Date lastSent) { | ||||
|         this.lastSent = lastSent; | ||||
|     } | ||||
| } | ||||
| @ -31,6 +31,7 @@ import com.cloud.api.commands.DisassociateIPAddrCmd; | ||||
| import com.cloud.api.commands.EnableAccountCmd; | ||||
| import com.cloud.api.commands.EnableUserCmd; | ||||
| import com.cloud.api.commands.GetCloudIdentifierCmd; | ||||
| import com.cloud.api.commands.ListAlertsCmd; | ||||
| import com.cloud.api.commands.LockAccountCmd; | ||||
| import com.cloud.api.commands.LockUserCmd; | ||||
| import com.cloud.api.commands.RebootSystemVmCmd; | ||||
| @ -1526,7 +1527,7 @@ public interface ManagementServer { | ||||
|      * @param c | ||||
|      * @return List of Alerts | ||||
|      */ | ||||
|     List<AlertVO> searchForAlerts(Criteria c); | ||||
|     List<AlertVO> searchForAlerts(ListAlertsCmd cmd); | ||||
| 
 | ||||
|     /** | ||||
|      * list all the capacity rows in capacity operations table | ||||
|  | ||||
| @ -65,13 +65,13 @@ import com.cloud.api.commands.CreatePortForwardingServiceRuleCmd; | ||||
| import com.cloud.api.commands.CreateUserCmd; | ||||
| import com.cloud.api.commands.CreateVolumeCmd; | ||||
| import com.cloud.api.commands.DeleteIsoCmd; | ||||
| import com.cloud.api.commands.DeleteTemplateCmd; | ||||
| import com.cloud.api.commands.DeleteUserCmd; | ||||
| import com.cloud.api.commands.DeployVMCmd; | ||||
| import com.cloud.api.commands.DisassociateIPAddrCmd; | ||||
| import com.cloud.api.commands.EnableAccountCmd; | ||||
| import com.cloud.api.commands.EnableUserCmd; | ||||
| import com.cloud.api.commands.GetCloudIdentifierCmd; | ||||
| import com.cloud.api.commands.ListAlertsCmd; | ||||
| import com.cloud.api.commands.LockAccountCmd; | ||||
| import com.cloud.api.commands.LockUserCmd; | ||||
| import com.cloud.api.commands.PrepareForMaintenanceCmd; | ||||
| @ -111,15 +111,15 @@ import com.cloud.async.executor.NetworkGroupIngressParam; | ||||
| import com.cloud.async.executor.SecurityGroupParam; | ||||
| import com.cloud.async.executor.UpdateLoadBalancerParam; | ||||
| import com.cloud.async.executor.VMOperationParam; | ||||
| import com.cloud.async.executor.VolumeOperationParam; | ||||
| import com.cloud.async.executor.VMOperationParam.VmOp; | ||||
| import com.cloud.async.executor.VolumeOperationParam; | ||||
| import com.cloud.async.executor.VolumeOperationParam.VolumeOp; | ||||
| import com.cloud.capacity.CapacityVO; | ||||
| import com.cloud.capacity.dao.CapacityDao; | ||||
| import com.cloud.configuration.ConfigurationManager; | ||||
| import com.cloud.configuration.ConfigurationVO; | ||||
| import com.cloud.configuration.ResourceLimitVO; | ||||
| import com.cloud.configuration.ResourceCount.ResourceType; | ||||
| import com.cloud.configuration.ResourceLimitVO; | ||||
| import com.cloud.configuration.dao.ConfigurationDao; | ||||
| import com.cloud.configuration.dao.ResourceLimitDao; | ||||
| import com.cloud.consoleproxy.ConsoleProxyManager; | ||||
| @ -129,8 +129,8 @@ import com.cloud.dc.DataCenterIpAddressVO; | ||||
| import com.cloud.dc.DataCenterVO; | ||||
| import com.cloud.dc.HostPodVO; | ||||
| import com.cloud.dc.PodVlanMapVO; | ||||
| import com.cloud.dc.VlanVO; | ||||
| import com.cloud.dc.Vlan.VlanType; | ||||
| import com.cloud.dc.VlanVO; | ||||
| import com.cloud.dc.dao.AccountVlanMapDao; | ||||
| import com.cloud.dc.dao.ClusterDao; | ||||
| import com.cloud.dc.dao.DataCenterDao; | ||||
| @ -194,21 +194,21 @@ import com.cloud.storage.GuestOSCategoryVO; | ||||
| import com.cloud.storage.GuestOSVO; | ||||
| import com.cloud.storage.LaunchPermissionVO; | ||||
| import com.cloud.storage.Snapshot; | ||||
| import com.cloud.storage.Snapshot.SnapshotType; | ||||
| import com.cloud.storage.SnapshotPolicyVO; | ||||
| import com.cloud.storage.SnapshotScheduleVO; | ||||
| import com.cloud.storage.SnapshotVO; | ||||
| import com.cloud.storage.Storage; | ||||
| import com.cloud.storage.Storage.ImageFormat; | ||||
| import com.cloud.storage.StorageManager; | ||||
| import com.cloud.storage.StoragePoolVO; | ||||
| import com.cloud.storage.StorageStats; | ||||
| import com.cloud.storage.VMTemplateHostVO; | ||||
| import com.cloud.storage.VMTemplateStorageResourceAssoc; | ||||
| import com.cloud.storage.VMTemplateVO; | ||||
| import com.cloud.storage.Volume.VolumeType; | ||||
| import com.cloud.storage.VolumeStats; | ||||
| import com.cloud.storage.VolumeVO; | ||||
| import com.cloud.storage.Snapshot.SnapshotType; | ||||
| import com.cloud.storage.Storage.ImageFormat; | ||||
| import com.cloud.storage.Volume.VolumeType; | ||||
| import com.cloud.storage.dao.DiskOfferingDao; | ||||
| import com.cloud.storage.dao.DiskTemplateDao; | ||||
| import com.cloud.storage.dao.GuestOSCategoryDao; | ||||
| @ -218,9 +218,9 @@ import com.cloud.storage.dao.SnapshotDao; | ||||
| import com.cloud.storage.dao.SnapshotPolicyDao; | ||||
| import com.cloud.storage.dao.StoragePoolDao; | ||||
| import com.cloud.storage.dao.VMTemplateDao; | ||||
| import com.cloud.storage.dao.VMTemplateDao.TemplateFilter; | ||||
| import com.cloud.storage.dao.VMTemplateHostDao; | ||||
| import com.cloud.storage.dao.VolumeDao; | ||||
| import com.cloud.storage.dao.VMTemplateDao.TemplateFilter; | ||||
| import com.cloud.storage.preallocatedlun.PreallocatedLunVO; | ||||
| import com.cloud.storage.preallocatedlun.dao.PreallocatedLunDao; | ||||
| import com.cloud.storage.secondary.SecondaryStorageVmManager; | ||||
| @ -242,12 +242,12 @@ import com.cloud.user.dao.UserDao; | ||||
| import com.cloud.user.dao.UserStatisticsDao; | ||||
| import com.cloud.uservm.UserVm; | ||||
| import com.cloud.utils.DateUtil; | ||||
| import com.cloud.utils.DateUtil.IntervalType; | ||||
| import com.cloud.utils.EnumUtils; | ||||
| import com.cloud.utils.NumbersUtil; | ||||
| import com.cloud.utils.Pair; | ||||
| import com.cloud.utils.PasswordGenerator; | ||||
| import com.cloud.utils.StringUtils; | ||||
| import com.cloud.utils.DateUtil.IntervalType; | ||||
| import com.cloud.utils.component.Adapters; | ||||
| import com.cloud.utils.component.ComponentLocator; | ||||
| import com.cloud.utils.concurrency.NamedThreadFactory; | ||||
| @ -6314,12 +6314,27 @@ public class ManagementServerImpl implements ManagementServer { | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public List<AlertVO> searchForAlerts(Criteria c) { | ||||
|         Filter searchFilter = new Filter(AlertVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit()); | ||||
|     public List<AlertVO> searchForAlerts(ListAlertsCmd cmd) { | ||||
|         Integer page = cmd.getPage(); | ||||
|         Integer pageSize = cmd.getPageSize(); | ||||
|         Long startIndex = Long.valueOf(0); | ||||
|         long pageSizeNum = 50; | ||||
|         if (pageSize != null) { | ||||
|             pageSizeNum = pageSize.intValue(); | ||||
|         } | ||||
|         if (page != null) { | ||||
|             int pageNum = page.intValue(); | ||||
|             if (pageNum > 0) { | ||||
|                 startIndex = pageSizeNum * (pageNum - 1L); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         Filter searchFilter = new Filter(AlertVO.class, "lastSent", false, startIndex, pageSizeNum); | ||||
|         SearchCriteria<AlertVO> sc = _alertDao.createSearchCriteria(); | ||||
| 
 | ||||
|         Object type = c.getCriteria(Criteria.TYPE); | ||||
|         Object keyword = c.getCriteria(Criteria.KEYWORD); | ||||
|          | ||||
|         Object type = cmd.getType(); | ||||
|         Object keyword = cmd.getKeyword(); | ||||
| 
 | ||||
|         if (keyword != null) { | ||||
|             SearchCriteria<AlertVO> ssc = _alertDao.createSearchCriteria(); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user