Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,19 @@ enum State {

static {
s_fsm.addTransition(State.Created, Event.StartRequested, State.Starting);
s_fsm.addTransition(State.Created, Event.DestroyRequested, State.Destroying);

s_fsm.addTransition(State.Starting, Event.OperationSucceeded, State.Running);
s_fsm.addTransition(State.Starting, Event.OperationFailed, State.Alert);
s_fsm.addTransition(State.Starting, Event.CreateFailed, State.Error);
s_fsm.addTransition(State.Starting, Event.StopRequested, State.Stopping);
s_fsm.addTransition(State.Starting, Event.DestroyRequested, State.Destroying);

s_fsm.addTransition(State.Running, Event.StopRequested, State.Stopping);
s_fsm.addTransition(State.Alert, Event.StopRequested, State.Stopping);
s_fsm.addTransition(State.Stopping, Event.OperationSucceeded, State.Stopped);
s_fsm.addTransition(State.Stopping, Event.OperationFailed, State.Alert);
s_fsm.addTransition(State.Stopping, Event.DestroyRequested, State.Destroying);

s_fsm.addTransition(State.Stopped, Event.StartRequested, State.Starting);

Expand All @@ -87,19 +90,23 @@ enum State {
s_fsm.addTransition(State.Running, Event.ScaleDownRequested, State.Scaling);
s_fsm.addTransition(State.Scaling, Event.OperationSucceeded, State.Running);
s_fsm.addTransition(State.Scaling, Event.OperationFailed, State.Alert);
s_fsm.addTransition(State.Scaling, Event.DestroyRequested, State.Destroying);

s_fsm.addTransition(State.Running, Event.UpgradeRequested, State.Upgrading);
s_fsm.addTransition(State.Upgrading, Event.OperationSucceeded, State.Running);
s_fsm.addTransition(State.Upgrading, Event.OperationFailed, State.Alert);
s_fsm.addTransition(State.Upgrading, Event.DestroyRequested, State.Destroying);

s_fsm.addTransition(State.Alert, Event.RecoveryRequested, State.Recovering);
s_fsm.addTransition(State.Recovering, Event.OperationSucceeded, State.Running);
s_fsm.addTransition(State.Recovering, Event.OperationFailed, State.Alert);
s_fsm.addTransition(State.Recovering, Event.DestroyRequested, State.Destroying);

s_fsm.addTransition(State.Running, Event.DestroyRequested, State.Destroying);
s_fsm.addTransition(State.Stopped, Event.DestroyRequested, State.Destroying);
s_fsm.addTransition(State.Alert, Event.DestroyRequested, State.Destroying);
s_fsm.addTransition(State.Error, Event.DestroyRequested, State.Destroying);
s_fsm.addTransition(State.Destroying, Event.DestroyRequested, State.Destroying);

s_fsm.addTransition(State.Destroying, Event.OperationSucceeded, State.Destroyed);

Expand Down Expand Up @@ -128,4 +135,4 @@ enum State {
State getState();
Date getCreated();
Date getRemoved();
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,8 @@ public boolean isDisplay() {
// public boolean isCheckForGc() {
// return checkForGc;
// }
public AutomationControllerVO(long id, String name, String description, Long automationTemplateId, Long zoneId, Long serviceOfferingId, long networkId, String networkName, long accountId, long domainId, State state, String automationControllerIp) {
public AutomationControllerVO(String name, String description, Long automationTemplateId, Long zoneId, Long serviceOfferingId, long networkId, String networkName, long accountId, long domainId, State state, String automationControllerIp) {
this.uuid = UUID.randomUUID().toString();
this.id = id;
this.name = name;
this.description = description;
this.automationTemplateId = automationTemplateId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,16 @@

import javax.inject.Inject;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

import static com.cloud.utils.NumbersUtil.toHumanReadableSize;

public class AutomationControllerActionWorker {

public static final int CLUSTER_USER_PORTAL_PORT = 8080;
public static final int CLUSTER_ADMIN_PORTAL_PORT = 8081;
public static final int CLUSTER_API_PORT = 8082;
public static final int CLUSTER_SAMBA_PORT = 9017;
public static final Integer AUTOMATION_CONTROLLER_PORT = null;

protected Logger logger = LogManager.getLogger(getClass());

protected StateMachine2<AutomationController.State, AutomationController.Event, AutomationController> _stateMachine = AutomationController.State.getStateMachine();
Expand Down Expand Up @@ -195,7 +189,14 @@ protected void init() {
}

protected String readResourceFile(String resource) throws IOException {
return IOUtils.toString(Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)), StringUtils.getPreferredCharset());
String normalizedResource = resource.startsWith("/") ? resource.substring(1) : resource;
InputStream resourceStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(normalizedResource);
if (resourceStream == null) {
throw new IOException(String.format("Automation controller resource not found: %s", resource));
}
try (InputStream inputStream = resourceStream) {
return IOUtils.toString(inputStream, StringUtils.getPreferredCharset());
}
}

protected void logMessage(final Level logLevel, final String message, final Exception e) {
Expand Down Expand Up @@ -267,7 +268,7 @@ public AutomationControllerVmMapVO doInTransaction(TransactionStatus status) {
protected List<AutomationControllerVmMapVO> getControlVMMaps() {
List<AutomationControllerVmMapVO> automationControllerVMs = automationControllerVmMapDao.listByAutomationControllerId(automationController.getId());
if (!CollectionUtils.isEmpty(automationControllerVMs)) {
automationControllerVMs.sort((t1, t2) -> (int)((t1.getId() - t2.getId())/Math.abs(t1.getId() - t2.getId())));
automationControllerVMs.sort((t1, t2) -> Long.compare(t1.getId(), t2.getId()));
}
return automationControllerVMs;
}
Expand All @@ -285,6 +286,11 @@ protected List<UserVm> getAutomationControllerVMs() {

protected boolean stateTransitTo(long automationControllerId, AutomationController.Event e) {
AutomationControllerVO automationController = automationControllerDao.findById(automationControllerId);
if (automationController == null) {
logger.warn(String.format("Failed to transition missing automation controller %d on event %s",
automationControllerId, e));
return false;
}
try {
return _stateMachine.transitTo(automationController, e, null, automationControllerDao);
} catch (NoTransitionException nte) {
Expand Down Expand Up @@ -321,30 +327,33 @@ protected IpAddress getAutomationControllerServerIp() {
protected void removeFirewallIngressRule(final IpAddress publicIp) {
List<FirewallRuleVO> firewallRules = firewallRulesDao.listByIpAndPurposeAndNotRevoked(publicIp.getId(), FirewallRule.Purpose.Firewall);
for (FirewallRuleVO firewallRule : firewallRules) {
if (firewallRule.getSourcePortStart() != null && firewallRule.getSourcePortEnd() != null) {
if (firewallRule.getSourcePortStart() == CLUSTER_USER_PORTAL_PORT &&
firewallRule.getSourcePortEnd() == CLUSTER_API_PORT && firewallRule.getTrafficType() == FirewallRule.TrafficType.Ingress) {
firewallService.revokeIngressFwRule(firewallRule.getId(), true);
}
if (firewallRule.getSourcePortStart() == CLUSTER_SAMBA_PORT &&
firewallRule.getSourcePortEnd() == CLUSTER_SAMBA_PORT && firewallRule.getTrafficType() == FirewallRule.TrafficType.Ingress) {
firewallService.revokeIngressFwRule(firewallRule.getId(), true);
}
if (FirewallRule.TrafficType.Ingress.equals(firewallRule.getTrafficType())
&& isAutomationControllerFirewallRule(firewallRule)) {
firewallService.revokeIngressFwRule(firewallRule.getId(), true);
}
}
}

protected void removeFirewallEgressRule(final Network network) {
List<FirewallRuleVO> firewallRules = firewallRulesDao.listByNetworkAndPurposeAndNotRevoked(network.getId(), FirewallRule.Purpose.Firewall);
for (FirewallRuleVO firewallRule : firewallRules) {
if (firewallRule.getSourcePortStart() != null && firewallRule.getSourcePortEnd() != null) {
if (firewallRule.getSourcePortStart() == CLUSTER_USER_PORTAL_PORT && firewallRule.getSourcePortEnd() == CLUSTER_ADMIN_PORTAL_PORT && firewallRule.getTrafficType() == FirewallRule.TrafficType.Egress) {
firewallService.revokeIngressFwRule(firewallRule.getId(), true);
}
if (FirewallRule.TrafficType.Egress.equals(firewallRule.getTrafficType())
&& isAutomationControllerFirewallRule(firewallRule)) {
firewallService.revokeEgressFirewallRule(firewallRule.getId(), true);
}
}
}

private boolean isAutomationControllerFirewallRule(FirewallRuleVO firewallRule) {
String protocol = firewallRule.getProtocol();
if (!("tcp".equalsIgnoreCase(protocol) || "udp".equalsIgnoreCase(protocol) || "icmp".equalsIgnoreCase(protocol))) {
return false;
}
Integer startPort = firewallRule.getSourcePortStart();
Integer endPort = firewallRule.getSourcePortEnd();
return (startPort == null && endPort == null) || (Integer.valueOf(1).equals(startPort) && Integer.valueOf(65535).equals(endPort));
}

protected void removePortForwardingRules(final IpAddress publicIp, final Network network, final Account account, final List<Long> removedVMIds) throws ResourceUnavailableException {
if (!CollectionUtils.isEmpty(removedVMIds)) {
for (Long vmId : removedVMIds) {
Expand Down
Loading
Loading