Skip to content

Commit ad19e00

Browse files
author
Rohit Yadav
authored
Merge pull request #13 from shapeblue/host-ha-4.5
APPLE-165: Host HA and KVM provider
2 parents 2b4cdd6 + 876fc74 commit ad19e00

120 files changed

Lines changed: 8462 additions & 415 deletions

File tree

Some content is hidden

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

‎api/src/com/cloud/dc/DataCenter.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818

1919
import com.cloud.org.Grouping;
2020
import org.apache.cloudstack.acl.InfrastructureEntity;
21-
import org.apache.cloudstack.api.Identity;
22-
import org.apache.cloudstack.api.InternalIdentity;
21+
import org.apache.cloudstack.kernel.Partition;
2322

2423
import java.util.Map;
2524

2625
/**
2726
*
2827
*/
29-
public interface DataCenter extends InfrastructureEntity, Grouping, Identity, InternalIdentity {
28+
public interface DataCenter extends InfrastructureEntity, Grouping, Partition {
3029

3130
public enum NetworkType {
3231
Basic, Advanced,

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import com.cloud.user.Account;
7575
import com.cloud.user.User;
7676
import com.cloud.vm.VirtualMachine;
77+
import org.apache.cloudstack.ha.HAConfig;
7778

7879
public class EventTypes {
7980

@@ -318,6 +319,12 @@ public class EventTypes {
318319
public static final String EVENT_HOST_OUTOFBAND_MANAGEMENT_CHANGE_PASSWORD = "HOST.OOBM.CHANGEPASSWORD";
319320
public static final String EVENT_HOST_OUTOFBAND_MANAGEMENT_POWERSTATE_TRANSITION = "HOST.OOBM.POWERSTATE.TRANSITION";
320321

322+
// HA
323+
public static final String EVENT_HA_RESOURCE_ENABLE = "HA.RESOURCE.ENABLE";
324+
public static final String EVENT_HA_RESOURCE_DISABLE = "HA.RESOURCE.DISABLE";
325+
public static final String EVENT_HA_RESOURCE_CONFIGURE = "HA.RESOURCE.CONFIGURE";
326+
public static final String EVENT_HA_STATE_TRANSITION = "HA.STATE.TRANSITION";
327+
321328
// Maintenance
322329
public static final String EVENT_MAINTENANCE_CANCEL = "MAINT.CANCEL";
323330
public static final String EVENT_MAINTENANCE_CANCEL_PRIMARY_STORAGE = "MAINT.CANCEL.PS";
@@ -754,6 +761,12 @@ public class EventTypes {
754761
entityEventDetails.put(EVENT_HOST_OUTOFBAND_MANAGEMENT_CHANGE_PASSWORD, Host.class);
755762
entityEventDetails.put(EVENT_HOST_OUTOFBAND_MANAGEMENT_POWERSTATE_TRANSITION, Host.class);
756763

764+
// HA
765+
entityEventDetails.put(EVENT_HA_RESOURCE_ENABLE, HAConfig.class);
766+
entityEventDetails.put(EVENT_HA_RESOURCE_DISABLE, HAConfig.class);
767+
entityEventDetails.put(EVENT_HA_RESOURCE_CONFIGURE, HAConfig.class);
768+
entityEventDetails.put(EVENT_HA_STATE_TRANSITION, HAConfig.class);
769+
757770
// Maintenance
758771
entityEventDetails.put(EVENT_MAINTENANCE_CANCEL, Host.class);
759772
entityEventDetails.put(EVENT_MAINTENANCE_CANCEL_PRIMARY_STORAGE, Host.class);

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
// under the License.
1717
package com.cloud.host;
1818

19-
import java.util.Date;
20-
21-
import org.apache.cloudstack.api.Identity;
22-
import org.apache.cloudstack.api.InternalIdentity;
23-
2419
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2520
import com.cloud.resource.ResourceState;
2621
import com.cloud.utils.fsm.StateObject;
22+
import org.apache.cloudstack.api.Identity;
23+
import org.apache.cloudstack.ha.HAResource;
24+
import org.apache.cloudstack.kernel.Partition;
25+
26+
import java.util.Date;
2727

2828
/**
2929
* Host represents one particular host server.
3030
*/
31-
public interface Host extends StateObject<Status>, Identity, InternalIdentity {
31+
public interface Host extends StateObject<Status>, Identity, Partition, HAResource {
3232
public enum Type {
3333
Storage(false), Routing(false), SecondaryStorage(false), SecondaryStorageCmdExecutor(false), ConsoleProxy(true), ExternalFirewall(false), ExternalLoadBalancer(
3434
false), ExternalVirtualSwitchSupervisor(false), PxeServer(false), BaremetalPxe(false), BaremetalDhcp(false), TrafficMonitor(false),
@@ -202,5 +202,7 @@ public static String[] toStrings(Host.Type... types) {
202202

203203
boolean isInMaintenanceStates();
204204

205+
boolean isDisabled();
206+
205207
ResourceState getResourceState();
206208
}

‎api/src/com/cloud/host/Status.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,14 @@ public static String[] toStrings(Status... states) {
150150
s_fsm.addTransition(Status.Down, Event.ManagementServerDown, Status.Down);
151151
s_fsm.addTransition(Status.Down, Event.AgentDisconnected, Status.Down);
152152
s_fsm.addTransition(Status.Down, Event.PingTimeout, Status.Down);
153+
s_fsm.addTransition(Status.Down, Event.HostDown, Status.Down);
153154
s_fsm.addTransition(Status.Alert, Event.AgentConnected, Status.Connecting);
154155
s_fsm.addTransition(Status.Alert, Event.Ping, Status.Up);
155156
s_fsm.addTransition(Status.Alert, Event.Remove, Status.Removed);
156157
s_fsm.addTransition(Status.Alert, Event.ManagementServerDown, Status.Alert);
157158
s_fsm.addTransition(Status.Alert, Event.AgentDisconnected, Status.Alert);
158159
s_fsm.addTransition(Status.Alert, Event.ShutdownRequested, Status.Disconnected);
160+
s_fsm.addTransition(Status.Alert, Event.HostDown, Status.Down);
159161
s_fsm.addTransition(Status.Rebalancing, Event.RebalanceFailed, Status.Disconnected);
160162
s_fsm.addTransition(Status.Rebalancing, Event.RebalanceCompleted, Status.Connecting);
161163
s_fsm.addTransition(Status.Rebalancing, Event.ManagementServerDown, Status.Disconnected);

‎api/src/com/cloud/org/Cluster.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
// under the License.
1717
package com.cloud.org;
1818

19-
import org.apache.cloudstack.api.Identity;
20-
import org.apache.cloudstack.api.InternalIdentity;
21-
2219
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2320
import com.cloud.org.Managed.ManagedState;
21+
import org.apache.cloudstack.kernel.Partition;
2422

25-
public interface Cluster extends Grouping, InternalIdentity, Identity {
23+
public interface Cluster extends Grouping, Partition {
2624
public static enum ClusterType {
2725
CloudManaged, ExternalManaged;
2826
};

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public static String[] toString(ResourceState... states) {
9393
s_fsm.addTransition(ResourceState.Enabled, Event.InternalCreated, ResourceState.Enabled);
9494
s_fsm.addTransition(ResourceState.Enabled, Event.Disable, ResourceState.Disabled);
9595
s_fsm.addTransition(ResourceState.Enabled, Event.AdminAskMaintenace, ResourceState.PrepareForMaintenance);
96+
s_fsm.addTransition(ResourceState.Enabled, Event.InternalEnterMaintenance, ResourceState.Maintenance);
9697
s_fsm.addTransition(ResourceState.Disabled, Event.Enable, ResourceState.Enabled);
9798
s_fsm.addTransition(ResourceState.Disabled, Event.Disable, ResourceState.Disabled);
9899
s_fsm.addTransition(ResourceState.Disabled, Event.InternalCreated, ResourceState.Disabled);
@@ -109,5 +110,7 @@ public static String[] toString(ResourceState... states) {
109110
s_fsm.addTransition(ResourceState.ErrorInMaintenance, Event.InternalEnterMaintenance, ResourceState.Maintenance);
110111
s_fsm.addTransition(ResourceState.ErrorInMaintenance, Event.AdminCancelMaintenance, ResourceState.Enabled);
111112
s_fsm.addTransition(ResourceState.Error, Event.InternalCreated, ResourceState.Error);
113+
s_fsm.addTransition(ResourceState.Disabled, Event.DeleteHost, ResourceState.Disabled);
114+
112115
}
113116
}

‎api/src/com/cloud/vm/VirtualMachine.java‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,24 @@
1616
// under the License.
1717
package com.cloud.vm;
1818

19-
import java.util.Arrays;
20-
import java.util.Date;
21-
import java.util.Map;
22-
23-
import org.apache.cloudstack.acl.ControlledEntity;
24-
import org.apache.cloudstack.api.Displayable;
25-
import org.apache.cloudstack.api.Identity;
26-
import org.apache.cloudstack.api.InternalIdentity;
27-
2819
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2920
import com.cloud.utils.fsm.StateMachine2;
3021
import com.cloud.utils.fsm.StateMachine2.Transition;
3122
import com.cloud.utils.fsm.StateMachine2.Transition.Impact;
3223
import com.cloud.utils.fsm.StateObject;
24+
import org.apache.cloudstack.acl.ControlledEntity;
25+
import org.apache.cloudstack.api.Displayable;
26+
import org.apache.cloudstack.kernel.Partition;
27+
28+
import java.util.Arrays;
29+
import java.util.Date;
30+
import java.util.Map;
3331

3432
/**
3533
* VirtualMachine describes the properties held by a virtual machine
3634
*
3735
*/
38-
public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, InternalIdentity, Displayable, StateObject<VirtualMachine.State> {
36+
public interface VirtualMachine extends RunningOn, ControlledEntity, Partition, Displayable, StateObject<VirtualMachine.State> {
3937

4038
public enum PowerState {
4139
PowerUnknown,

‎api/src/org/apache/cloudstack/alert/AlertService.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
// under the License.
1717
package org.apache.cloudstack.alert;
1818

19-
import java.util.HashSet;
20-
import java.util.Set;
21-
2219
import com.cloud.capacity.Capacity;
2320
import com.cloud.exception.InvalidParameterValueException;
2421

22+
import java.util.HashSet;
23+
import java.util.Set;
24+
2525
public interface AlertService {
2626
public static class AlertType {
2727
private static Set<AlertType> defaultAlertTypes = new HashSet<AlertType>();
@@ -66,6 +66,7 @@ private AlertType(short type, String name, boolean isDefault) {
6666
public static final AlertType ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED = new AlertType((short)26, "ALERT.RESOURCE.EXCEED", true);
6767
public static final AlertType ALERT_TYPE_SYNC = new AlertType((short)27, "ALERT.TYPE.SYNC", true);
6868
public static final AlertType ALERT_TYPE_OOBM_AUTH_ERROR = new AlertType((short)29, "ALERT.OOBM.AUTHERROR", true);
69+
public static final AlertType ALERT_TYPE_HA_ACTION = new AlertType((short)30, "ALERT.HA.ACTION", true);
6970

7071
public short getType() {
7172
return type;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class ApiConstants {
2121
public static final String ACCOUNTS = "accounts";
2222
public static final String ACCOUNT_TYPE = "accounttype";
2323
public static final String ACCOUNT_ID = "accountid";
24+
public static final String ACTIVITY = "activity";
2425
public static final String ADDRESS = "address";
2526
public static final String ALGORITHM = "algorithm";
2627
public static final String ALLOCATED_ONLY = "allocatedonly";
@@ -93,13 +94,15 @@ public class ApiConstants {
9394
public static final String DOMAIN_ID = "domainid";
9495
public static final String DOMAIN__ID = "domainId";
9596
public static final String DURATION = "duration";
97+
public static final String ELIGIBLE = "eligible";
9698
public static final String EMAIL = "email";
9799
public static final String END_DATE = "enddate";
98100
public static final String END_IP = "endip";
99101
public static final String END_IPV6 = "endipv6";
100102
public static final String END_PORT = "endport";
101103
public static final String ENTRY_TIME = "entrytime";
102104
public static final String EXPIRES = "expires";
105+
public static final String FENCE = "fence";
103106
public static final String FETCH_LATEST = "fetchlatest";
104107
public static final String FIRSTNAME = "firstname";
105108
public static final String FORCED = "forced";
@@ -118,6 +121,9 @@ public class ApiConstants {
118121
public static final String GUEST_CIDR_ADDRESS = "guestcidraddress";
119122
public static final String GUEST_VLAN_RANGE = "guestvlanrange";
120123
public static final String HA_ENABLE = "haenable";
124+
public static final String HA_PROVIDER = "haprovider";
125+
public static final String HA_STATE = "hastate";
126+
public static final String HEALTH = "health";
121127
public static final String HOST_ID = "hostid";
122128
public static final String HOST_NAME = "hostname";
123129
public static final String HYPERVISOR = "hypervisor";
@@ -212,6 +218,7 @@ public class ApiConstants {
212218
public static final String PUBLIC_END_PORT = "publicendport";
213219
public static final String PUBLIC_ZONE = "publiczone";
214220
public static final String RECEIVED_BYTES = "receivedbytes";
221+
public static final String RECOVER = "recover";
215222
public static final String REQUIRES_HVM = "requireshvm";
216223
public static final String RESOURCE_TYPE = "resourcetype";
217224
public static final String RESPONSE = "response";
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
18+
package org.apache.cloudstack.api.command.admin.ha;
19+
20+
import com.cloud.event.EventTypes;
21+
import com.cloud.exception.ConcurrentOperationException;
22+
import com.cloud.exception.InsufficientCapacityException;
23+
import com.cloud.exception.NetworkRuleConflictException;
24+
import com.cloud.exception.ResourceAllocationException;
25+
import com.cloud.exception.ResourceUnavailableException;
26+
import com.cloud.host.Host;
27+
import com.cloud.user.Account;
28+
import org.apache.cloudstack.acl.RoleType;
29+
import org.apache.cloudstack.api.APICommand;
30+
import org.apache.cloudstack.api.ApiArgValidator;
31+
import org.apache.cloudstack.api.ApiConstants;
32+
import org.apache.cloudstack.api.ApiErrorCode;
33+
import org.apache.cloudstack.api.BaseAsyncCmd;
34+
import org.apache.cloudstack.api.BaseCmd;
35+
import org.apache.cloudstack.api.Parameter;
36+
import org.apache.cloudstack.api.ServerApiException;
37+
import org.apache.cloudstack.api.response.HostHAResponse;
38+
import org.apache.cloudstack.api.response.HostResponse;
39+
import org.apache.cloudstack.context.CallContext;
40+
import org.apache.cloudstack.ha.HAConfigManager;
41+
import org.apache.cloudstack.ha.HAResource;
42+
43+
import javax.inject.Inject;
44+
45+
@APICommand(name = ConfigureHAForHostCmd.APINAME, description = "Configures HA for a host",
46+
responseObject = HostHAResponse.class,
47+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
48+
since = "4.11", authorized = {RoleType.Admin})
49+
public final class ConfigureHAForHostCmd extends BaseAsyncCmd {
50+
public static final String APINAME = "configureHAForHost";
51+
52+
@Inject
53+
private HAConfigManager haConfigManager;
54+
55+
/////////////////////////////////////////////////////
56+
//////////////// API parameters /////////////////////
57+
/////////////////////////////////////////////////////
58+
59+
@Parameter(name = ApiConstants.HOST_ID, type = CommandType.UUID, entityType = HostResponse.class,
60+
description = "ID of the host", required = true, validations = {ApiArgValidator.PositiveNumber})
61+
private Long hostId;
62+
63+
@Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING,
64+
description = "HA provider", required = true, validations = {ApiArgValidator.NotNullOrEmpty})
65+
private String haProvider;
66+
67+
/////////////////////////////////////////////////////
68+
/////////////////// Accessors ///////////////////////
69+
/////////////////////////////////////////////////////
70+
71+
public Long getHostId() {
72+
return hostId;
73+
}
74+
75+
public String getHaProvider() {
76+
return haProvider;
77+
}
78+
79+
/////////////////////////////////////////////////////
80+
/////////////// API Implementation///////////////////
81+
/////////////////////////////////////////////////////
82+
83+
@Override
84+
public String getCommandName() {
85+
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
86+
}
87+
88+
@Override
89+
public long getEntityOwnerId() {
90+
return Account.ACCOUNT_ID_SYSTEM;
91+
}
92+
93+
private void setupResponse(final boolean result, final String resourceUuid) {
94+
final HostHAResponse response = new HostHAResponse();
95+
response.setId(resourceUuid);
96+
response.setProvider(getHaProvider().toLowerCase());
97+
response.setResponseName(getCommandName());
98+
setResponseObject(response);
99+
}
100+
101+
@Override
102+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
103+
final Host host = _resourceService.getHost(getHostId());
104+
if (host == null) {
105+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find host by ID: " + getHostId());
106+
}
107+
108+
final boolean result = haConfigManager.configureHA(host.getId(), HAResource.ResourceType.Host, getHaProvider());
109+
if (!result) {
110+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure HA provider for the host");
111+
}
112+
CallContext.current().setEventDetails("Host Id:" + host.getId() + " HA configured with provider: " + getHaProvider());
113+
CallContext.current().putContextParameter(Host.class, host.getUuid());
114+
115+
setupResponse(result, host.getUuid());
116+
}
117+
118+
@Override
119+
public String getEventType() {
120+
return EventTypes.EVENT_HA_RESOURCE_DISABLE;
121+
}
122+
123+
@Override
124+
public String getEventDescription() {
125+
return "configure HA for host: " + getHostId();
126+
}
127+
}

0 commit comments

Comments
 (0)