more revert cleanup

This commit is contained in:
David Nalley 2014-10-12 23:31:17 -04:00
parent ac48aa8e0c
commit ffe846673c
8 changed files with 17 additions and 211 deletions

View File

@ -454,7 +454,6 @@ public class EventTypes {
public static final String EVENT_BAREMETAL_PXE_SERVER_ADD = "PHYSICAL.PXE.ADD";
public static final String EVENT_BAREMETAL_PXE_SERVER_DELETE = "PHYSICAL.PXE.DELETE";
public static final String EVENT_BAREMETAL_RCT_ADD = "BAREMETAL.RCT.ADD";
public static final String EVENT_BAREMETAL_PROVISION_DONE = "BAREMETAL.PROVISION.DONE";
public static final String EVENT_AFFINITY_GROUP_CREATE = "AG.CREATE";
public static final String EVENT_AFFINITY_GROUP_DELETE = "AG.DELETE";

View File

@ -20,12 +20,9 @@ package com.cloud.baremetal.manager;
import com.cloud.utils.component.Manager;
import com.cloud.utils.component.PluggableService;
import org.apache.cloudstack.api.BaremetalProvisionDoneNotificationCmd;
public interface BaremetalManager extends Manager, PluggableService {
public static final String EchoSecurityGroupAgent = "EchoSecurityGroupAgent";
public static final String ExternalBaremetalSystemUrl = "ExternalBaremetalSystemUrl";
public static final String DO_PXE = "doPxe";
void notifyProvisionDone(BaremetalProvisionDoneNotificationCmd cmd);
}

View File

@ -26,12 +26,6 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import com.cloud.utils.db.QueryBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.dao.VMInstanceDao;
import org.apache.cloudstack.api.BaremetalProvisionDoneNotificationCmd;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.AddBaremetalHostCmd;
@ -51,8 +45,6 @@ public class BaremetalManagerImpl extends ManagerBase implements BaremetalManage
@Inject
protected HostDao _hostDao;
@Inject
protected VMInstanceDao vmDao;
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
@ -115,40 +107,6 @@ public class BaremetalManagerImpl extends ManagerBase implements BaremetalManage
public List<Class<?>> getCommands() {
List<Class<?>> cmds = new ArrayList<Class<?>>();
cmds.add(AddBaremetalHostCmd.class);
cmds.add(BaremetalProvisionDoneNotificationCmd.class);
return cmds;
}
@Override
public void notifyProvisionDone(BaremetalProvisionDoneNotificationCmd cmd) {
QueryBuilder<HostVO> hq = QueryBuilder.create(HostVO.class);
hq.and(hq.entity().getPrivateMacAddress(), SearchCriteria.Op.EQ, cmd.getMac());
HostVO host = hq.find();
if (host == null) {
throw new CloudRuntimeException(String.format("cannot find host[mac:%s]", cmd.getMac()));
}
_hostDao.loadDetails(host);
String vmName = host.getDetail("vmName");
if (vmName == null) {
throw new CloudRuntimeException(String.format("cannot find any baremetal instance running on host[mac:%s]", cmd.getMac()));
}
QueryBuilder<VMInstanceVO> vmq = QueryBuilder.create(VMInstanceVO.class);
vmq.and(vmq.entity().getInstanceName(), SearchCriteria.Op.EQ, vmName);
VMInstanceVO vm = vmq.find();
if (vm == null) {
throw new CloudRuntimeException(String.format("cannot find baremetal instance[name:%s]", vmName));
}
if (State.Starting != vm.getState()) {
throw new CloudRuntimeException(String.format("baremetal instance[name:%s, state:%s] is not in state of Starting", vmName, vm.getState()));
}
vm.setState(State.Running);
vmDao.update(vm.getId(), vm);
s_logger.debug(String.format("received baremetal provision done notification for vm[id:%s name:%s] running on host[mac:%s, ip:%s]",
vm.getId(), vm.getInstanceName(), host.getPrivateMacAddress(), host.getPrivateIpAddress()));
}
}

View File

@ -61,15 +61,12 @@ import com.cloud.hypervisor.Hypervisor;
import com.cloud.resource.ServerResource;
import com.cloud.utils.Pair;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.db.QueryBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.OutputInterpreter;
import com.cloud.utils.script.Script;
import com.cloud.utils.script.Script2;
import com.cloud.utils.script.Script2.ParamType;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.PowerState;
import com.cloud.vm.dao.VMInstanceDao;
import org.apache.cloudstack.api.ApiConstants;
@ -112,8 +109,6 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource
protected Script2 _bootOrRebootCommand;
protected String _vmName;
protected int ipmiRetryTimes = 5;
protected boolean provisionDoneNotificationOn = false;
protected int isProvisionDoneNotificationTimeout = 1800;
protected ConfigurationDao configDao;
protected VMInstanceDao vmDao;
@ -188,13 +183,6 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource
s_logger.debug(e.getMessage(), e);
}
try {
provisionDoneNotificationOn = Boolean.valueOf(configDao.getValue(Config.BaremetalProvisionDoneNotificationEnabled.key()));
isProvisionDoneNotificationTimeout = Integer.valueOf(configDao.getValue(Config.BaremetalProvisionDoneNotificationTimeout.key()));
} catch (Exception e) {
s_logger.debug(e.getMessage(), e);
}
String injectScript = "scripts/util/ipmi.py";
String scriptPath = Script.findScript("", injectScript);
if (scriptPath == null) {
@ -591,39 +579,6 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource
}
}
if (provisionDoneNotificationOn) {
QueryBuilder<VMInstanceVO> q = QueryBuilder.create(VMInstanceVO.class);
q.and(q.entity().getInstanceName(), SearchCriteria.Op.EQ, vm.getName());
VMInstanceVO vmvo = q.find();
if (vmvo.getLastHostId() == null) {
// this is new created vm
long timeout = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(isProvisionDoneNotificationTimeout);
while (timeout > System.currentTimeMillis()) {
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
s_logger.warn(e.getMessage(), e);
}
q = QueryBuilder.create(VMInstanceVO.class);
q.and(q.entity().getInstanceName(), SearchCriteria.Op.EQ, vm.getName());
vmvo = q.find();
if (vmvo == null) {
return new StartAnswer(cmd, String.format("cannot find vm[name:%s] while waiting for baremtal provision done notification", vm.getName()));
}
if (VirtualMachine.State.Running == vmvo.getState()) {
return new StartAnswer(cmd);
}
s_logger.debug(String.format("still wait for baremetal provision done notification for vm[name:%s], current vm state is %s", vmvo.getInstanceName(), vmvo.getState()));
}
return new StartAnswer(cmd, String.format("timeout after %s seconds, no baremetal provision done notification received. vm[name:%s] failed to start", isProvisionDoneNotificationTimeout, vm.getName()));
}
}
s_logger.debug("Start bare metal vm " + vm.getName() + "successfully");
_vmName = vm.getName();
return new StartAnswer(cmd);

View File

@ -30,7 +30,6 @@ import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import com.cloud.configuration.Config;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.AddBaremetalKickStartPxeCmd;
@ -219,11 +218,6 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase imple
throw new CloudRuntimeException(String.format("cannot find management nic on virtual router[id:%s]", vr.getId()));
}
String internalServerIp = _configDao.getValue(Config.BaremetalInternalStorageServer.key());
if (internalServerIp == null) {
throw new CloudRuntimeException(String.format("please specify 'baremetal.internal.storage.server.ip', which is the http server/nfs server storing kickstart files and ISO files, in global setting"));
}
List<String> tuple = parseKickstartUrl(profile);
Pair<Boolean, String> ret = SshHelper.sshExecute(mgmtNic.getIp4Address(), 3922, "root", getSystemVMKeyFile(), null,
String.format("/usr/bin/prepare_pxe.sh %s %s %s %s %s", tuple.get(1), tuple.get(2), profile.getTemplate().getUuid(),

View File

@ -1,87 +0,0 @@
// 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.api;
import com.cloud.baremetal.manager.BaremetalManager;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.context.CallContext;
import javax.inject.Inject;
import org.apache.log4j.Logger;
/**
* Created by frank on 9/17/14.
*/
@APICommand(name = "notifyBaremetalProvisionDone", description = "Notify provision has been done on a host. This api is for baremetal virtual router service, not for end user", responseObject = SuccessResponse.class,
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.User})
public class BaremetalProvisionDoneNotificationCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(BaremetalProvisionDoneNotificationCmd.class);
private static final String s_name = "baremetalprovisiondone";
@Inject
private BaremetalManager bmMgr;
@Parameter(name="mac", required = true, description = "mac of the nic used for provision")
private String mac;
@Override
public String getEventType() {
return EventTypes.EVENT_BAREMETAL_PROVISION_DONE;
}
@Override
public String getEventDescription() {
return "notify management server that baremetal provision has been done on a host";
}
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
bmMgr.notifyProvisionDone(this);
this.setResponseObject(new SuccessResponse(getCommandName()));
} catch (Exception e) {
s_logger.warn(String.format("unable to notify baremetal provision done[mac:%s]", mac), e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
public String getMac() {
return mac;
}
public void setMac(String mac) {
this.mac = mac;
}
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccount().getId();
}
}

View File

@ -1849,6 +1849,22 @@ public enum Config {
"The maximum number of retrying times to search for an available IPv6 address in the table",
null),
BaremetalEnableCompleteNotification(
"Advanced",
ManagementServer.class,
Boolean.class,
"baremetal.provision.done.notification",
"false",
"Enable provision done notification through virtual router",
null),
BaremetalPeerHypervisorType(
"Advanced",
ManagementServer.class,
String.class,
"baremetal.peer.hypervisor.type",
"Vmware",
"Hypervisor[Xenserver/KVM/VMWare] used to spring up virtual router for baremetal instances. The cluster having this hypervisor type must be in the same zone with baremetal cluster",
null),
BaremetalInternalStorageServer(
"Advanced",
ManagementServer.class,
@ -1857,30 +1873,6 @@ public enum Config {
null,
"the ip address of server that stores kickstart file, kernel, initrd, ISO for advanced networking baremetal provisioning",
null),
BaremetalProvisionDoneNotificationEnabled(
"Advanced",
ManagementServer.class,
Boolean.class,
"baremetal.provision.done.notification.enabled",
"true",
"whether to enable baremetal provison done notification",
null),
BaremetalProvisionDoneNotificationTimeout(
"Advanced",
ManagementServer.class,
Integer.class,
"baremetal.provision.done.notification.timeout",
"1800",
"the max time to wait before treating a baremetal provision as failure if no provision done notification is not received, in secs",
null),
BaremetalProvisionDoneNotificationPort(
"Advanced",
ManagementServer.class,
Integer.class,
"baremetal.provision.done.notification.port",
"8080",
"the port that listens baremetal provision done notification. Should be the same to port management server listening on for now. Please change it to management server port if it's not default 8080",
null),
ExternalBaremetalSystemUrl(
"Advanced",
ManagementServer.class,

View File

@ -2323,7 +2323,7 @@ VirtualMachineGuru, Listener, Configurable, StateListener<State, VirtualMachine.
}
}
if (Boolean.valueOf(_configDao.getValue(Config.BaremetalProvisionDoneNotificationEnabled.key()))) {
if (Boolean.valueOf(_configDao.getValue("baremetal.provision.done.notification"))) {
QueryBuilder<UserVO> acntq = QueryBuilder.create(UserVO.class);
acntq.and(acntq.entity().getUsername(), SearchCriteria.Op.EQ, "baremetal-system-account");
UserVO user = acntq.find();
@ -2332,8 +2332,6 @@ VirtualMachineGuru, Listener, Configurable, StateListener<State, VirtualMachine.
} else {
buf.append(String.format(" baremetalnotificationsecuritykey=%s", user.getSecretKey()));
buf.append(String.format(" baremetalnotificationapikey=%s", user.getApiKey()));
buf.append(" host=").append(ApiServiceConfiguration.ManagementHostIPAdr.value());
buf.append(" port=").append(_configDao.getValue(Config.BaremetalProvisionDoneNotificationPort.key()));
}
}