Skip to content

Commit 5074a21

Browse files
committed
Merge remote-tracking branch 'upstream/main' into format-logger-apiserver
2 parents 27aef97 + f958896 commit 5074a21

File tree

311 files changed

+2815
-1831
lines changed

Some content is hidden

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

311 files changed

+2815
-1831
lines changed

agent/src/main/java/com/cloud/agent/Agent.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -453,22 +453,30 @@ private void scheduleCertificateRenewalTask() {
453453
certExecutor.schedule(new PostCertificateRenewalTask(this), 5, TimeUnit.SECONDS);
454454
}
455455

456-
private void scheduleHostLBCheckerTask(final long checkInterval) {
456+
private void scheduleHostLBCheckerTask(final String lbAlgorithm, final long checkInterval) {
457457
String name = "HostLBCheckerTask";
458458
if (hostLbCheckExecutor != null && !hostLbCheckExecutor.isShutdown()) {
459+
logger.info("Shutting down the preferred host checker task {}", name);
459460
hostLbCheckExecutor.shutdown();
460461
try {
461462
if (!hostLbCheckExecutor.awaitTermination(1, TimeUnit.SECONDS)) {
462463
hostLbCheckExecutor.shutdownNow();
463464
}
464465
} catch (InterruptedException e) {
465-
logger.debug("Forcing {} shutdown as it did not shutdown in the desired time due to: {}",
466+
logger.debug("Forcing the preferred host checker task {} shutdown as it did not shutdown in the desired time due to: {}",
466467
name, e.getMessage());
467468
hostLbCheckExecutor.shutdownNow();
468469
}
469470
}
470471
if (checkInterval > 0L) {
471-
logger.info("Scheduling preferred host task with host.lb.interval={}ms", checkInterval);
472+
if ("shuffle".equalsIgnoreCase(lbAlgorithm)) {
473+
logger.info("Scheduling the preferred host checker task to trigger once (to apply lb algorithm '{}') after host.lb.interval={} ms", lbAlgorithm, checkInterval);
474+
hostLbCheckExecutor = Executors.newSingleThreadScheduledExecutor((new NamedThreadFactory(name)));
475+
hostLbCheckExecutor.schedule(new PreferredHostCheckerTask(), checkInterval, TimeUnit.MILLISECONDS);
476+
return;
477+
}
478+
479+
logger.info("Scheduling a recurring preferred host checker task with lb algorithm '{}' and host.lb.interval={} ms", lbAlgorithm, checkInterval);
472480
hostLbCheckExecutor = Executors.newSingleThreadScheduledExecutor((new NamedThreadFactory(name)));
473481
hostLbCheckExecutor.scheduleAtFixedRate(new PreferredHostCheckerTask(), checkInterval, checkInterval,
474482
TimeUnit.MILLISECONDS);
@@ -928,7 +936,7 @@ private Answer setupAgentCertificate(final SetupCertificateCommand cmd) {
928936
return new SetupCertificateAnswer(true);
929937
}
930938

931-
private void processManagementServerList(final List<String> msList, final List<String> avoidMsList, final String lbAlgorithm, final Long lbCheckInterval) {
939+
private void processManagementServerList(final List<String> msList, final List<String> avoidMsList, final String lbAlgorithm, final Long lbCheckInterval, final boolean triggerHostLB) {
932940
if (CollectionUtils.isNotEmpty(msList) && StringUtils.isNotEmpty(lbAlgorithm)) {
933941
try {
934942
final String newMSHosts = String.format("%s%s%s", com.cloud.utils.StringUtils.toCSVList(msList), IAgentShell.hostLbAlgorithmSeparator, lbAlgorithm);
@@ -941,22 +949,24 @@ private void processManagementServerList(final List<String> msList, final List<S
941949
}
942950
}
943951
shell.setAvoidHosts(avoidMsList);
944-
if ("shuffle".equals(lbAlgorithm)) {
945-
scheduleHostLBCheckerTask(0);
946-
} else {
947-
scheduleHostLBCheckerTask(shell.getLbCheckerInterval(lbCheckInterval));
952+
if (triggerHostLB) {
953+
logger.info("Triggering the preferred host checker task now");
954+
ScheduledExecutorService hostLbExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("HostLB-Executor"));
955+
hostLbExecutor.schedule(new PreferredHostCheckerTask(), 0, TimeUnit.MILLISECONDS);
956+
hostLbExecutor.shutdown();
948957
}
958+
scheduleHostLBCheckerTask(lbAlgorithm, shell.getLbCheckerInterval(lbCheckInterval));
949959
}
950960

951961
private Answer setupManagementServerList(final SetupMSListCommand cmd) {
952-
processManagementServerList(cmd.getMsList(), cmd.getAvoidMsList(), cmd.getLbAlgorithm(), cmd.getLbCheckInterval());
962+
processManagementServerList(cmd.getMsList(), cmd.getAvoidMsList(), cmd.getLbAlgorithm(), cmd.getLbCheckInterval(), cmd.getTriggerHostLb());
953963
return new SetupMSListAnswer(true);
954964
}
955965

956966
private Answer migrateAgentToOtherMS(final MigrateAgentConnectionCommand cmd) {
957967
try {
958968
if (CollectionUtils.isNotEmpty(cmd.getMsList())) {
959-
processManagementServerList(cmd.getMsList(), cmd.getAvoidMsList(), cmd.getLbAlgorithm(), cmd.getLbCheckInterval());
969+
processManagementServerList(cmd.getMsList(), cmd.getAvoidMsList(), cmd.getLbAlgorithm(), cmd.getLbCheckInterval(), false);
960970
}
961971
Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("MigrateAgentConnection-Job")).schedule(() -> {
962972
migrateAgentConnection(cmd.getAvoidMsList());
@@ -1046,7 +1056,7 @@ public void processReadyCommand(final Command cmd) {
10461056
}
10471057

10481058
verifyAgentArch(ready.getArch());
1049-
processManagementServerList(ready.getMsHostList(), ready.getAvoidMsHostList(), ready.getLbAlgorithm(), ready.getLbCheckInterval());
1059+
processManagementServerList(ready.getMsHostList(), ready.getAvoidMsHostList(), ready.getLbAlgorithm(), ready.getLbCheckInterval(), false);
10501060

10511061
logger.info("Ready command is processed for agent [id: {}, uuid: {}, name: {}]", getId(), getUuid(), getName());
10521062
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,9 @@ public class EventTypes {
801801
// Resource Limit
802802
public static final String EVENT_RESOURCE_LIMIT_UPDATE = "RESOURCE.LIMIT.UPDATE";
803803

804+
// Management Server
805+
public static final String EVENT_MANAGEMENT_SERVER_REMOVE = "MANAGEMENT.SERVER.REMOVE";
806+
804807
public static final String VM_LEASE_EXPIRED = "VM.LEASE.EXPIRED";
805808
public static final String VM_LEASE_DISABLED = "VM.LEASE.DISABLED";
806809
public static final String VM_LEASE_CANCELLED = "VM.LEASE.CANCELLED";
@@ -1301,6 +1304,9 @@ public class EventTypes {
13011304
entityEventDetails.put(EVENT_SHAREDFS_EXPUNGE, SharedFS.class);
13021305
entityEventDetails.put(EVENT_SHAREDFS_RECOVER, SharedFS.class);
13031306

1307+
// Management Server
1308+
entityEventDetails.put(EVENT_MANAGEMENT_SERVER_REMOVE, "ManagementServer");
1309+
13041310
// VM Lease
13051311
entityEventDetails.put(VM_LEASE_EXPIRED, VirtualMachine.class);
13061312
entityEventDetails.put(VM_LEASE_EXPIRING, VirtualMachine.class);

api/src/main/java/com/cloud/exception/OperationTimedoutException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class OperationTimedoutException extends CloudException {
4040
boolean _isActive;
4141

4242
public OperationTimedoutException(Command[] cmds, long agentId, long seqId, int time, boolean isActive) {
43-
super("Commands " + seqId + " to Host " + agentId + " timed out after " + time);
43+
super("Commands " + seqId + " to Host " + agentId + " timed out after " + time + " secs");
4444
_agentId = agentId;
4545
_seqId = seqId;
4646
_time = time;

api/src/main/java/com/cloud/host/Host.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ public static String[] toStrings(Host.Type... types) {
5353
return strs;
5454
}
5555
}
56-
public static final String HOST_UEFI_ENABLE = "host.uefi.enable";
57-
public static final String HOST_VOLUME_ENCRYPTION = "host.volume.encryption";
58-
public static final String HOST_INSTANCE_CONVERSION = "host.instance.conversion";
56+
57+
String HOST_UEFI_ENABLE = "host.uefi.enable";
58+
String HOST_VOLUME_ENCRYPTION = "host.volume.encryption";
59+
String HOST_INSTANCE_CONVERSION = "host.instance.conversion";
60+
String HOST_OVFTOOL_VERSION = "host.ovftool.version";
61+
String HOST_VIRTV2V_VERSION = "host.virtv2v.version";
5962

6063
/**
6164
* @return name of the machine.

api/src/main/java/com/cloud/resource/ResourceState.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public static Event toEvent(String e) {
7676
}
7777
}
7878

79+
public static List<ResourceState> s_maintenanceStates = List.of(ResourceState.Maintenance,
80+
ResourceState.ErrorInMaintenance, ResourceState.PrepareForMaintenance,
81+
ResourceState.ErrorInPrepareForMaintenance);
82+
7983
public ResourceState getNextState(Event a) {
8084
return s_fsm.getNextState(this, a);
8185
}
@@ -98,8 +102,7 @@ public static String[] toString(ResourceState... states) {
98102
}
99103

100104
public static boolean isMaintenanceState(ResourceState state) {
101-
return Arrays.asList(ResourceState.Maintenance, ResourceState.ErrorInMaintenance,
102-
ResourceState.PrepareForMaintenance, ResourceState.ErrorInPrepareForMaintenance).contains(state);
105+
return s_maintenanceStates.contains(state);
103106
}
104107

105108
public static boolean canAttemptMaintenance(ResourceState state) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.cloudstack.api.command.admin.guest.UpdateGuestOsMappingCmd;
3939
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
4040
import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
41+
import org.apache.cloudstack.api.command.admin.management.RemoveManagementServerCmd;
4142
import org.apache.cloudstack.api.command.admin.pod.ListPodsByCmd;
4243
import org.apache.cloudstack.api.command.admin.resource.ArchiveAlertsCmd;
4344
import org.apache.cloudstack.api.command.admin.resource.DeleteAlertsCmd;
@@ -506,4 +507,6 @@ VirtualMachine upgradeSystemVM(ScaleSystemVMCmd cmd) throws ResourceUnavailableE
506507

507508
Pair<Boolean, String> patchSystemVM(PatchSystemVMCmd cmd);
508509

510+
boolean removeManagementServer(RemoveManagementServerCmd cmd);
511+
509512
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ public class ApiConstants {
441441
public static final String PUBLIC_END_PORT = "publicendport";
442442
public static final String PUBLIC_ZONE = "publiczone";
443443
public static final String PURGE_RESOURCES = "purgeresources";
444+
public static final String REBALANCE = "rebalance";
444445
public static final String RECEIVED_BYTES = "receivedbytes";
445446
public static final String RECONNECT = "reconnect";
446447
public static final String RECOVER = "recover";

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
public enum ApiErrorCode {
2424

25+
BAD_REQUEST(400),
2526
UNAUTHORIZED(401),
2627
UNAUTHORIZED2FA(511),
2728
METHOD_NOT_ALLOWED(405),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ public ResponseObject loginUser(HttpSession session, String username, String pas
4848
boolean forgotPassword(UserAccount userAccount, Domain domain);
4949

5050
boolean resetPassword(UserAccount userAccount, String token, String password);
51+
52+
boolean isPostRequestsAndTimestampsEnforced();
5153
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.admin.management;
18+
19+
import com.cloud.event.EventTypes;
20+
import org.apache.cloudstack.acl.RoleType;
21+
import org.apache.cloudstack.api.APICommand;
22+
import org.apache.cloudstack.api.Parameter;
23+
import org.apache.cloudstack.api.ServerApiException;
24+
import org.apache.cloudstack.api.ApiConstants;
25+
import org.apache.cloudstack.api.ApiErrorCode;
26+
import org.apache.cloudstack.api.BaseCmd;
27+
import org.apache.cloudstack.api.response.ManagementServerResponse;
28+
import org.apache.cloudstack.api.response.SuccessResponse;
29+
import org.apache.cloudstack.context.CallContext;
30+
31+
@APICommand(name = "removeManagementServer", description = "Removes a Management Server.", responseObject = SuccessResponse.class,
32+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = RoleType.Admin)
33+
public class RemoveManagementServerCmd extends BaseCmd {
34+
35+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = ManagementServerResponse.class, required = true, description = "the ID of the Management Server")
36+
private Long id;
37+
38+
public Long getId() {
39+
return id;
40+
}
41+
42+
@Override
43+
public void execute() {
44+
boolean result = _mgr.removeManagementServer(this);
45+
if (result) {
46+
SuccessResponse response = new SuccessResponse(getCommandName());
47+
this.setResponseObject(response);
48+
} else {
49+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove Management Server.");
50+
}
51+
}
52+
53+
@Override
54+
public long getEntityOwnerId() {
55+
return CallContext.current().getCallingAccountId();
56+
}
57+
58+
public String getEventType() {
59+
return EventTypes.EVENT_MANAGEMENT_SERVER_REMOVE;
60+
}
61+
}

0 commit comments

Comments
 (0)