This repository has been archived by the owner on Jan 14, 2020. It is now read-only.
/
TaskFeClient.java
161 lines (128 loc) · 7.02 KB
/
TaskFeClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* Copyright 2015 VMware, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, without warranties or
* conditions of any kind, EITHER EXPRESS OR IMPLIED. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.vmware.photon.controller.api.frontend.clients;
import com.vmware.photon.controller.api.frontend.backends.AvailabilityZoneBackend;
import com.vmware.photon.controller.api.frontend.backends.DiskBackend;
import com.vmware.photon.controller.api.frontend.backends.FlavorBackend;
import com.vmware.photon.controller.api.frontend.backends.HostBackend;
import com.vmware.photon.controller.api.frontend.backends.ImageBackend;
import com.vmware.photon.controller.api.frontend.backends.ProjectBackend;
import com.vmware.photon.controller.api.frontend.backends.ResourceTicketBackend;
import com.vmware.photon.controller.api.frontend.backends.TaskBackend;
import com.vmware.photon.controller.api.frontend.backends.TenantBackend;
import com.vmware.photon.controller.api.frontend.backends.VmBackend;
import com.vmware.photon.controller.api.frontend.entities.HostEntity;
import com.vmware.photon.controller.api.frontend.entities.ImageEntity;
import com.vmware.photon.controller.api.frontend.entities.ProjectEntity;
import com.vmware.photon.controller.api.frontend.entities.ResourceTicketEntity;
import com.vmware.photon.controller.api.frontend.entities.TenantEntity;
import com.vmware.photon.controller.api.frontend.exceptions.external.ExternalException;
import com.vmware.photon.controller.api.model.AvailabilityZone;
import com.vmware.photon.controller.api.model.Flavor;
import com.vmware.photon.controller.api.model.PersistentDisk;
import com.vmware.photon.controller.api.model.ResourceList;
import com.vmware.photon.controller.api.model.Task;
import com.vmware.photon.controller.api.model.Vm;
import com.google.common.base.Optional;
import com.google.inject.Inject;
import com.google.inject.Singleton;
/**
* Frontend client for task used by {@link com.vmware.photon.controller.api.frontend.resources.tasks.TasksResource}
* and {@link com.vmware.photon.controller.api.frontend.resources.tasks.TaskResource}.
*/
@Singleton
public class TaskFeClient {
private final TaskBackend taskBackend;
private final TenantBackend tenantBackend;
private final ProjectBackend projectBackend;
private final ResourceTicketBackend resourceTicketBackend;
private final VmBackend vmBackend;
private final DiskBackend diskBackend;
private final ImageBackend imageBackend;
private final FlavorBackend flavorBackend;
private final HostBackend hostBackend;
private final AvailabilityZoneBackend availabilityZoneBackend;
@Inject
public TaskFeClient(TaskBackend taskBackend, TenantBackend tenantBackend, ProjectBackend projectBackend,
ResourceTicketBackend resourceTicketBackend, VmBackend vmBackend, DiskBackend diskBackend,
ImageBackend imageBackend, FlavorBackend flavorBackend, HostBackend hostBackend,
AvailabilityZoneBackend availabilityZoneBackend) {
this.taskBackend = taskBackend;
this.tenantBackend = tenantBackend;
this.projectBackend = projectBackend;
this.resourceTicketBackend = resourceTicketBackend;
this.vmBackend = vmBackend;
this.diskBackend = diskBackend;
this.imageBackend = imageBackend;
this.flavorBackend = flavorBackend;
this.hostBackend = hostBackend;
this.availabilityZoneBackend = availabilityZoneBackend;
}
public Task get(String id) throws ExternalException {
return taskBackend.getApiRepresentation(id);
}
public ResourceList<Task> find(Optional<String> entityId, Optional<String> entityKind, Optional<String> state,
Optional<Integer> pageSize)
throws ExternalException {
return taskBackend.filter(entityId, entityKind, state, pageSize);
}
public ResourceList<Task> getPage(String pageLink) throws ExternalException {
return taskBackend.getTasksPage(pageLink);
}
public ResourceList<Task> getTenantTasks(String tenantId, Optional<String> state, Optional<Integer> pageSize)
throws ExternalException {
tenantBackend.findById(tenantId);
return taskBackend.filter(Optional.of(tenantId), Optional.of(TenantEntity.KIND), state, pageSize);
}
public ResourceList<Task> getProjectTasks(String projectId, Optional<String> state, Optional<Integer> pagesize)
throws ExternalException {
projectBackend.findById(projectId);
return taskBackend.filter(Optional.of(projectId), Optional.of(ProjectEntity.KIND), state, pagesize);
}
public ResourceList<Task> getResourceTicketTasks(String resourceTicketId, Optional<String> state,
Optional<Integer> pageSize) throws ExternalException {
resourceTicketBackend.findById(resourceTicketId);
return taskBackend.filter(Optional.of(resourceTicketId), Optional.of(ResourceTicketEntity.KIND), state, pageSize);
}
public ResourceList<Task> getVmTasks(String vmId, Optional<String> state, Optional<Integer> pageSize)
throws ExternalException {
vmBackend.findById(vmId);
return taskBackend.filter(Optional.of(vmId), Optional.of(Vm.KIND), state, pageSize);
}
public ResourceList<Task> getDiskTasks(String diskId, Optional<String> state, Optional<Integer> pageSize)
throws ExternalException {
diskBackend.find(PersistentDisk.KIND, diskId);
return taskBackend.filter(Optional.of(diskId), Optional.of(PersistentDisk.KIND), state, pageSize);
}
public ResourceList<Task> getImageTasks(String imageId, Optional<String> state, Optional<Integer> pageSize)
throws ExternalException {
imageBackend.findById(imageId);
return taskBackend.filter(Optional.of(imageId), Optional.of(ImageEntity.KIND), state, pageSize);
}
public ResourceList<Task> getFlavorTasks(String flavorId, Optional<String> state, Optional<Integer> pageSize)
throws ExternalException {
flavorBackend.getEntityById(flavorId);
return taskBackend.filter(Optional.of(flavorId), Optional.of(Flavor.KIND), state, pageSize);
}
public ResourceList<Task> getHostTasks(String hostId, Optional<String> state, Optional<Integer> pageSize)
throws ExternalException {
hostBackend.findById(hostId);
return taskBackend.filter(Optional.of(hostId), Optional.of(HostEntity.KIND), state, pageSize);
}
public ResourceList<Task> getAvailabilityZoneTasks(String availabilityZoneId, Optional<String> state,
Optional<Integer> pageSize)
throws ExternalException {
availabilityZoneBackend.getEntityById(availabilityZoneId);
return taskBackend.filter(Optional.of(availabilityZoneId), Optional.of(AvailabilityZone.KIND), state, pageSize);
}
}