Skip to content

Commit 3f827ef

Browse files
authored
UI: Support to upload resource icons (#5157)
* Resource Icon support - backend * Add API support for resourceicon * update reponse params + ui support * Add exclusive list api for icons and UI changes * refactor upload view * UI changes to support resource icon wherever necessary * convert api to POST + refactor icon view * Add response name to list API + cosmetic changes in UI * Added support for the following: resource icon support for vpcs, networks, domains, and projects add icons to list view if reosurces support icons to be added support for showing project icons in the project switching drop-down menu * List resourceicon cmds to be allowed for user role too Users to inherit account icon if present (in listUsers response) Move common code to plugin.js Add icon to project list view - while switching between projects - Dashboard page Show icons against zones - Capacity Dashboard view Show user / account icon at the login button if present * cosmetic changes * optimize ui code * fix reload issue for domain view * add access check for delete operation * ui-related changes to show iso icons * iso image in uservm response * add icons to custom form's list resources * some more custom forms aligned to show icon for resources * conmitic changes + add listing of icons to listdomainchildren cmd * Add backend/server-side validation for base64 string passed for image * change preview border * preselect zone if there's only one * add default icon * show icon for network list in deploy vm view * add custom icons if any to the import-export VM view * preselect zone persistence on clearing cache * prevent root vol from inheriting template/iso icon * show tempalte icon in the info card details * fix icon not being show on hard-refresh / initial traversal * fx success message
1 parent f409e7a commit 3f827ef

115 files changed

Lines changed: 3001 additions & 303 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,10 @@ public class EventTypes {
493493
public static final String EVENT_TAGS_CREATE = "CREATE_TAGS";
494494
public static final String EVENT_TAGS_DELETE = "DELETE_TAGS";
495495

496+
// resource icon related events
497+
public static final String EVENT_RESOURCE_ICON_UPLOAD = "UPLOAD.RESOURCE.ICON";
498+
public static final String EVENT_RESOURCE_ICON_DELETE = "DELETE.RESOURCE.ICON";
499+
496500
// meta data related events
497501
public static final String EVENT_RESOURCE_DETAILS_CREATE = "CREATE_RESOURCE_DETAILS";
498502
public static final String EVENT_RESOURCE_DETAILS_DELETE = "DELETE_RESOURCE_DETAILS";
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.server;
18+
19+
import org.apache.cloudstack.api.Identity;
20+
import org.apache.cloudstack.api.InternalIdentity;
21+
22+
public interface ResourceIcon extends Identity, InternalIdentity {
23+
long getResourceId();
24+
25+
void setResourceId(long resourceId);
26+
27+
ResourceTag.ResourceObjectType getResourceType();
28+
29+
String getResourceUuid();
30+
31+
String getIcon();
32+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.server;
18+
19+
import java.util.List;
20+
21+
public interface ResourceIconManager {
22+
23+
boolean uploadResourceIcon(List<String> resourceIds, ResourceTag.ResourceObjectType resourceType, String base64Image);
24+
25+
boolean deleteResourceIcon(List<String> resourceIds, ResourceTag.ResourceObjectType resourceType);
26+
27+
ResourceIcon getByResourceTypeAndUuid(ResourceTag.ResourceObjectType type, String resourceId);
28+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.server;
18+
19+
public interface ResourceManagerUtil {
20+
long getResourceId(String resourceId, ResourceTag.ResourceObjectType resourceType);
21+
String getUuid(String resourceId, ResourceTag.ResourceObjectType resourceType);
22+
ResourceTag.ResourceObjectType getResourceType(String resourceTypeStr);
23+
void checkResourceAccessible(Long accountId, Long domainId, String exceptionMessage);
24+
}

api/src/main/java/com/cloud/server/ResourceTag.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,36 @@ public interface ResourceTag extends ControlledEntity, Identity, InternalIdentit
2424

2525
// FIXME - extract enum to another interface as its used both by resourceTags and resourceMetaData code
2626
public enum ResourceObjectType {
27-
UserVm(true, true),
28-
Template(true, true),
29-
ISO(true, false),
27+
UserVm(true, true, true),
28+
Template(true, true, true),
29+
ISO(true, false, true),
3030
Volume(true, true),
3131
Snapshot(true, false),
3232
Backup(true, false),
33-
Network(true, true),
33+
Network(true, true, true),
3434
Nic(false, true),
3535
LoadBalancer(true, true),
3636
PortForwardingRule(true, true),
3737
FirewallRule(true, true),
3838
SecurityGroup(true, false),
3939
SecurityGroupRule(true, false),
4040
PublicIpAddress(true, true),
41-
Project(true, false),
42-
Account(true, false),
43-
Vpc(true, true),
41+
Project(true, false, true),
42+
Account(true, false, true),
43+
Vpc(true, true, true),
4444
NetworkACL(true, true),
4545
StaticRoute(true, false),
4646
VMSnapshot(true, false),
4747
RemoteAccessVpn(true, true),
48-
Zone(false, true),
48+
Zone(false, true, true),
4949
ServiceOffering(false, true),
5050
Storage(false, true),
5151
PrivateGateway(false, true),
5252
NetworkACLList(false, true),
5353
VpnGateway(false, true),
5454
CustomerGateway(false, true),
5555
VpnConnection(false, true),
56-
User(true, true),
56+
User(true, true, true),
5757
DiskOffering(false, true),
5858
AutoScaleVmProfile(false, true),
5959
AutoScaleVmGroup(false, true),
@@ -62,16 +62,23 @@ public enum ResourceObjectType {
6262
SnapshotPolicy(true, true),
6363
GuestOs(false, true),
6464
NetworkOffering(false, true),
65-
VpcOffering(true, false);
65+
VpcOffering(true, false),
66+
Domain(false, false, true);
6667

6768

6869
ResourceObjectType(boolean resourceTagsSupport, boolean resourceMetadataSupport) {
6970
this.resourceTagsSupport = resourceTagsSupport;
7071
metadataSupport = resourceMetadataSupport;
7172
}
7273

74+
ResourceObjectType(boolean resourceTagsSupport, boolean resourceMetadataSupport, boolean resourceIconSupport) {
75+
this(resourceTagsSupport, resourceMetadataSupport);
76+
this.resourceIconSupport = resourceIconSupport;
77+
}
78+
7379
private final boolean resourceTagsSupport;
7480
private final boolean metadataSupport;
81+
private boolean resourceIconSupport;
7582

7683
public boolean resourceTagsSupport() {
7784
return resourceTagsSupport;
@@ -80,6 +87,10 @@ public boolean resourceTagsSupport() {
8087
public boolean resourceMetadataSupport() {
8188
return metadataSupport;
8289
}
90+
91+
public boolean resourceIconSupport() {
92+
return resourceIconSupport;
93+
}
8394
}
8495

8596
/**

api/src/main/java/com/cloud/server/TaggedResourceService.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ public interface TaggedResourceService {
4343

4444
List<? extends ResourceTag> listByResourceTypeAndId(ResourceObjectType type, long resourceId);
4545

46-
//FIXME - the methods below should be extracted to its separate manager/service responsible just for retrieving object details
47-
ResourceObjectType getResourceType(String resourceTypeStr);
48-
49-
/**
50-
* @param resourceId
51-
* @param resourceType
52-
* @return
53-
*/
54-
String getUuid(String resourceId, ResourceObjectType resourceType);
55-
56-
public long getResourceId(String resourceId, ResourceObjectType resourceType);
57-
5846
/**
5947
* Retrieves tags from resource.
6048
* @param type

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class ApiConstants {
3737
public static final String BACKUP_ID = "backupid";
3838
public static final String BACKUP_OFFERING_NAME = "backupofferingname";
3939
public static final String BACKUP_OFFERING_ID = "backupofferingid";
40+
public static final String BASE64_IMAGE = "base64image";
4041
public static final String BITS = "bits";
4142
public static final String BOOTABLE = "bootable";
4243
public static final String BIND_DN = "binddn";
@@ -333,6 +334,7 @@ public class ApiConstants {
333334
public static final String SESSIONKEY = "sessionkey";
334335
public static final String SHOW_CAPACITIES = "showcapacities";
335336
public static final String SHOW_REMOVED = "showremoved";
337+
public static final String SHOW_RESOURCE_ICON = "showicon";
336338
public static final String SHOW_UNIQUE = "showunique";
337339
public static final String SIGNATURE = "signature";
338340
public static final String SIGNATURE_VERSION = "signatureversion";
@@ -747,6 +749,7 @@ public class ApiConstants {
747749
public static final String ACCESS_TYPE = "accesstype";
748750

749751
public static final String RESOURCE_DETAILS = "resourcedetails";
752+
public static final String RESOURCE_ICON = "icon";
750753
public static final String EXPUNGE = "expunge";
751754
public static final String FOR_DISPLAY = "fordisplay";
752755
public static final String PASSIVE = "passive";

api/src/main/java/org/apache/cloudstack/api/BaseCmd.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929

3030
import javax.inject.Inject;
3131

32+
import com.cloud.server.ManagementService;
33+
import com.cloud.server.ResourceIconManager;
34+
import com.cloud.server.ResourceManagerUtil;
35+
import com.cloud.server.ResourceMetaDataService;
36+
import com.cloud.server.TaggedResourceService;
3237
import org.apache.cloudstack.acl.ProjectRoleService;
3338
import org.apache.cloudstack.acl.RoleService;
3439
import org.apache.cloudstack.acl.RoleType;
@@ -67,9 +72,6 @@
6772
import com.cloud.network.vpn.Site2SiteVpnService;
6873
import com.cloud.projects.ProjectService;
6974
import com.cloud.resource.ResourceService;
70-
import com.cloud.server.ManagementService;
71-
import com.cloud.server.ResourceMetaDataService;
72-
import com.cloud.server.TaggedResourceService;
7375
import com.cloud.storage.DataStoreProviderApiService;
7476
import com.cloud.storage.StorageService;
7577
import com.cloud.storage.VolumeApiService;
@@ -164,6 +166,8 @@ public static enum CommandType {
164166
@Inject
165167
public TaggedResourceService _taggedResourceService;
166168
@Inject
169+
public ResourceManagerUtil resourceManagerUtil;
170+
@Inject
167171
public ResourceMetaDataService _resourceMetaDataService;
168172
@Inject
169173
public VpcService _vpcService;
@@ -201,6 +205,8 @@ public static enum CommandType {
201205
public UUIDManager _uuidMgr;
202206
@Inject
203207
public AnnotationService annotationService;
208+
@Inject
209+
public ResourceIconManager resourceIconManager;
204210

205211
public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,
206212
ResourceAllocationException, NetworkRuleConflictException;

api/src/main/java/org/apache/cloudstack/api/ResponseGenerator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.Map;
2323
import java.util.Set;
2424

25+
import com.cloud.server.ResourceIcon;
26+
import org.apache.cloudstack.api.response.ResourceIconResponse;
2527
import org.apache.cloudstack.api.response.RouterHealthCheckResultResponse;
2628
import com.cloud.resource.RollingMaintenanceManager;
2729
import org.apache.cloudstack.api.response.RollingMaintenanceResponse;
@@ -270,7 +272,7 @@ public interface ResponseGenerator {
270272

271273
PodResponse createPodResponse(Pod pod, Boolean showCapacities);
272274

273-
ZoneResponse createZoneResponse(ResponseView view, DataCenter dataCenter, Boolean showCapacities);
275+
ZoneResponse createZoneResponse(ResponseView view, DataCenter dataCenter, Boolean showCapacities, Boolean showResourceIcon);
274276

275277
VolumeResponse createVolumeResponse(ResponseView view, Volume volume);
276278

@@ -487,4 +489,6 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
487489

488490
RollingMaintenanceResponse createRollingMaintenanceResponse(Boolean success, String details, List<RollingMaintenanceManager.HostUpdated> hostsUpdated, List<RollingMaintenanceManager.HostSkipped> hostsSkipped);
489491

492+
ResourceIconResponse createResourceIconResponse(ResourceIcon resourceIcon);
493+
490494
}

api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainChildrenCmd.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22+
import com.cloud.server.ResourceIcon;
23+
import com.cloud.server.ResourceTag;
24+
import org.apache.cloudstack.api.response.ResourceIconResponse;
2225
import org.apache.log4j.Logger;
2326

2427
import org.apache.cloudstack.api.APICommand;
@@ -58,6 +61,10 @@ public class ListDomainChildrenCmd extends BaseListCmd {
5861
description = "If set to false, list only resources belonging to the command's caller; if set to true - list resources that the caller is authorized to see. Default value is false")
5962
private Boolean listAll;
6063

64+
@Parameter(name = ApiConstants.SHOW_RESOURCE_ICON, type = CommandType.BOOLEAN,
65+
description = "flag to display the resource icon for domains")
66+
private Boolean showIcon;
67+
6168
/////////////////////////////////////////////////////
6269
/////////////////// Accessors ///////////////////////
6370
/////////////////////////////////////////////////////
@@ -78,6 +85,10 @@ public boolean isRecursive() {
7885
return recursive == null ? false : recursive;
7986
}
8087

88+
public Boolean getShowIcon() {
89+
return showIcon != null ? showIcon : false;
90+
}
91+
8192
/////////////////////////////////////////////////////
8293
/////////////// API Implementation///////////////////
8394
/////////////////////////////////////////////////////
@@ -100,6 +111,20 @@ public void execute() {
100111

101112
response.setResponses(domainResponses, result.second());
102113
response.setResponseName(getCommandName());
114+
if (response != null && response.getCount() > 0 && getShowIcon()) {
115+
updateDomainResponse(response.getResponses());
116+
}
103117
this.setResponseObject(response);
104118
}
119+
120+
private void updateDomainResponse(List<DomainResponse> response) {
121+
for (DomainResponse domainResponse : response) {
122+
ResourceIcon resourceIcon = resourceIconManager.getByResourceTypeAndUuid(ResourceTag.ResourceObjectType.Domain, domainResponse.getId());
123+
if (resourceIcon == null) {
124+
continue;
125+
}
126+
ResourceIconResponse iconResponse = _responseGenerator.createResourceIconResponse(resourceIcon);
127+
domainResponse.setResourceIconResponse(iconResponse);
128+
}
129+
}
105130
}

0 commit comments

Comments
 (0)