Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: Reconcile commands (CopyCommand, MigrateCommand, MigrateVolumeCommand) #10514

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions agent/src/main/java/com/cloud/agent/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,9 @@
}
commandsInProgress.incrementAndGet();
try {
if (cmd.isReconcile()) {
cmd.setRequestSequence(request.getSequence());

Check warning on line 801 in agent/src/main/java/com/cloud/agent/Agent.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L801 was not covered by tests
}
answer = serverResource.executeRequest(cmd);
} finally {
commandsInProgress.decrementAndGet();
Expand Down Expand Up @@ -1003,9 +1006,13 @@
for (final IAgentControlListener listener : controlListeners) {
listener.processControlResponse(response, (AgentControlAnswer)answer);
}
} else if (answer instanceof PingAnswer && (((PingAnswer) answer).isSendStartup()) && reconnectAllowed) {
logger.info("Management server requested startup command to reinitialize the agent");
sendStartup(link);
} else if (answer instanceof PingAnswer) {
if (((PingAnswer) answer).isSendStartup() && reconnectAllowed) {
logger.info("Management server requested startup command to reinitialize the agent");
sendStartup(link);

Check warning on line 1012 in agent/src/main/java/com/cloud/agent/Agent.java

View check run for this annotation

Codecov / codecov/patch

agent/src/main/java/com/cloud/agent/Agent.java#L1011-L1012

Added lines #L1011 - L1012 were not covered by tests
} else {
serverResource.processPingAnswer((PingAnswer) answer);

Check warning on line 1014 in agent/src/main/java/com/cloud/agent/Agent.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1014 was not covered by tests
}
} else {
updateLastPingResponseTime();
}
Expand Down Expand Up @@ -1073,6 +1080,9 @@
Answer answer = null;
commandsInProgress.incrementAndGet();
try {
if (command.isReconcile()) {
command.setRequestSequence(req.getSequence());

Check warning on line 1084 in agent/src/main/java/com/cloud/agent/Agent.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1084 was not covered by tests
}
answer = serverResource.executeRequest(command);
} finally {
commandsInProgress.decrementAndGet();
Expand Down
34 changes: 34 additions & 0 deletions api/src/main/java/com/cloud/agent/api/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,31 @@
Continue, Stop
}

public enum State {
CREATED, // Command is created by management server
STARTED, // Command is started by agent
PROCESSING, // Processing by agent
PROCESSING_IN_BACKEND, // Processing in backend by agent
COMPLETED, // Operation succeeds by agent or management server
FAILED, // Operation fails by agent
RECONCILE_RETRY, // Ready for retry of reconciliation
RECONCILING, // Being reconciled by management server
RECONCILED, // Reconciled by management server
RECONCILE_SKIPPED, // Skip the reconciliation as the resource state is inconsistent with the command
RECONCILE_FAILED, // Fail to reconcile by management server
TIMED_OUT, // Timed out on management server or agent
INTERRUPTED, // Interrupted by management server or agent (for example agent is restarted),
DANGLED_IN_BACKEND // Backend process which cannot be processed normally (for example agent is restarted)
}

public static final String HYPERVISOR_TYPE = "hypervisorType";

// allow command to carry over hypervisor or other environment related context info
@LogLevel(Log4jLevel.Trace)
protected Map<String, String> contextMap = new HashMap<String, String>();
private int wait; //in second
private boolean bypassHostMaintenance = false;
private transient long requestSequence = 0L;

protected Command() {
this.wait = 0;
Expand Down Expand Up @@ -82,6 +100,10 @@
return contextMap.get(name);
}

public Map<String, String> getContextMap() {
return contextMap;
}

Check warning on line 105 in api/src/main/java/com/cloud/agent/api/Command.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/com/cloud/agent/api/Command.java#L103-L105

Added lines #L103 - L105 were not covered by tests

public boolean allowCaching() {
return true;
}
Expand All @@ -94,6 +116,18 @@
this.bypassHostMaintenance = bypassHostMaintenance;
}

public boolean isReconcile() {

Check warning on line 119 in api/src/main/java/com/cloud/agent/api/Command.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/com/cloud/agent/api/Command.java#L119

Added line #L119 was not covered by tests
return false;
}

Check warning on line 121 in api/src/main/java/com/cloud/agent/api/Command.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/com/cloud/agent/api/Command.java#L121

Added line #L121 was not covered by tests

public long getRequestSequence() {

Check warning on line 123 in api/src/main/java/com/cloud/agent/api/Command.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/com/cloud/agent/api/Command.java#L123

Added line #L123 was not covered by tests
return requestSequence;
}

Check warning on line 125 in api/src/main/java/com/cloud/agent/api/Command.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/com/cloud/agent/api/Command.java#L125

Added line #L125 was not covered by tests

public void setRequestSequence(long requestSequence) {

Check warning on line 127 in api/src/main/java/com/cloud/agent/api/Command.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/com/cloud/agent/api/Command.java#L127

Added line #L127 was not covered by tests
this.requestSequence = requestSequence;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
6 changes: 3 additions & 3 deletions api/src/main/java/com/cloud/agent/api/to/DiskTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class DiskTO {
private Long diskSeq;
private String path;
private Volume.Type type;
private Map<String, String> _details;
private Map<String, String> details;

public DiskTO() {

Expand Down Expand Up @@ -92,10 +92,10 @@ public void setType(Volume.Type type) {
}

public void setDetails(Map<String, String> details) {
_details = details;
this.details = details;
}

public Map<String, String> getDetails() {
return _details;
return details;
}
}
6 changes: 3 additions & 3 deletions api/src/main/java/com/cloud/agent/api/to/NetworkTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
protected TrafficType type;
protected URI broadcastUri;
protected URI isolationUri;
protected boolean isSecurityGroupEnabled;
protected boolean securityGroupEnabled;
protected String name;
protected String ip6address;
protected String ip6gateway;
Expand Down Expand Up @@ -112,7 +112,7 @@
}

public void setSecurityGroupEnabled(boolean enabled) {
this.isSecurityGroupEnabled = enabled;
this.securityGroupEnabled = enabled;
}

/**
Expand Down Expand Up @@ -221,7 +221,7 @@
}

public boolean isSecurityGroupEnabled() {
return this.isSecurityGroupEnabled;
return this.securityGroupEnabled;

Check warning on line 224 in api/src/main/java/com/cloud/agent/api/to/NetworkTO.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/com/cloud/agent/api/to/NetworkTO.java#L224

Added line #L224 was not covered by tests
}

public void setIp6Dns1(String ip6Dns1) {
Expand Down
8 changes: 8 additions & 0 deletions api/src/main/java/com/cloud/agent/api/to/NicTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@
this.nicUuid = uuid;
}

public String getNicUuid() {
return nicUuid;
}

Check warning on line 91 in api/src/main/java/com/cloud/agent/api/to/NicTO.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/com/cloud/agent/api/to/NicTO.java#L89-L91

Added lines #L89 - L91 were not covered by tests

public void setNicUuid(String nicUuid) {
this.nicUuid = nicUuid;
}

Check warning on line 95 in api/src/main/java/com/cloud/agent/api/to/NicTO.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/com/cloud/agent/api/to/NicTO.java#L93-L95

Added lines #L93 - L95 were not covered by tests

@Override
public String toString() {
return new StringBuilder("[Nic:").append(type).append("-").append(ip).append("-").append(broadcastUri).append("]").toString();
Expand Down
12 changes: 8 additions & 4 deletions api/src/main/java/com/cloud/agent/api/to/VirtualMachineTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
@LogLevel(LogLevel.Log4jLevel.Off)
String vncPassword;
String vncAddr;
Map<String, String> params;
Map<String, String> details;
String uuid;
String bootType;
String bootMode;
Expand Down Expand Up @@ -191,7 +191,11 @@
return maxSpeed;
}

public boolean getLimitCpuUse() {
public boolean isEnableHA() {
return enableHA;
}

Check warning on line 196 in api/src/main/java/com/cloud/agent/api/to/VirtualMachineTO.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/com/cloud/agent/api/to/VirtualMachineTO.java#L194-L196

Added lines #L194 - L196 were not covered by tests

public boolean isLimitCpuUse() {

Check warning on line 198 in api/src/main/java/com/cloud/agent/api/to/VirtualMachineTO.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/com/cloud/agent/api/to/VirtualMachineTO.java#L198

Added line #L198 was not covered by tests
return limitCpuUse;
}

Expand Down Expand Up @@ -289,11 +293,11 @@
}

public Map<String, String> getDetails() {
return params;
return details;
}

public void setDetails(Map<String, String> params) {
this.params = params;
this.details = params;
}

public String getUuid() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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 org.apache.cloudstack.command;


import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.hypervisor.Hypervisor;
import org.apache.cloudstack.framework.config.ConfigKey;

import java.util.Arrays;
import java.util.List;

public interface ReconcileCommandService {

ConfigKey<Boolean> ReconcileCommandsEnabled = new ConfigKey<>("Advanced", Boolean.class,

Check warning on line 30 in api/src/main/java/org/apache/cloudstack/command/ReconcileCommandService.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/command/ReconcileCommandService.java#L30

Added line #L30 was not covered by tests
"reconcile.commands.enabled", "true",
"Indicates whether the background task to reconcile the commands is enabled or not",
false);

ConfigKey<Integer> ReconcileCommandsInterval = new ConfigKey<>("Advanced", Integer.class,

Check warning on line 35 in api/src/main/java/org/apache/cloudstack/command/ReconcileCommandService.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/command/ReconcileCommandService.java#L35

Added line #L35 was not covered by tests
"reconcile.commands.interval", "60",
"Interval (in seconds) for the background task to reconcile the commands",
false);
ConfigKey<Integer> ReconcileCommandsMaxAttempts = new ConfigKey<>("Advanced", Integer.class,

Check warning on line 39 in api/src/main/java/org/apache/cloudstack/command/ReconcileCommandService.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/command/ReconcileCommandService.java#L39

Added line #L39 was not covered by tests
"reconcile.commands.max.attempts", "30",
"The maximum number of attempts to reconcile the commands",
true);

ConfigKey<Integer> ReconcileCommandsWorkers = new ConfigKey<>("Advanced", Integer.class,

Check warning on line 44 in api/src/main/java/org/apache/cloudstack/command/ReconcileCommandService.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/command/ReconcileCommandService.java#L44

Added line #L44 was not covered by tests
"reconcile.commands.workers", "100",
"The Number of worker threads to reconcile the commands",
false);

List<Hypervisor.HypervisorType> SupportedHypervisorTypes = Arrays.asList(Hypervisor.HypervisorType.KVM);

Check warning on line 49 in api/src/main/java/org/apache/cloudstack/command/ReconcileCommandService.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/command/ReconcileCommandService.java#L49

Added line #L49 was not covered by tests

void persistReconcileCommands(Long hostId, Long requestSequence, Command[] cmd);

boolean updateReconcileCommand(long requestSeq, Command command, Answer answer, Command.State newStateByManagement, Command.State newStateByAgent);

void processCommand(Command pingCommand, Answer pingAnswer);

void processAnswers(long requestSeq, Command[] commands, Answer[] answers);

void updateReconcileCommandToInterruptedByManagementServerId(long managementServerId);

void updateReconcileCommandToInterruptedByHostId(long hostId);
}
25 changes: 15 additions & 10 deletions core/src/main/java/com/cloud/agent/api/MigrateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@

public class MigrateCommand extends Command {
private String vmName;
private String destIp;
private String destinationIp;
private Map<String, MigrateDiskInfo> migrateStorage;
private boolean migrateStorageManaged;
private boolean migrateNonSharedInc;
private boolean autoConvergence;
private String hostGuid;
private boolean isWindows;
private VirtualMachineTO vmTO;
private boolean windows;
private VirtualMachineTO virtualMachine;
private boolean executeInSequence = false;
private List<MigrateDiskInfo> migrateDiskInfoList = new ArrayList<>();
private Map<String, DpdkTO> dpdkInterfaceMapping = new HashMap<>();
Expand Down Expand Up @@ -64,11 +64,11 @@
protected MigrateCommand() {
}

public MigrateCommand(String vmName, String destIp, boolean isWindows, VirtualMachineTO vmTO, boolean executeInSequence) {
public MigrateCommand(String vmName, String destinationIp, boolean windows, VirtualMachineTO virtualMachine, boolean executeInSequence) {
this.vmName = vmName;
this.destIp = destIp;
this.isWindows = isWindows;
this.vmTO = vmTO;
this.destinationIp = destinationIp;
this.windows = windows;
this.virtualMachine = virtualMachine;
this.executeInSequence = executeInSequence;
}

Expand Down Expand Up @@ -105,15 +105,15 @@
}

public boolean isWindows() {
return isWindows;
return windows;

Check warning on line 108 in core/src/main/java/com/cloud/agent/api/MigrateCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/MigrateCommand.java#L108

Added line #L108 was not covered by tests
}

public VirtualMachineTO getVirtualMachine() {
return vmTO;
return virtualMachine;
}

public String getDestinationIp() {
return destIp;
return destinationIp;
}

public String getVmName() {
Expand Down Expand Up @@ -233,4 +233,9 @@
this.isSourceDiskOnStorageFileSystem = isDiskOnFileSystemStorage;
}
}

@Override
public boolean isReconcile() {
return true;
}
}
17 changes: 17 additions & 0 deletions core/src/main/java/com/cloud/agent/api/PingAnswer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@

package com.cloud.agent.api;

import java.util.ArrayList;
import java.util.List;

public class PingAnswer extends Answer {
private PingCommand _command = null;

private boolean sendStartup = false;

private List<String> reconcileCommands = new ArrayList<>();

Check warning on line 30 in core/src/main/java/com/cloud/agent/api/PingAnswer.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/PingAnswer.java#L30

Added line #L30 was not covered by tests

protected PingAnswer() {
}

Expand All @@ -44,4 +49,16 @@
public void setSendStartup(boolean sendStartup) {
this.sendStartup = sendStartup;
}

public List<String> getReconcileCommands() {
return reconcileCommands;
}

Check warning on line 55 in core/src/main/java/com/cloud/agent/api/PingAnswer.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/PingAnswer.java#L53-L55

Added lines #L53 - L55 were not covered by tests

public void setReconcileCommands(List<String> reconcileCommands) {
this.reconcileCommands = reconcileCommands;
}

Check warning on line 59 in core/src/main/java/com/cloud/agent/api/PingAnswer.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/PingAnswer.java#L57-L59

Added lines #L57 - L59 were not covered by tests

public void addReconcileCommand(String reconcileCommand) {
this.reconcileCommands.add(reconcileCommand);
}

Check warning on line 63 in core/src/main/java/com/cloud/agent/api/PingAnswer.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/PingAnswer.java#L61-L63

Added lines #L61 - L63 were not covered by tests
}
11 changes: 11 additions & 0 deletions core/src/main/java/com/cloud/agent/api/PingCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
package com.cloud.agent.api;

import com.cloud.host.Host;
import org.apache.cloudstack.command.CommandInfo;

public class PingCommand extends Command {
Host.Type hostType;
long hostId;
boolean outOfBand;
@LogLevel(LogLevel.Log4jLevel.Trace)
private CommandInfo[] commandInfos = new CommandInfo[] {};

protected PingCommand() {
}
Expand Down Expand Up @@ -78,4 +81,12 @@
result = 31 * result + (int) (hostId ^ (hostId >>> 32));
return result;
}

public CommandInfo[] getCommandInfos() {
return commandInfos;
}

Check warning on line 87 in core/src/main/java/com/cloud/agent/api/PingCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/PingCommand.java#L85-L87

Added lines #L85 - L87 were not covered by tests

public void setCommandInfos(CommandInfo[] commandInfos) {
this.commandInfos = commandInfos;
}

Check warning on line 91 in core/src/main/java/com/cloud/agent/api/PingCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/PingCommand.java#L89-L91

Added lines #L89 - L91 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,9 @@
}

public String getChainInfo() { return chainInfo; }

@Override
public boolean isReconcile() {
return true;
}

Check warning on line 152 in core/src/main/java/com/cloud/agent/api/storage/MigrateVolumeCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/MigrateVolumeCommand.java#L150-L152

Added lines #L150 - L152 were not covered by tests
}
Loading
Loading