Skip to content

Commit b29ec2b

Browse files
committed
Merge remote-tracking branch 'apache/4.19'
2 parents 68a3e9e + 9fd410b commit b29ec2b

File tree

36 files changed

+1488
-40
lines changed

36 files changed

+1488
-40
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- uses: actions/checkout@v4
3434

3535
- name: Set up JDK 11
36-
uses: actions/setup-java@v3
36+
uses: actions/setup-java@v4
3737
with:
3838
java-version: '11'
3939
distribution: 'adopt'

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ jobs:
211211
fetch-depth: 0
212212

213213
- name: Set up JDK
214-
uses: actions/setup-java@v3
214+
uses: actions/setup-java@v4
215215
with:
216216
java-version: '11'
217217
distribution: 'adopt'

.github/workflows/codecov.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
fetch-depth: 0
3838

3939
- name: Set up JDK11
40-
uses: actions/setup-java@v3
40+
uses: actions/setup-java@v4
4141
with:
4242
distribution: 'temurin'
4343
java-version: '11'

.github/workflows/main-sonar-check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
fetch-depth: 0
3838

3939
- name: Set up JDK11
40-
uses: actions/setup-java@v3
40+
uses: actions/setup-java@v4
4141
with:
4242
distribution: 'temurin'
4343
java-version: '11'

.github/workflows/rat.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
steps:
3333
- uses: actions/checkout@v4
3434
- name: Set up JDK 11
35-
uses: actions/setup-java@v3
35+
uses: actions/setup-java@v4
3636
with:
3737
java-version: '11'
3838
distribution: 'adopt'

.github/workflows/sonar-check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
fetch-depth: 0
4040

4141
- name: Set up JDK11
42-
uses: actions/setup-java@v3
42+
uses: actions/setup-java@v4
4343
with:
4444
distribution: 'temurin'
4545
java-version: '11'

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

+1
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ public class EventTypes {
303303
public static final String EVENT_VOLUME_CREATE = "VOLUME.CREATE";
304304
public static final String EVENT_VOLUME_DELETE = "VOLUME.DELETE";
305305
public static final String EVENT_VOLUME_ATTACH = "VOLUME.ATTACH";
306+
public static final String EVENT_VOLUME_CHECK = "VOLUME.CHECK";
306307
public static final String EVENT_VOLUME_DETACH = "VOLUME.DETACH";
307308
public static final String EVENT_VOLUME_EXTRACT = "VOLUME.EXTRACT";
308309
public static final String EVENT_VOLUME_UPLOAD = "VOLUME.UPLOAD";

api/src/main/java/com/cloud/storage/VolumeApiService.java

+4
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
import java.util.List;
2323
import java.util.Map;
2424

25+
import com.cloud.utils.Pair;
2526
import org.apache.cloudstack.api.command.user.volume.AssignVolumeCmd;
2627
import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
2728
import org.apache.cloudstack.api.command.user.volume.ChangeOfferingForVolumeCmd;
29+
import org.apache.cloudstack.api.command.user.volume.CheckAndRepairVolumeCmd;
2830
import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
2931
import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd;
3032
import org.apache.cloudstack.api.command.user.volume.ExtractVolumeCmd;
@@ -178,4 +180,6 @@ Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account acc
178180
void publishVolumeCreationUsageEvent(Volume volume);
179181

180182
boolean stateTransitTo(Volume vol, Volume.Event event) throws NoTransitionException;
183+
184+
Pair<String, String> checkAndRepairVolume(CheckAndRepairVolumeCmd cmd) throws ResourceAllocationException;
181185
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ public class ApiConstants {
380380
public static final String RECEIVED_BYTES = "receivedbytes";
381381
public static final String RECONNECT = "reconnect";
382382
public static final String RECOVER = "recover";
383+
public static final String REPAIR = "repair";
383384
public static final String REQUIRES_HVM = "requireshvm";
384385
public static final String RESOURCE_COUNT = "resourcecount";
385386
public static final String RESOURCE_NAME = "resourcename";
@@ -506,6 +507,9 @@ public class ApiConstants {
506507
public static final String IS_VOLATILE = "isvolatile";
507508
public static final String VOLUME_ID = "volumeid";
508509
public static final String VOLUMES = "volumes";
510+
public static final String VOLUME_CHECK_RESULT = "volumecheckresult";
511+
public static final String VOLUME_REPAIR_RESULT = "volumerepairresult";
512+
509513
public static final String ZONE = "zone";
510514
public static final String ZONE_ID = "zoneid";
511515
public static final String ZONE_NAME = "zonename";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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 org.apache.cloudstack.api.command.user.volume;
18+
19+
import com.cloud.event.EventTypes;
20+
import com.cloud.exception.InvalidParameterValueException;
21+
import org.apache.cloudstack.acl.RoleType;
22+
import org.apache.cloudstack.api.APICommand;
23+
import org.apache.cloudstack.api.ApiCommandResourceType;
24+
import org.apache.cloudstack.api.ApiConstants;
25+
import org.apache.cloudstack.api.ApiErrorCode;
26+
import org.apache.cloudstack.api.BaseAsyncCmd;
27+
import org.apache.cloudstack.api.Parameter;
28+
import org.apache.cloudstack.api.ResponseObject.ResponseView;
29+
import org.apache.cloudstack.api.ServerApiException;
30+
import org.apache.cloudstack.api.response.VolumeResponse;
31+
import org.apache.cloudstack.context.CallContext;
32+
import org.apache.log4j.Logger;
33+
34+
import com.cloud.exception.ResourceAllocationException;
35+
import com.cloud.storage.Volume;
36+
import com.cloud.user.Account;
37+
import com.cloud.utils.Pair;
38+
import com.cloud.utils.StringUtils;
39+
40+
import java.util.Arrays;
41+
42+
@APICommand(name = "checkVolume", description = "Check the volume for any errors or leaks and also repairs when repair parameter is passed, this is currently supported for KVM only", responseObject = VolumeResponse.class, entityType = {Volume.class},
43+
since = "4.19.1",
44+
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
45+
public class CheckAndRepairVolumeCmd extends BaseAsyncCmd {
46+
public static final Logger s_logger = Logger.getLogger(CheckAndRepairVolumeCmd.class.getName());
47+
48+
private static final String s_name = "checkandrepairvolumeresponse";
49+
50+
/////////////////////////////////////////////////////
51+
//////////////// API parameters /////////////////////
52+
/////////////////////////////////////////////////////
53+
54+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = VolumeResponse.class, required = true, description = "The ID of the volume")
55+
private Long id;
56+
57+
@Parameter(name = ApiConstants.REPAIR, type = CommandType.STRING, required = false, description = "parameter to repair the volume, leaks or all are the possible values")
58+
private String repair;
59+
60+
/////////////////////////////////////////////////////
61+
/////////////////// Accessors ///////////////////////
62+
/////////////////////////////////////////////////////
63+
64+
public enum RepairValues {
65+
LEAKS, ALL
66+
}
67+
68+
public Long getId() {
69+
return id;
70+
}
71+
72+
public String getRepair() {
73+
if (org.apache.commons.lang3.StringUtils.isNotEmpty(repair)) {
74+
RepairValues repairType = Enum.valueOf(RepairValues.class, repair.toUpperCase());
75+
if (repairType == null) {
76+
throw new InvalidParameterValueException(String.format("Repair parameter can only take the following values: %s" + Arrays.toString(RepairValues.values())));
77+
}
78+
return repair.toLowerCase();
79+
}
80+
return null;
81+
}
82+
83+
/////////////////////////////////////////////////////
84+
/////////////// API Implementation///////////////////
85+
/////////////////////////////////////////////////////
86+
87+
@Override
88+
public String getCommandName() {
89+
return s_name;
90+
}
91+
92+
@Override
93+
public long getEntityOwnerId() {
94+
Volume volume = _entityMgr.findById(Volume.class, getId());
95+
if (volume != null) {
96+
return volume.getAccountId();
97+
}
98+
99+
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
100+
}
101+
102+
@Override
103+
public String getEventType() {
104+
return EventTypes.EVENT_VOLUME_CHECK;
105+
}
106+
107+
@Override
108+
public String getEventDescription() {
109+
return String.format("check and repair operation on volume: %s", this._uuidMgr.getUuid(Volume.class, getId()));
110+
}
111+
112+
@Override
113+
public Long getApiResourceId() {
114+
return id;
115+
}
116+
117+
@Override
118+
public ApiCommandResourceType getApiResourceType() {
119+
return ApiCommandResourceType.Volume;
120+
}
121+
122+
@Override
123+
public void execute() throws ResourceAllocationException {
124+
CallContext.current().setEventDetails("Volume Id: " + getId());
125+
Pair<String, String> result = _volumeService.checkAndRepairVolume(this);
126+
Volume volume = _responseGenerator.findVolumeById(getId());
127+
if (result != null) {
128+
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
129+
response.setVolumeCheckResult(StringUtils.parseJsonToMap(result.first()));
130+
if (getRepair() != null) {
131+
response.setVolumeRepairResult(StringUtils.parseJsonToMap(result.second()));
132+
}
133+
response.setResponseName(getCommandName());
134+
setResponseObject(response);
135+
} else {
136+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to check volume and repair");
137+
}
138+
}
139+
}

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

+25
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.Date;
2020
import java.util.LinkedHashSet;
21+
import java.util.Map;
2122
import java.util.Set;
2223

2324
import org.apache.cloudstack.acl.RoleType;
@@ -288,6 +289,14 @@ public class VolumeResponse extends BaseResponseWithTagInformation implements Co
288289
@Param(description = "volume uuid that is given by virtualisation provider (only for VMware)")
289290
private String externalUuid;
290291

292+
@SerializedName(ApiConstants.VOLUME_CHECK_RESULT)
293+
@Param(description = "details for the volume check result, they may vary for different hypervisors, since = 4.19.1")
294+
private Map<String, String> volumeCheckResult;
295+
296+
@SerializedName(ApiConstants.VOLUME_REPAIR_RESULT)
297+
@Param(description = "details for the volume repair result, they may vary for different hypervisors, since = 4.19.1")
298+
private Map<String, String> volumeRepairResult;
299+
291300
public String getPath() {
292301
return path;
293302
}
@@ -817,4 +826,20 @@ public String getExternalUuid() {
817826
public void setExternalUuid(String externalUuid) {
818827
this.externalUuid = externalUuid;
819828
}
829+
830+
public Map<String, String> getVolumeCheckResult() {
831+
return volumeCheckResult;
832+
}
833+
834+
public void setVolumeCheckResult(Map<String, String> volumeCheckResult) {
835+
this.volumeCheckResult = volumeCheckResult;
836+
}
837+
838+
public Map<String, String> getVolumeRepairResult() {
839+
return volumeRepairResult;
840+
}
841+
842+
public void setVolumeRepairResult(Map<String, String> volumeRepairResult) {
843+
this.volumeRepairResult = volumeRepairResult;
844+
}
820845
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.agent.api.storage;
21+
22+
import com.cloud.agent.api.Answer;
23+
24+
public class CheckAndRepairVolumeAnswer extends Answer {
25+
private String volumeCheckExecutionResult;
26+
private String volumeRepairExecutionResult;
27+
28+
protected CheckAndRepairVolumeAnswer() {
29+
super();
30+
}
31+
32+
public CheckAndRepairVolumeAnswer(CheckAndRepairVolumeCommand cmd, boolean result, String details, String volumeCheckExecutionResult, String volumeRepairedExecutionResult) {
33+
super(cmd, result, details);
34+
this.volumeCheckExecutionResult = volumeCheckExecutionResult;
35+
this.volumeRepairExecutionResult = volumeRepairedExecutionResult;
36+
}
37+
38+
public CheckAndRepairVolumeAnswer(CheckAndRepairVolumeCommand cmd, boolean result, String details) {
39+
super(cmd, result, details);
40+
}
41+
42+
public String getVolumeCheckExecutionResult() {
43+
return volumeCheckExecutionResult;
44+
}
45+
46+
public String getVolumeRepairExecutionResult() {
47+
return volumeRepairExecutionResult;
48+
}
49+
50+
public void setVolumeCheckExecutionResult(String volumeCheckExecutionResult) {
51+
this.volumeCheckExecutionResult = volumeCheckExecutionResult;
52+
}
53+
54+
public void setVolumeRepairExecutionResult(String volumeRepairExecutionResult) {
55+
this.volumeRepairExecutionResult = volumeRepairExecutionResult;
56+
}
57+
}

0 commit comments

Comments
 (0)