Skip to content

Commit 574f0ea

Browse files
committed
address comments
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 5710676 commit 574f0ea

16 files changed

Lines changed: 124 additions & 86 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ public class ApiConstants {
261261
public static final String FOR_VIRTUAL_NETWORK = "forvirtualnetwork";
262262
public static final String FOR_SYSTEM_VMS = "forsystemvms";
263263
public static final String FOR_PROVIDER = "forprovider";
264+
public static final String FROM_CHECKPOINT_ID = "fromcheckpointid";
264265
public static final String FULL_PATH = "fullpath";
265266
public static final String GATEWAY = "gateway";
266267
public static final String IP6_GATEWAY = "ip6gateway";
@@ -610,6 +611,7 @@ public class ApiConstants {
610611
public static final String TENANT_NAME = "tenantname";
611612
public static final String TOTAL = "total";
612613
public static final String TOTAL_SUBNETS = "totalsubnets";
614+
public static final String TO_CHECKPOINT_ID = "tocheckpointid";
613615
public static final String TYPE = "type";
614616
public static final String TRUST_STORE = "truststore";
615617
public static final String TRUST_STORE_PASSWORD = "truststorepass";

api/src/main/java/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ private Long getProjectId() {
163163

164164
public Long getStorageId() {
165165
if (snapshotId != null && storageId != null) {
166-
throw new IllegalArgumentException("StorageId parameter cannot be specified with the SnapshotId parameter.");
166+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR,
167+
"StorageId parameter cannot be specified with the SnapshotId parameter.");
167168
}
168169
return storageId;
169170
}

api/src/main/java/org/apache/cloudstack/api/response/BackupResponse.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,16 @@ public class BackupResponse extends BaseResponse {
127127
@Param(description = "Indicates whether the VM from which the backup was taken is expunged or not", since = "4.22.0")
128128
private Boolean isVmExpunged;
129129

130-
@SerializedName("from_checkpoint_id")
131-
@Param(description = "Previous active checkpoint id for incremental backups", since = "4.22.0")
130+
@SerializedName(ApiConstants.FROM_CHECKPOINT_ID)
131+
@Param(description = "Previous active checkpoint ID for incremental backups", since = "4.23.0")
132132
private String fromCheckpointId;
133133

134-
@SerializedName("to_checkpoint_id")
135-
@Param(description = "Next checkpoint id for incremental backups", since = "4.22.0")
134+
@SerializedName(ApiConstants.TO_CHECKPOINT_ID)
135+
@Param(description = "Next checkpoint ID for incremental backups", since = "4.23.0")
136136
private String toCheckpointId;
137137

138138
@SerializedName(ApiConstants.HOST_ID)
139-
@Param(description = "Host ID where the backup is running", since = "4.22.0")
139+
@Param(description = "Host ID where the backup is running", since = "4.23.0")
140140
private String hostId;
141141

142142
public String getId() {

plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlServer.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
import java.util.List;
2626

2727
import javax.servlet.DispatcherType;
28+
import javax.servlet.http.HttpServlet;
2829
import javax.servlet.http.HttpServletRequest;
30+
import javax.servlet.http.HttpServletResponse;
2931

3032
import org.apache.cloudstack.utils.server.ServerPropertiesUtil;
3133
import org.apache.cloudstack.veeam.api.ApiRouteHandler;
@@ -155,33 +157,27 @@ private static Handler buildContextHandler(ServletContextHandler ctx) {
155157
// Handler for root ('/') path
156158
final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
157159
root.setContextPath("/");
158-
root.addServlet(new ServletHolder(new javax.servlet.http.HttpServlet() {
160+
root.addServlet(new ServletHolder(new HttpServlet() {
159161
private static final long serialVersionUID = 1L;
160162

161163
@Override
162-
protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
164+
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
163165
throws java.io.IOException {
164166
resp.setContentType("text/plain");
165-
resp.setStatus(javax.servlet.http.HttpServletResponse.SC_OK);
167+
resp.setStatus(HttpServletResponse.SC_OK);
166168
resp.getWriter().println("Veeam Control API");
167169
}
168170

169171
@Override
170-
protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
172+
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
171173
throws java.io.IOException {
172174
doGet(req, resp);
173175
}
174176
}), "/*");
175177

176178
final RequestLog requestLog = (request, response) -> {
177-
final String uri = request.getRequestURI() +
178-
(request.getQueryString() != null ? "?" + request.getQueryString() : "");
179-
LOGGER.info("Request - remoteAddr: {}, method: {}, uri: {}, headers: {}, status: {}",
180-
request.getRemoteAddr(),
181-
request.getMethod(),
182-
uri,
183-
dumpRequestHeaders(request),
184-
response.getStatus());
179+
LOGGER.debug("Handled request - {}",
180+
() -> getRequestResponseMetadata(request, response));
185181
};
186182

187183
final RequestLogHandler requestLogHandler = new RequestLogHandler();
@@ -201,16 +197,25 @@ public void stop() throws Exception {
201197
}
202198
}
203199

204-
private static String dumpRequestHeaders(HttpServletRequest request) {
200+
private static String getRequestResponseMetadata(HttpServletRequest request, HttpServletResponse response) {
205201
final StringBuilder sb = new StringBuilder();
206-
final Enumeration<String> headerNames = request.getHeaderNames();
207-
while (headerNames.hasMoreElements()) {
208-
final String name = headerNames.nextElement();
209-
final Enumeration<String> values = request.getHeaders(name);
210-
while (values.hasMoreElements()) {
211-
sb.append(name).append("=").append(values.nextElement()).append("; ");
202+
sb.append("remote address: ").append(request.getRemoteAddr()).append(", ");
203+
sb.append("method: ").append(request.getMethod()).append(", ");
204+
sb.append("uri: ").append(request.getRequestURI())
205+
.append(request.getQueryString() != null ? "?" + request.getQueryString() : "").append(", ");
206+
if (VeeamControlService.DeveloperLogs.value()) {
207+
sb.append("headers: [");
208+
final Enumeration<String> headerNames = request.getHeaderNames();
209+
while (headerNames.hasMoreElements()) {
210+
final String name = headerNames.nextElement();
211+
final Enumeration<String> values = request.getHeaders(name);
212+
while (values.hasMoreElements()) {
213+
sb.append(name).append("=").append(values.nextElement()).append("; ");
214+
}
212215
}
216+
sb.append("], ");
213217
}
218+
sb.append("status: ").append(response.getStatus());
214219
return sb.toString();
215220
}
216221
}

plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,20 @@ public interface VeeamControlService extends PluggableService, Configurable {
5757
"", "Comma-separated list of CIDR blocks representing clients allowed to access the API. " +
5858
"If empty, all clients will be allowed. Example: '192.168.1.1/24,192.168.2.100/32", true);
5959

60+
ConfigKey<Boolean> DeveloperLogs = new ConfigKey<>("Developer", Boolean.class, "integration.veeam.control.developer.logs",
61+
"false", "Enable verbose logging for development and troubleshooting purposes. " +
62+
"Logs will include detailed information about API requests, responses, and internal operations.", false);
63+
6064
long getCurrentManagementServerHostId();
6165

6266
List<String> getAllowedClientCidrs();
6367

68+
String getInstanceId();
69+
6470
boolean validateCredentials(String username, String password);
6571

72+
String getHmacSecret();
73+
6674
static String getPackageVersion() {
6775
return VeeamControlService.class.getPackage().getImplementationVersion();
6876
}

plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlServiceImpl.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.cloudstack.veeam;
1919

20+
import java.nio.charset.StandardCharsets;
2021
import java.util.Collections;
2122
import java.util.List;
2223
import java.util.stream.Collectors;
@@ -31,6 +32,8 @@
3132

3233
import com.cloud.cluster.ManagementServerHostVO;
3334
import com.cloud.cluster.dao.ManagementServerHostDao;
35+
import com.cloud.user.AccountService;
36+
import com.cloud.utils.UuidUtils;
3437
import com.cloud.utils.component.ManagerBase;
3538
import com.cloud.utils.net.NetUtils;
3639

@@ -39,6 +42,9 @@ public class VeeamControlServiceImpl extends ManagerBase implements VeeamControl
3942
@Inject
4043
ManagementServerHostDao managementServerHostDao;
4144

45+
@Inject
46+
AccountService accountService;
47+
4248
private List<RouteHandler> routeHandlers;
4349
private VeeamControlServer veeamControlServer;
4450
private SingleCache<List<String>> allowedClientCidrsCache;
@@ -83,12 +89,23 @@ public List<String> getAllowedClientCidrs() {
8389
return allowedClientCidrsCache.get();
8490
}
8591

92+
@Override
93+
public String getInstanceId() {
94+
return accountService.getSystemAccount().getUuid();
95+
}
96+
8697
@Override
8798
public boolean validateCredentials(String username, String password) {
8899
return DataUtil.constantTimeEquals(Username.value(), username) &&
89100
DataUtil.constantTimeEquals(Password.value(), password);
90101
}
91102

103+
@Override
104+
public String getHmacSecret() {
105+
String base = getInstanceId() + ":" + Port.value() + ":" + Username.value() + Password.value();
106+
return UuidUtils.nameUUIDFromBytes(base.getBytes(StandardCharsets.UTF_8)).toString();
107+
}
108+
92109
@Override
93110
public boolean start() {
94111
allowedClientCidrsCache = new SingleCache<>(30, this::getAllowedClientCidrsInternal);
@@ -132,7 +149,8 @@ public ConfigKey<?>[] getConfigKeys() {
132149
Password,
133150
ServiceAccountId,
134151
InstanceRestoreAssignOwner,
135-
AllowedClientCidrs
152+
AllowedClientCidrs,
153+
DeveloperLogs
136154
};
137155
}
138156
}

plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/api/ApiRouteHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.apache.cloudstack.veeam.api.dto.Version;
4040
import org.apache.cloudstack.veeam.utils.Negotiation;
4141

42-
import com.cloud.user.AccountService;
4342
import com.cloud.utils.component.ManagerBase;
4443

4544
public class ApiRouteHandler extends ManagerBase implements RouteHandler {
@@ -49,7 +48,7 @@ public class ApiRouteHandler extends ManagerBase implements RouteHandler {
4948
ServerAdapter serverAdapter;
5049

5150
@Inject
52-
AccountService accountService;
51+
VeeamControlService veeamControlService;
5352

5453
@Override
5554
public boolean canHandle(String method, String path) {
@@ -99,7 +98,7 @@ protected Api createApiObject(String basePath) {
9998

10099
/* ---------------- Product info ---------------- */
101100
ProductInfo productInfo = new ProductInfo();
102-
productInfo.setInstanceId(accountService.getSystemAccount().getUuid());
101+
productInfo.setInstanceId(veeamControlService.getInstanceId());
103102
productInfo.name = VeeamControlService.PLUGIN_NAME;
104103

105104
productInfo.version = Version.fromPackageAndCSVersion(true);

plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/api/converter/AsyncJobJoinVOToJobConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static List<Job> toJobList(List<AsyncJobJoinVO> vos) {
7171

7272
protected static void fillAction(final ResourceAction action, final AsyncJobJoinVO vo) {
7373
final String basePath = VeeamControlService.ContextPath.value();
74-
action.setJob(Ref.of(basePath + JobsRouteHandler.BASE_ROUTE + vo.getUuid(), vo.getUuid()));
74+
action.setJob(Ref.of(basePath + JobsRouteHandler.BASE_ROUTE + "/" + vo.getUuid(), vo.getUuid()));
7575
action.setStatus("complete");
7676
}
7777

plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/api/converter/DataCenterJoinVOToDataCenterConverter.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
package org.apache.cloudstack.veeam.api.converter;
1919

20-
import java.util.Arrays;
2120
import java.util.List;
2221
import java.util.stream.Collectors;
22+
import java.util.stream.Stream;
2323

2424
import org.apache.cloudstack.veeam.VeeamControlService;
2525
import org.apache.cloudstack.veeam.api.DataCentersRouteHandler;
@@ -50,7 +50,6 @@ public static DataCenter toDataCenter(final DataCenterJoinVO zone) {
5050
dc.setStatus(Grouping.AllocationState.Enabled.equals(zone.getAllocationState()) ? "up" : "down");
5151
dc.setLocal("false");
5252
dc.setQuotaMode("disabled");
53-
dc.setStorageFormat("v5");
5453

5554
// ---- Versions ----
5655
final Version ver = Version.fromPackageAndCSVersion(false);
@@ -61,11 +60,10 @@ public static DataCenter toDataCenter(final DataCenterJoinVO zone) {
6160
dc.setMacPool(Ref.of(basePath + "/macpools/default", "default"));
6261

6362
// ---- Related links ----
64-
dc.link = Arrays.asList(
65-
Link.of(href + "/clusters", "clusters"),
66-
Link.of(href + "/networks", "networks"),
67-
Link.of(href + "/storagedomains", "storagedomains")
68-
);
63+
64+
dc.link = Stream.of("cluster", "networks", "storagedomains")
65+
.map(rel -> Link.of(rel, href + "/" + rel))
66+
.collect(Collectors.toList());
6967

7068
return dc;
7169
}

plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/api/dto/ReportedDevice.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ReportedDevice extends BaseDto {
2121
private String comment;
2222
private String description;
2323
private NamedList<Ip> ips;
24-
private Mac Mac;
24+
private Mac mac;
2525
private String name;
2626
private String type;
2727
private Vm vm;
@@ -51,11 +51,11 @@ public void setIps(NamedList<Ip> ips) {
5151
}
5252

5353
public Mac getMac() {
54-
return Mac;
54+
return mac;
5555
}
5656

5757
public void setMac(Mac mac) {
58-
Mac = mac;
58+
this.mac = mac;
5959
}
6060

6161
public String getName() {

0 commit comments

Comments
 (0)