CS-14605: OVS Tunnel Manager Clean-up

1) Remove old VLAN-in-overlay manager
2) Remove unused DAO objects
3) Fix code using removed object (all stale lines)

Conflicts:

	server/src/com/cloud/network/ovs/GreTunnelException.java
	server/src/com/cloud/network/ovs/OvsVlanExhaustedException.java
	server/src/com/cloud/network/ovs/dao/OvsTunnelAccountDao.java
	server/src/com/cloud/network/ovs/dao/OvsTunnelAccountDaoImpl.java
	server/src/com/cloud/network/ovs/dao/OvsTunnelAccountVO.java
This commit is contained in:
Salvatore Orlando 2012-04-25 10:50:17 +01:00
parent f7836ba61c
commit 33a2b17972
22 changed files with 0 additions and 2384 deletions

View File

@ -1,183 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.EntityExistsException;
import org.apache.log4j.Logger;
import com.cloud.agent.Listener;
import com.cloud.agent.api.AgentControlAnswer;
import com.cloud.agent.api.AgentControlCommand;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.PingRoutingWithOvsCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.exception.ConnectionException;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.dao.HostDao;
import com.cloud.network.ovs.dao.GreTunnelDao;
import com.cloud.network.ovs.dao.GreTunnelVO;
import com.cloud.network.ovs.dao.OvsWorkDao;
import com.cloud.network.ovs.dao.OvsWorkVO.Step;
import com.cloud.network.ovs.dao.VlanMappingDao;
import com.cloud.network.ovs.dao.VlanMappingVO;
import com.cloud.resource.ResourceManager;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Inject;
public class OvsListener implements Listener {
public static final Logger s_logger = Logger.getLogger(OvsListener.class.getName());
OvsNetworkManager _ovsNetworkMgr;
OvsWorkDao _workDao;
GreTunnelDao _tunnelDao;
VlanMappingDao _mappingDao;
HostDao _hostDao;
ResourceManager _resourceMgr;
public OvsListener(OvsNetworkManager ovsMgr, OvsWorkDao workDao, GreTunnelDao tunnelDao,
VlanMappingDao mappingDao, HostDao hostDao) {
this._ovsNetworkMgr = ovsMgr;
this._workDao = workDao;
this._tunnelDao = tunnelDao;
this._mappingDao = mappingDao;
this._hostDao = hostDao;
ComponentLocator locator = ComponentLocator.getLocator("management-server");
_resourceMgr = locator.getManager(ResourceManager.class);
}
@Override
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
Set<Long> failedFlowVms = new HashSet<Long>();
try {
for (Answer ans : answers) {
if (ans instanceof OvsSetTagAndFlowAnswer) {
OvsSetTagAndFlowAnswer r = (OvsSetTagAndFlowAnswer) ans;
if (!r.getResult()) {
s_logger.warn("Failed to set flow for VM "
+ r.getVmId());
_workDao.updateStep(r.getVmId(), r.getSeqNo(),
Step.Error);
failedFlowVms.add(r.getVmId());
} else {
s_logger.info("Success to set flow for VM "
+ r.getVmId());
_workDao.updateStep(r.getVmId(), r.getSeqNo(),
Step.Done);
}
}
}
} catch (Exception e) {
s_logger.warn("process answer failed", e);
}
if (failedFlowVms.size() > 0) {
_ovsNetworkMgr.scheduleFlowUpdateToHosts(failedFlowVms, false, new Long(10*1000l));
}
return true;
}
@Override
public boolean processCommands(long agentId, long seq, Command[] commands) {
boolean processed = false;
for (Command cmd : commands) {
if (cmd instanceof PingRoutingWithOvsCommand) {
PingRoutingWithOvsCommand ping = (PingRoutingWithOvsCommand)cmd;
if (ping !=null && ping.getStates().size() > 0) {
_ovsNetworkMgr.fullSync(ping.getStates());
}
processed = true;
}
}
return processed;
}
@Override
public AgentControlAnswer processControlCommand(long agentId,
AgentControlCommand cmd) {
return null;
}
@Override
public void processConnect(HostVO host, StartupCommand cmd, boolean forRebalance)
throws ConnectionException {
if (host.getType() != Host.Type.Routing) {
return;
}
List<VlanMappingVO> maps = _mappingDao.listByHostId(host.getId());
if (maps.size() == 0) {
for (int i=0; i<512; i++) {
VlanMappingVO vo = new VlanMappingVO(0, host.getId(), i);
_mappingDao.persist(vo);
}
}
try {
List<HostVO> hosts = _resourceMgr.listAllHostsInAllZonesByType(Host.Type.Routing);
for (HostVO h : hosts) {
if (h.getId() == host.getId()) {
continue;
}
GreTunnelVO t = _tunnelDao.getByFromAndTo(host.getId(), h.getId());
if (t == null) {
t = new GreTunnelVO(host.getId(), h.getId());
try {
_tunnelDao.persist(t);
} catch (EntityExistsException e) {
s_logger.debug(String.format("Already has (from=%1$s, to=%2$s)", host.getId(), h.getId()));
}
}
t = _tunnelDao.getByFromAndTo(h.getId(), host.getId());
if (t == null) {
t = new GreTunnelVO(h.getId(), host.getId());
try {
_tunnelDao.persist(t);
} catch (EntityExistsException e) {
s_logger.debug(String.format("Already has (from=%1$s, to=%2$s)", h.getId(), host.getId()));
}
}
}
} catch (Exception e) {
s_logger.warn("process connect failed", e);
}
}
@Override
public boolean processDisconnect(long agentId, Status state) {
return true;
}
@Override
public boolean isRecurring() {
return false;
}
@Override
public int getTimeout() {
return -1;
}
@Override
public boolean processTimeout(long agentId, long seq) {
return true;
}
}

View File

@ -1,38 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs;
import java.util.List;
import java.util.Set;
import com.cloud.deploy.DeployDestination;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Manager;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.VirtualMachineProfile;
public interface OvsNetworkManager extends Manager {
public boolean isOvsNetworkEnabled();
public void VmCheckAndCreateTunnel(VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest);
public void handleVmStateTransition(VMInstanceVO userVm, State vmState);
public void fullSync(List<Pair<String, Long>> states);
public void scheduleFlowUpdateToHosts(Set<Long> affectedVms, boolean updateSeqno, Long delayMs);
String applyDefaultFlow(VirtualMachine instance, DeployDestination dest);
}

View File

@ -1,771 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.manager.Commands;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.ovs.dao.GreTunnelDao;
import com.cloud.network.ovs.dao.GreTunnelVO;
import com.cloud.network.ovs.dao.OvsWorkDao;
import com.cloud.network.ovs.dao.OvsWorkVO;
import com.cloud.network.ovs.dao.OvsWorkVO.Step;
import com.cloud.network.ovs.dao.VlanMappingDao;
import com.cloud.network.ovs.dao.VlanMappingDirtyDao;
import com.cloud.network.ovs.dao.VlanMappingVO;
import com.cloud.network.ovs.dao.VmFlowLogDao;
import com.cloud.network.ovs.dao.VmFlowLogVO;
import com.cloud.server.ManagementServer;
import com.cloud.user.AccountVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.Pair;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Inject;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.fsm.StateListener;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.Event;
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.NicDao;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.VMInstanceDao;
@Local(value={OvsNetworkManager.class})
public class OvsNetworkManagerImpl implements OvsNetworkManager {
private static final Logger s_logger = Logger.getLogger(OvsNetworkManagerImpl.class);
@Inject ConfigurationDao _configDao;
@Inject VlanMappingDao _vlanMappingDao;
@Inject UserVmDao _userVmDao;
@Inject HostDao _hostDao;
@Inject AgentManager _agentMgr;
@Inject NicDao _nicDao;
@Inject NetworkDao _networkDao;
@Inject VlanMappingDirtyDao _vlanMappingDirtyDao;
@Inject DomainRouterDao _routerDao;
@Inject OvsWorkDao _workDao;
@Inject VmFlowLogDao _flowLogDao;
@Inject UserVmDao _userVMDao;
@Inject VMInstanceDao _instanceDao;
@Inject AccountDao _accountDao;
@Inject GreTunnelDao _tunnelDao;
String _name;
boolean _isEnabled;
ScheduledExecutorService _executorPool;
ScheduledExecutorService _cleanupExecutor;
OvsListener _ovsListener;
VmStateListener _stateListener;
private long _serverId;
private final long _timeBetweenCleanups = 30; //seconds
public class VmStateListener implements StateListener<State, VirtualMachine.Event, VirtualMachine> {
OvsNetworkManager _mgr;
public VmStateListener(OvsNetworkManager mgr) {
_mgr = mgr;
}
@Override
public boolean postStateTransitionEvent(State oldState, Event event, State newState, VirtualMachine vm, boolean status, Object opaque) {
if (!_isEnabled || !status || (vm.getType() != VirtualMachine.Type.User && vm.getType() != VirtualMachine.Type.DomainRouter)) {
return false;
}
if (VirtualMachine.State.isVmStarted(oldState, event, newState)) {
_mgr.handleVmStateTransition((VMInstanceVO)vm, State.Running);
} else if (VirtualMachine.State.isVmMigrated(oldState, event, newState)) {
}
return true;
}
@Override
public boolean preStateTransitionEvent(State oldState, Event event, State newState, VirtualMachine vm, boolean status, Object opaque) {
if (!_isEnabled || !status || (vm.getType() != VirtualMachine.Type.User && vm.getType() != VirtualMachine.Type.DomainRouter)) {
return false;
}
if (VirtualMachine.State.isVmStopped(oldState, event, newState)) {
_mgr.handleVmStateTransition((VMInstanceVO)vm, State.Stopped);
}
return true;
}
}
public class WorkerThread implements Runnable {
@Override
public void run() {
work();
}
WorkerThread() {
}
}
public class CleanupThread implements Runnable {
@Override
public void run() {
cleanupFinishedWork();
cleanupUnfinishedWork();
}
CleanupThread() {
}
}
@Override
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
_name = name;
_isEnabled = Boolean.parseBoolean(_configDao.getValue(Config.OvsNetwork.key()));
if (_isEnabled) {
_serverId = ((ManagementServer)ComponentLocator.getComponent(ManagementServer.Name)).getId();
_executorPool = Executors.newScheduledThreadPool(10, new NamedThreadFactory("OVS"));
_cleanupExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("OVS-Cleanup"));
_ovsListener = new OvsListener(this, _workDao, _tunnelDao, _vlanMappingDao, _hostDao);
_agentMgr.registerForHostEvents(_ovsListener, true, true, true);
_stateListener = new VmStateListener(this);
VirtualMachine.State.getStateMachine().registerListener(_stateListener);
}
return true;
}
@Override
public boolean start() {
if (_isEnabled) {
_cleanupExecutor.scheduleAtFixedRate(new CleanupThread(), _timeBetweenCleanups, _timeBetweenCleanups, TimeUnit.SECONDS);
}
return true;
}
@Override
public boolean stop() {
return true;
}
@Override
public String getName() {
return _name;
}
@Override
public boolean isOvsNetworkEnabled() {
return _isEnabled;
}
public void cleanupFinishedWork() {
Date before = new Date(System.currentTimeMillis() - 24*3600*1000l);
int numDeleted = _workDao.deleteFinishedWork(before);
if (numDeleted > 0) {
s_logger.info("Ovs cleanup deleted " + numDeleted + " finished work items older than " + before.toString());
}
}
private void cleanupUnfinishedWork() {
Date before = new Date(System.currentTimeMillis() - 30*1000l);
List<OvsWorkVO> unfinished = _workDao.findUnfinishedWork(before);
if (unfinished.size() > 0) {
s_logger.info("Ovscleanup found " + unfinished.size() + " unfinished work items older than " + before.toString());
Set<Long> affectedVms = new HashSet<Long>();
for (OvsWorkVO work: unfinished) {
affectedVms.add(work.getInstanceId());
}
s_logger.info("Ovs cleanup re-schedule unfinished work");
scheduleFlowUpdateToHosts(affectedVms, false, null);
} else {
s_logger.debug("Ovs cleanup found no unfinished work items older than " + before.toString());
}
}
//TODO: think about lock, how new VM start when we change rows
@DB
public void work() {
if (s_logger.isTraceEnabled()) {
s_logger.trace("Checking the database");
}
final OvsWorkVO work = _workDao.take(_serverId);
if (work == null) {
return;
}
Long userVmId = work.getInstanceId();
VirtualMachine vm = null;
Long seqnum = null;
Long vmId = work.getInstanceId();
s_logger.info("Ovs working on " + work.toString());
final Transaction txn = Transaction.currentTxn();
txn.start();
try {
vm = _userVMDao.acquireInLockTable(vmId);
if (vm == null) {
vm = _routerDao.acquireInLockTable(vmId);
if (vm == null) {
s_logger.warn("Ovs unable to acquire lock on vm id=" + userVmId);
return ;
}
}
Long agentId = null;
VmFlowLogVO log = _flowLogDao.findByVmId(userVmId);
if (log == null) {
s_logger.warn("Ovs cannot find log record for vm id=" + userVmId);
return;
}
seqnum = log.getLogsequence();
if (vm != null && vm.getState() == State.Running) {
agentId = vm.getHostId();
if (agentId != null ) {
String vlans = getVlanInPortMapping(vm.getAccountId(), vm.getHostId());
String tag = Long.toString(_vlanMappingDao.findByAccountIdAndHostId(
vm.getAccountId(), vm.getHostId()).getVlan());
Commands cmds = new Commands(new OvsSetTagAndFlowCommand(
vm.getHostName(), tag, vlans, seqnum.toString(),
vm.getId()));
try {
_agentMgr.send(agentId, cmds, _ovsListener);
} catch (AgentUnavailableException e) {
s_logger.debug("Unable to send updates for vm: "
+ userVmId + "(agentid=" + agentId + ")");
_workDao.updateStep(work.getInstanceId(), seqnum,
Step.Done);
}
}
}
} finally {
if (vm != null) {
if (vm.getType() == VirtualMachine.Type.User) {
_userVMDao.releaseFromLockTable(vmId);
} else if (vm.getType() == VirtualMachine.Type.DomainRouter) {
_routerDao.releaseFromLockTable(vmId);
} else {
assert 1 == 0 : "Should not be here";
}
_workDao.updateStep(work.getId(), Step.Done);
}
txn.commit();
}
}
@DB
protected long askVlanId(long accountId, long hostId) throws OvsVlanExhaustedException {
assert _isEnabled : "Who call me ??? while OvsNetwokr is not enabled!!!";
final Transaction txn = Transaction.currentTxn();
txn.start();
VlanMappingVO currVlan = _vlanMappingDao.lockByAccountIdAndHostId(accountId, hostId);
long vlan = 0;
if (currVlan != null) {
vlan = currVlan.getVlan();
currVlan.ref();
_vlanMappingDao.update(currVlan.getId(), currVlan);
s_logger.debug("Already has an Vlan " + vlan + " on host " + hostId
+ " for account " + accountId + ", use it, reference count is " + currVlan.getRef());
txn.commit();
return vlan;
}
List<VlanMappingVO>mappings = _vlanMappingDao.listByHostId(hostId);
assert mappings.size() > 0: "where is my data!? it should be added when host connected!";
VlanMappingVO target = null;
for (VlanMappingVO vo : mappings) {
if (vo.getAccountId() == 0) {
target = _vlanMappingDao.lockRow(vo.getId(), true);
if (target == null || target.getAccountId() != 0) {
s_logger.debug("Someone took vlan mapping host = "
+ vo.getHostId() + " vlan = " + vo.getVlan());
continue;
} else {
break;
}
}
}
if (target == null) {
throw new OvsVlanExhaustedException("vlan exhausted on host " + hostId);
}
target.setAccountId(accountId);
target.ref();
_vlanMappingDao.update(target.getId(), target);
_vlanMappingDirtyDao.markDirty(accountId);
String s = String.format("allocate a new vlan %1$s(account:%2$s, hostId:%3$s), mark dirty",
vlan, accountId, hostId);
s_logger.debug("OVSDIRTY:" + s);
txn.commit();
return target.getVlan();
}
private void handleCreateTunnelAnswer(Answer[] answers) throws GreTunnelException {
OvsCreateGreTunnelAnswer r = (OvsCreateGreTunnelAnswer) answers[0];
String s = String.format(
"(hostIP:%1$s, remoteIP:%2$s, bridge:%3$s, greKey:%4$s)",
r.getHostIp(), r.getRemoteIp(), r.getBridge(), r.getKey());
if (!r.getResult()) {
s_logger.warn("Create GRE tunnel failed due to " + r.getDetails()
+ s);
} else {
GreTunnelVO tunnel = _tunnelDao.getByFromAndTo(r.getFrom(), r.getTo());
if (tunnel == null) {
throw new GreTunnelException("No record matches from = "
+ r.getFrom() + " to = " + r.getTo());
} else {
tunnel.setInPort(r.getPort());
_tunnelDao.update(tunnel.getId(), tunnel);
s_logger.info("Create GRE tunnel success" + s + " from "
+ r.getFrom() + " to " + r.getTo() + " inport="
+ r.getPort());
}
}
}
@DB
protected void CheckAndCreateTunnel(VirtualMachine instance,
DeployDestination dest) throws GreTunnelException {
if (!_isEnabled) {
return;
}
if (instance.getType() != VirtualMachine.Type.User
&& instance.getType() != VirtualMachine.Type.DomainRouter) {
return;
}
final Transaction txn = Transaction.currentTxn();
long hostId = dest.getHost().getId();
long accountId = instance.getAccountId();
List<UserVmVO>vms = _userVmDao.listByAccountId(accountId);
List<DomainRouterVO> routers = _routerDao.findBy(accountId, instance.getDataCenterIdToDeployIn());
List<VMInstanceVO>ins = new ArrayList<VMInstanceVO>();
ins.addAll(vms);
ins.addAll(routers);
List<Long>toHostIds = new ArrayList<Long>();
List<Long>fromHostIds = new ArrayList<Long>();
for (VMInstanceVO v : ins) {
Long rh = v.getHostId();
if (rh == null || rh.longValue() == hostId) {
continue;
}
txn.start();
GreTunnelVO tunnel = _tunnelDao.lockByFromAndTo(hostId,
rh.longValue());
txn.commit();
if (tunnel == null) {
throw new GreTunnelException(String.format(
"No entity(from=%1$s, to=%2$s) of failed to lock",
hostId, rh.longValue()));
}
if (tunnel.getInPort() == 0 && !toHostIds.contains(rh)) {
toHostIds.add(rh);
}
txn.start();
tunnel = _tunnelDao.lockByFromAndTo(rh.longValue(), hostId);
txn.commit();
if (tunnel == null) {
throw new GreTunnelException(String.format(
"No entity(from=%1$s, to=%2$s) of failed to lock",
rh.longValue(), hostId));
}
if (tunnel.getInPort() == 0 && !fromHostIds.contains(rh)) {
fromHostIds.add(rh);
}
}
try {
String myIp = dest.getHost().getPrivateIpAddress();
for (Long i : toHostIds) {
HostVO rHost = _hostDao.findById(i.longValue());
Commands cmds = new Commands(
new OvsCreateGreTunnelCommand(
rHost.getPrivateIpAddress(), "1", hostId,
i.longValue()));
s_logger.debug("Ask host " + hostId + " to create gre tunnel to " + i.longValue());
Answer[] answers = _agentMgr.send(hostId, cmds);
handleCreateTunnelAnswer(answers);
}
for (Long i : fromHostIds) {
Commands cmd2s = new Commands(new OvsCreateGreTunnelCommand(myIp, "1", i.longValue(), hostId));
s_logger.debug("Ask host " + i.longValue() + " to create gre tunnel to " + hostId);
Answer[] answers = _agentMgr.send(i.longValue(), cmd2s);
handleCreateTunnelAnswer(answers);
}
} catch (Exception e) {
s_logger.warn("Ovs vlan remap network creates tunnel failed", e);
}
}
@DB
protected String getVlanInPortMapping(long accountId, long from) {
List<GreTunnelVO> tunnels = _tunnelDao.getByFrom(from);
if (tunnels.size() == 0) {
return "[]";
} else {
List<String> maps = new ArrayList<String>();
for (GreTunnelVO t : tunnels) {
VlanMappingVO m = _vlanMappingDao.findByAccountIdAndHostId(accountId, t.getTo());
if (m == null) {
s_logger.debug("Host " + t.getTo() + " has no VM for account " + accountId + ", skip it");
continue;
}
String s = String.format("%1$s:%2$s", m.getVlan(), t.getInPort());
maps.add(s);
}
return maps.toString();
}
}
private String cmdPair(String key, String value) {
return String.format("%1$s;%2$s", key, value);
}
@Override
public String applyDefaultFlow(VirtualMachine instance, DeployDestination dest) {
if (!_isEnabled) {
return null;
}
VirtualMachine.Type vmType = instance.getType();
if (vmType != VirtualMachine.Type.User
&& vmType != VirtualMachine.Type.DomainRouter) {
return null;
}
try {
long hostId = instance.getHostId();
long accountId = instance.getAccountId();
String tag = Long.toString(askVlanId(accountId, hostId));
CheckAndUpdateDhcpFlow(instance);
String vlans = getVlanInPortMapping(accountId, hostId);
VmFlowLogVO log = _flowLogDao.findOrNewByVmId(instance.getId(),
instance.getHostName());
StringBuffer command = new StringBuffer();
command.append("vlan");
command.append("/");
command.append(cmdPair("vmName", instance.getHostName()));
command.append("/");
command.append(cmdPair("tag", tag));
command.append("/");
vlans = vlans.replace("[", "@");
vlans = vlans.replace("]", "#");
command.append(cmdPair("vlans", vlans));
command.append("/");
command.append(cmdPair("seqno", Long.toString(log.getLogsequence())));
command.append("/");
command.append(cmdPair("vmId", Long.toString(instance.getId())));
return command.toString();
} catch (OvsVlanExhaustedException e) {
s_logger.warn("vlan exhaused on host " + instance.getHostId(), e);
return null;
}
}
//FIXME: if router has record in database but not start, this will hang 10 secs due to host
//plugin cannot found vif for router.
protected void CheckAndUpdateDhcpFlow(VirtualMachine instance) {
if (!_isEnabled) {
return;
}
if (instance.getType() == VirtualMachine.Type.DomainRouter) {
return;
}
long accountId = instance.getAccountId();
List<DomainRouterVO> routers = _routerDao.findBy(accountId, instance.getDataCenterIdToDeployIn());
if (routers.size() == 0) {
return;
}
if (!_vlanMappingDirtyDao.isDirty(accountId)) {
return;
}
for (DomainRouterVO router : routers) {
try {
long hostId = router.getHostId();
String tag = Long.toString(_vlanMappingDao.findByAccountIdAndHostId(accountId, hostId).getVlan());
VmFlowLogVO log = _flowLogDao.findOrNewByVmId(instance.getId(), instance.getHostName());
String vlans = getVlanInPortMapping(accountId, hostId);
s_logger.debug("ask router " + router.getHostName() + " on host "
+ hostId + " update vlan map to " + vlans);
Commands cmds = new Commands(new OvsSetTagAndFlowCommand(
router.getHostName(), tag, vlans, Long.toString(log.getLogsequence()), instance.getId()));
_agentMgr.send(router.getHostId(), cmds, _ovsListener);
} catch (Exception e) {
s_logger.warn("apply flow to router failed", e);
}
}
}
@DB
@Override
public void scheduleFlowUpdateToHosts(Set<Long> affectedVms, boolean updateSeqno, Long delayMs) {
if (!_isEnabled) {
return;
}
if (affectedVms == null) {
return;
}
if (delayMs == null) {
delayMs = new Long(100l);
}
for (Long vmId: affectedVms) {
Transaction txn = Transaction.currentTxn();
txn.start();
VmFlowLogVO log = null;
OvsWorkVO work = null;
VirtualMachine vm = null;
try {
vm = _userVMDao.acquireInLockTable(vmId);
if (vm == null) {
vm = _routerDao.acquireInLockTable(vmId);
if (vm == null) {
s_logger.warn("Ovs failed to acquire lock on vm id " + vmId);
continue;
}
}
log = _flowLogDao.findOrNewByVmId(vmId, vm.getHostName());
if (log != null && updateSeqno){
log.incrLogsequence();
_flowLogDao.update(log.getId(), log);
}
work = _workDao.findByVmIdStep(vmId, Step.Scheduled);
if (work == null) {
work = new OvsWorkVO(vmId, null, null, OvsWorkVO.Step.Scheduled, null);
work = _workDao.persist(work);
}
work.setLogsequenceNumber(log.getLogsequence());
_workDao.update(work.getId(), work);
} finally {
if (vm != null) {
if (vm.getType() == VirtualMachine.Type.User) {
_userVMDao.releaseFromLockTable(vmId);
} else if (vm.getType() == VirtualMachine.Type.DomainRouter) {
_routerDao.releaseFromLockTable(vmId);
} else {
assert 1 == 0 : "Should not be here";
}
}
}
txn.commit();
_executorPool.schedule(new WorkerThread(), delayMs, TimeUnit.MILLISECONDS);
}
}
protected Set<Long> getAffectedVms(VMInstanceVO instance, boolean tellRouter) {
long accountId = instance.getAccountId();
if (!_vlanMappingDirtyDao.isDirty(accountId)) {
s_logger.debug("OVSAFFECTED: no VM affected by " + instance.getHostName());
return null;
}
Set<Long> affectedVms = new HashSet<Long>();
List<UserVmVO> vms = _userVmDao.listByAccountId(accountId);
for (UserVmVO vm : vms) {
affectedVms.add(new Long(vm.getId()));
}
if (tellRouter && instance.getType() != VirtualMachine.Type.DomainRouter) {
List<DomainRouterVO> routers = _routerDao.findBy(accountId, instance.getDataCenterIdToDeployIn());
for (DomainRouterVO router : routers) {
if (router != null) {
affectedVms.add(new Long(router.getId()));
}
}
}
return affectedVms;
}
protected void handleVmStateChange(VMInstanceVO instance, boolean tellRouter) {
Set<Long> affectedVms = getAffectedVms(instance, tellRouter);
scheduleFlowUpdateToHosts(affectedVms, true, null);
_vlanMappingDirtyDao.clean(instance.getAccountId());
s_logger.debug("OVSDIRTY:Clean dirty for account " + instance.getAccountId());
}
@DB
protected void checkAndRemove(VMInstanceVO instance) {
long accountId = instance.getAccountId();
long hostId = instance.getHostId();
final Transaction txn = Transaction.currentTxn();
txn.start();
VlanMappingVO vo = _vlanMappingDao.lockByAccountIdAndHostId(accountId, hostId);
assert vo!=null: "Why there is no record for account " + accountId + " host " + hostId;
if (vo.unref() == 0) {
vo.setAccountId(0);
_vlanMappingDirtyDao.markDirty(accountId);
String s = String.format("%1$s is the last VM(host:%2$s, accountId:%3$s), remove vlan",
instance.getHostName(), hostId, accountId);
s_logger.debug("OVSDIRTY:" + s);
} else {
s_logger.debug(instance.getHostName()
+ " reduces reference count of (account,host) = ("
+ accountId + "," + hostId + ") to " + vo.getRef());
}
_vlanMappingDao.update(vo.getId(), vo);
_flowLogDao.deleteByVmId(instance.getId());
txn.commit();
try {
Commands cmds = new Commands(new OvsDeleteFlowCommand(instance.getHostName()));
_agentMgr.send(hostId, cmds, _ovsListener);
} catch (Exception e) {
s_logger.warn("remove flow failed", e);
}
}
@Override
public void handleVmStateTransition(VMInstanceVO instance, State vmState) {
if (!_isEnabled) {
return;
}
switch (vmState) {
case Destroyed:
case Error:
case Migrating:
case Expunging:
case Starting:
case Unknown:
return;
case Running:
handleVmStateChange(instance, false);
break;
case Stopping:
case Stopped:
checkAndRemove(instance);
handleVmStateChange(instance, true);
break;
}
}
@Override
public void VmCheckAndCreateTunnel(VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest) {
try {
CheckAndCreateTunnel(vm.getVirtualMachine(), dest);
} catch (Exception e) {
s_logger.warn("create gre tunnel failed", e);
}
}
@Override
public void fullSync(List<Pair<String, Long>> states) {
if (!_isEnabled) {
return;
}
//TODO:debug code, remove in future
List<AccountVO> accounts = _accountDao.listAll();
for (AccountVO acnt : accounts) {
if (_vlanMappingDirtyDao.isDirty(acnt.getId())) {
s_logger.warn("Vlan mapping for account "
+ acnt.getAccountName() + " id " + acnt.getId()
+ " is dirty");
}
}
if (states.size() ==0) {
s_logger.info("Nothing to do, Ovs fullsync is happy");
return;
}
Set<Long>vmIds = new HashSet<Long>();
for (Pair<String, Long>state : states) {
if (state.second() == -1) {
s_logger.warn("Ovs fullsync get wrong seqno for " + state.first());
continue;
}
VmFlowLogVO log = _flowLogDao.findByName(state.first());
if (log.getLogsequence() != state.second()) {
s_logger.debug("Ovs fullsync detected unmatch seq number for " + state.first() + ", run sync");
VMInstanceVO vo = _instanceDao.findById(log.getInstanceId());
if (vo == null) {
s_logger.warn("Ovs can't find " + state.first() + " in vm_instance!");
continue;
}
if (vo.getType() != VirtualMachine.Type.User && vo.getType() != VirtualMachine.Type.DomainRouter) {
s_logger.warn("Ovs fullsync: why we sync a " + vo.getType().toString() + " VM???");
continue;
}
vmIds.add(new Long(vo.getId()));
}
}
if (vmIds.size() > 0) {
scheduleFlowUpdateToHosts(vmIds, false, null);
}
}
}

View File

@ -1,139 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs;
import java.util.List;
import javax.persistence.EntityExistsException;
import org.apache.log4j.Logger;
import com.cloud.agent.Listener;
import com.cloud.agent.api.AgentControlAnswer;
import com.cloud.agent.api.AgentControlCommand;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.StartupCommand;
import com.cloud.exception.ConnectionException;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.dao.HostDao;
import com.cloud.network.Network.GuestType;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkVO;
import com.cloud.network.ovs.dao.GreTunnelVO;
import com.cloud.network.ovs.dao.OvsTunnelDao;
import com.cloud.network.ovs.dao.OvsTunnelVO;
import com.cloud.resource.ResourceManager;
import com.cloud.utils.component.ComponentLocator;
public class OvsTunnelListener implements Listener {
public static final Logger s_logger = Logger.getLogger(OvsListener.class.getName());
HostDao _hostDao;
OvsTunnelDao _tunnelDao;
ResourceManager _resourceMgr;
NetworkManager _networkMgr;
public OvsTunnelListener(OvsTunnelDao tunnelDao, HostDao hostDao) {
this._hostDao = hostDao;
this._tunnelDao = tunnelDao;
ComponentLocator locator = ComponentLocator.getLocator("management-server");
_resourceMgr = locator.getManager(ResourceManager.class);
_networkMgr = locator.getManager(NetworkManager.class);
}
@Override
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
return true;
}
@Override
public boolean processCommands(long agentId, long seq, Command[] commands) {
// TODO Auto-generated method stub
return true;
}
@Override
public AgentControlAnswer processControlCommand(long agentId,
AgentControlCommand cmd) {
return null;
}
@Override
public void processConnect(HostVO host, StartupCommand cmd, boolean forRebalance)
throws ConnectionException {
if (host.getType() != Host.Type.Routing) {
return;
}
//try {
//List<HostVO> hosts = _resourceMgr.listAllHostsInAllZonesByType(Host.Type.Routing);
// NOTE: Trying to semplfy things by removing tunnel pre-allocation
//List<NetworkVO> networks = _networkMgr.listAllNetworksInAllZonesByType(GuestType.Isolated);
//for (HostVO h : hosts) {
// if (h.getId() == host.getId()) {
// continue;
// }
//
// OvsTunnelVO t = _tunnelDao.getByFromAndTo(host.getId(), h.getId());
// if (t == null) {
// t = new OvsTunnelVO(host.getId(), h.getId());
// try {
// _tunnelDao.persist(t);
// } catch (EntityExistsException e) {
// s_logger.debug(String.format("Already has (from=%1$s, to=%2$s)", host.getId(), h.getId()));
// }
// }
//
// t = _tunnelDao.getByFromAndTo(h.getId(), host.getId());
// if (t == null) {
// t = new OvsTunnelVO(h.getId(), host.getId());
// try {
// _tunnelDao.persist(t);
// } catch (EntityExistsException e) {
// s_logger.debug(String.format("Already has (from=%1$s, to=%2$s)", h.getId(), host.getId()));
// }
// }
//}
//} catch (Exception e) {
//e.printStackTrace();
//}
}
@Override
public boolean processDisconnect(long agentId, Status state) {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isRecurring() {
// TODO Auto-generated method stub
return false;
}
@Override
public int getTimeout() {
// TODO Auto-generated method stub
return -1;
}
@Override
public boolean processTimeout(long agentId, long seq) {
// TODO Auto-generated method stub
return true;
}
}

View File

@ -1,23 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import java.util.List;
import com.cloud.utils.db.GenericDao;
public interface GreTunnelDao extends GenericDao<GreTunnelVO, Long> {
List<GreTunnelVO> getByFrom(long from);
GreTunnelVO getByFromAndTo(long from, long To);
GreTunnelVO lockByFromAndTo(long from, long to);
}

View File

@ -1,64 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import java.util.List;
import javax.ejb.Local;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
@Local(value = { GreTunnelDao.class })
public class GreTunnelDaoImpl extends GenericDaoBase<GreTunnelVO, Long>
implements GreTunnelDao {
protected final SearchBuilder<GreTunnelVO> fromSearch;
protected final SearchBuilder<GreTunnelVO> fromToSearch;
public GreTunnelDaoImpl() {
fromSearch = createSearchBuilder();
fromSearch.and("from", fromSearch.entity().getFrom(), Op.EQ);
fromSearch.done();
fromToSearch = createSearchBuilder();
fromToSearch.and("from", fromToSearch.entity().getFrom(), Op.EQ);
fromToSearch.and("to", fromToSearch.entity().getTo(), Op.EQ);
fromToSearch.done();
}
@Override
public List<GreTunnelVO> getByFrom(long from) {
SearchCriteria<GreTunnelVO> sc = fromSearch.create();
sc.setParameters("from", from);
return listBy(sc, null);
}
@Override
public GreTunnelVO getByFromAndTo(long from, long to) {
SearchCriteria<GreTunnelVO> sc = fromToSearch.create();
sc.setParameters("from", from);
sc.setParameters("to", to);
return findOneBy(sc);
}
@Override
public GreTunnelVO lockByFromAndTo(long from, long to) {
SearchCriteria<GreTunnelVO> sc = fromToSearch.create();
sc.setParameters("from", from);
sc.setParameters("to", to);
return lockOneRandomRow(sc, true);
}
}

View File

@ -1,76 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name=("ovs_tunnel_alloc"))
public class GreTunnelVO {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
@Column(name = "from")
private long from;
@Column(name = "to")
private long to;
@Column(name = "in_port")
private int inPort;
public GreTunnelVO() {
}
public GreTunnelVO(long from, long to) {
this.from = from;
this.to = to;
this.inPort = 0;
}
public GreTunnelVO(long id, long from, long to) {
this.from = from;
this.to = to;
this.inPort = 0;
this.id = id;
}
public void setInPort(int port) {
inPort = port;
}
public long getFrom() {
return from;
}
public long getTo() {
return to;
}
public int getInPort() {
return inPort;
}
public long getId() {
return id;
}
}

View File

@ -1,21 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import com.cloud.utils.db.GenericDao;
public interface OvsTunnelDao extends GenericDao<OvsTunnelVO, Long> {
OvsTunnelVO lockByFromAndTo(long from, long to);
OvsTunnelVO getByFromAndTo(long from, long to);
int askKey(long from, long to);
}

View File

@ -1,71 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import javax.ejb.Local;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.db.SearchCriteria.Op;
@Local(value = { OvsTunnelDao.class })
public class OvsTunnelDaoImpl extends GenericDaoBase<OvsTunnelVO, Long>
implements OvsTunnelDao {
protected final SearchBuilder<OvsTunnelVO> fromToSearch;
public OvsTunnelDaoImpl() {
fromToSearch = createSearchBuilder();
fromToSearch.and("from", fromToSearch.entity().getFrom(), Op.EQ);
fromToSearch.and("to", fromToSearch.entity().getTo(), Op.EQ);
fromToSearch.done();
}
@Override
public OvsTunnelVO lockByFromAndTo(long from, long to) {
SearchCriteria<OvsTunnelVO> sc = fromToSearch.create();
sc.setParameters("from", from);
sc.setParameters("to", to);
return lockOneRandomRow(sc, true);
}
@Override
@DB
public int askKey(long from, long to) {
int key = -1;
final Transaction txn = Transaction.currentTxn();
txn.start();
OvsTunnelVO t = lockByFromAndTo(from, to);
if (t != null) {
key = t.getKey();
t.setKey(key+1);
update(t.getId(), t);
}
txn.commit();
return key;
}
@Override
public OvsTunnelVO getByFromAndTo(long from, long to) {
SearchCriteria<OvsTunnelVO> sc = fromToSearch.create();
sc.setParameters("from", from);
sc.setParameters("to", to);
return findOneBy(sc);
}
}

View File

@ -1,76 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name=("ovs_tunnel"))
public class OvsTunnelVO {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
@Column(name = "from")
private long from;
@Column(name = "to")
private long to;
@Column(name = "key")
private int key;
public OvsTunnelVO() {
}
public OvsTunnelVO(long from, long to) {
this.from = from;
this.to = to;
this.key = 0;
}
public OvsTunnelVO(long id, long from, long to) {
this.from = from;
this.to = to;
this.key = 0;
this.id = id;
}
public void setKey(int key) {
this.key = key;
}
public long getFrom() {
return from;
}
public long getTo() {
return to;
}
public int getKey() {
return key;
}
public long getId() {
return id;
}
}

View File

@ -1,35 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import java.util.Date;
import java.util.List;
import com.cloud.network.ovs.dao.OvsWorkVO.Step;
import com.cloud.utils.db.GenericDao;
public interface OvsWorkDao extends GenericDao<OvsWorkVO, Long> {
OvsWorkVO findByVmId(long vmId, boolean taken);
OvsWorkVO findByVmIdStep(long vmId, Step step);
OvsWorkVO take(long serverId);
void updateStep(Long vmId, Long logSequenceNumber, Step done);
void updateStep(Long workId, Step done);
int deleteFinishedWork(Date timeBefore);
List<OvsWorkVO> findUnfinishedWork(Date timeBefore);
}

View File

@ -1,199 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import java.util.Date;
import java.util.List;
import javax.ejb.Local;
import com.cloud.ha.HaWorkVO;
import com.cloud.network.ovs.dao.OvsWorkVO.Step;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
@Local(value={OvsWorkDao.class})
public class OvsWorkDaoImpl extends GenericDaoBase<OvsWorkVO, Long> implements
OvsWorkDao {
private SearchBuilder<OvsWorkVO> VmIdTakenSearch;
private SearchBuilder<OvsWorkVO> VmIdSeqNumSearch;
private SearchBuilder<OvsWorkVO> VmIdUnTakenSearch;
private SearchBuilder<OvsWorkVO> UntakenWorkSearch;
private SearchBuilder<OvsWorkVO> VmIdStepSearch;
private SearchBuilder<OvsWorkVO> CleanupSearch;
protected OvsWorkDaoImpl() {
VmIdTakenSearch = createSearchBuilder();
VmIdTakenSearch.and("vmId", VmIdTakenSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
VmIdTakenSearch.and("taken", VmIdTakenSearch.entity().getDateTaken(), SearchCriteria.Op.NNULL);
VmIdTakenSearch.done();
VmIdUnTakenSearch = createSearchBuilder();
VmIdUnTakenSearch.and("vmId", VmIdUnTakenSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
VmIdUnTakenSearch.and("taken", VmIdUnTakenSearch.entity().getDateTaken(), SearchCriteria.Op.NULL);
VmIdUnTakenSearch.done();
UntakenWorkSearch = createSearchBuilder();
UntakenWorkSearch.and("server", UntakenWorkSearch.entity().getServerId(), SearchCriteria.Op.NULL);
UntakenWorkSearch.and("taken", UntakenWorkSearch.entity().getDateTaken(), SearchCriteria.Op.NULL);
UntakenWorkSearch.and("step", UntakenWorkSearch.entity().getStep(), SearchCriteria.Op.EQ);
UntakenWorkSearch.done();
VmIdSeqNumSearch = createSearchBuilder();
VmIdSeqNumSearch.and("vmId", VmIdSeqNumSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
VmIdSeqNumSearch.and("seqno", VmIdSeqNumSearch.entity().getLogsequenceNumber(), SearchCriteria.Op.EQ);
VmIdSeqNumSearch.done();
VmIdStepSearch = createSearchBuilder();
VmIdStepSearch.and("vmId", VmIdStepSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
VmIdStepSearch.and("step", VmIdStepSearch.entity().getStep(), SearchCriteria.Op.EQ);
VmIdStepSearch.done();
CleanupSearch = createSearchBuilder();
CleanupSearch.and("taken", CleanupSearch.entity().getDateTaken(), Op.LTEQ);
CleanupSearch.and("step", CleanupSearch.entity().getStep(), SearchCriteria.Op.IN);
CleanupSearch.done();
}
@Override
public OvsWorkVO findByVmId(long vmId, boolean taken) {
SearchCriteria<OvsWorkVO> sc = taken?VmIdTakenSearch.create():VmIdUnTakenSearch.create();
sc.setParameters("vmId", vmId);
return findOneIncludingRemovedBy(sc);
}
@Override
@DB
public OvsWorkVO take(long serverId) {
final Transaction txn = Transaction.currentTxn();
try {
final SearchCriteria<OvsWorkVO> sc = UntakenWorkSearch.create();
sc.setParameters("step", Step.Scheduled);
final Filter filter = new Filter(OvsWorkVO.class, null, true, 0l, 1l);//FIXME: order desc by update time?
txn.start();
final List<OvsWorkVO> vos = lockRows(sc, filter, true);
if (vos.size() == 0) {
return null;
}
OvsWorkVO work = null;
for (OvsWorkVO w: vos) {
//ensure that there is no job in Processing state for the same VM
if ( findByVmIdStep(w.getInstanceId(), Step.Processing) == null) {
work = w;
break;
}
}
if (work == null) {
return null;
}
work.setServerId(serverId);
work.setDateTaken(new Date());
work.setStep(OvsWorkVO.Step.Processing);
update(work.getId(), work);
txn.commit();
return work;
} catch (final Throwable e) {
throw new CloudRuntimeException("Unable to execute take", e);
}
}
@Override
@DB
public void updateStep(Long vmId, Long logSequenceNumber, Step step) {
final Transaction txn = Transaction.currentTxn();
txn.start();
SearchCriteria<OvsWorkVO> sc = VmIdSeqNumSearch.create();
sc.setParameters("vmId", vmId);
sc.setParameters("seqno", logSequenceNumber);
final Filter filter = new Filter(HaWorkVO.class, null, true, 0l, 1l);
final List<OvsWorkVO> vos = lockRows(sc, filter, true);
if (vos.size() == 0) {
return;
}
OvsWorkVO work = vos.get(0);
work.setStep(step);
update(work.getId(), work);
txn.commit();
}
@Override
public OvsWorkVO findByVmIdStep(long vmId, Step step) {
SearchCriteria<OvsWorkVO> sc = VmIdStepSearch.create();
sc.setParameters("vmId", vmId);
sc.setParameters("step", step);
return findOneIncludingRemovedBy(sc);
}
@Override
@DB
public void updateStep(Long workId, Step step) {
final Transaction txn = Transaction.currentTxn();
txn.start();
OvsWorkVO work = lockRow(workId, true);
if (work == null) {
return;
}
work.setStep(step);
update(work.getId(), work);
txn.commit();
}
@Override
public int deleteFinishedWork(Date timeBefore) {
final SearchCriteria<OvsWorkVO> sc = CleanupSearch.create();
sc.setParameters("taken", timeBefore);
sc.setParameters("step", Step.Done);
return expunge(sc);
}
@Override
public List<OvsWorkVO> findUnfinishedWork(Date timeBefore) {
final SearchCriteria<OvsWorkVO> sc = CleanupSearch.create();
sc.setParameters("taken", timeBefore);
sc.setParameters("step", Step.Processing);
List<OvsWorkVO> result = listIncludingRemovedBy(sc);
OvsWorkVO work = createForUpdate();
work.setStep(Step.Error);
update(work, sc);
return result;
}
}

View File

@ -1,135 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import com.cloud.utils.db.GenericDao;
@Entity
@Table(name="ovs_work")
public class OvsWorkVO {
public enum Step {
Scheduled,
Processing,
Done,
Error
}
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private Long id;
@Column(name="instance_id", updatable=false, nullable=false)
private Long instanceId; // vm_instance id
@Column(name="mgmt_server_id", nullable=true)
private Long serverId;
@Column(name=GenericDao.CREATED_COLUMN)
private Date created;
@Column(name="step", nullable = false)
@Enumerated(value=EnumType.STRING)
private Step step;
@Column(name="taken", nullable=true)
@Temporal(value=TemporalType.TIMESTAMP)
private Date dateTaken;
@Column(name="seq_no", nullable=true)
private Long logsequenceNumber = null;
protected OvsWorkVO() {
}
public Long getId() {
return id;
}
public Long getInstanceId() {
return instanceId;
}
public Long getServerId() {
return serverId;
}
public void setServerId(final Long serverId) {
this.serverId = serverId;
}
public Date getCreated() {
return created;
}
public OvsWorkVO(Long instanceId, Long serverId, Date created,
Step step, Date dateTaken) {
super();
this.instanceId = instanceId;
this.serverId = serverId;
this.created = created;
this.step = step;
this.dateTaken = dateTaken;
}
@Override
public String toString() {
return new StringBuilder("[Ovs-Work:id=").append(id).append(":vm=").append(instanceId).append("]").toString();
}
public Date getDateTaken() {
return dateTaken;
}
public void setStep(Step step) {
this.step = step;
}
public Step getStep() {
return step;
}
public void setDateTaken(Date date) {
dateTaken = date;
}
public Long getLogsequenceNumber() {
return logsequenceNumber;
}
public void setLogsequenceNumber(Long logsequenceNumber) {
this.logsequenceNumber = logsequenceNumber;
}
}

View File

@ -1,31 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import java.util.List;
import com.cloud.utils.db.GenericDao;
public interface VlanMappingDao extends GenericDao<VlanMappingVO, Long> {
List<VlanMappingVO> listByAccountIdAndHostId(long accountId, long hostId);
List<VlanMappingVO> listByHostId(long hostId);
List<VlanMappingVO> listByAccountId(long accountId);
List<VlanMappingVO> lockByAccountId(long accoutnId);
VlanMappingVO findByAccountIdAndHostId(long accountId, long hostId);
VlanMappingVO lockByAccountIdAndHostId(long accountId, long hostId);
}

View File

@ -1,100 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import java.util.List;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
import javax.ejb.Local;
@Local(value = { VlanMappingDao.class })
public class VlanMappingDaoImpl extends GenericDaoBase<VlanMappingVO, Long>
implements VlanMappingDao {
protected final SearchBuilder<VlanMappingVO> accountIdSearch;
protected final SearchBuilder<VlanMappingVO> hostSearch;
protected final SearchBuilder<VlanMappingVO> accountHostSearch;
public VlanMappingDaoImpl() {
super();
accountHostSearch = createSearchBuilder();
accountHostSearch.and("host_id", accountHostSearch.entity().getHostId(), Op.EQ);
accountHostSearch.and("account_id", accountHostSearch.entity().getAccountId(), Op.EQ);
accountHostSearch.done();
accountIdSearch = createSearchBuilder();
accountIdSearch.and("account_id", accountIdSearch.entity().getAccountId(), Op.EQ);
accountIdSearch.done();
hostSearch = createSearchBuilder();
hostSearch.and("host_id", hostSearch.entity().getHostId(), Op.EQ);
hostSearch.done();
}
@Override
public List<VlanMappingVO> listByAccountIdAndHostId(long accountId,
long hostId) {
SearchCriteria<VlanMappingVO> sc = accountHostSearch.create();
sc.setParameters("account_id", accountId);
sc.setParameters("host_id", hostId);
return listBy(sc, null);
}
@Override
public List<VlanMappingVO> listByHostId(long hostId) {
SearchCriteria<VlanMappingVO> sc = hostSearch.create();
sc.setParameters("host_id", hostId);
return listBy(sc, null);
}
@Override
public List<VlanMappingVO> listByAccountId(long accountId) {
SearchCriteria<VlanMappingVO> sc = accountIdSearch.create();
sc.setParameters("account_id", accountId);
return listBy(sc, null);
}
@Override
public VlanMappingVO findByAccountIdAndHostId(long accountId, long hostId) {
return getByAccountIdAndHostId(accountId, hostId, false);
}
@Override
public List<VlanMappingVO> lockByAccountId(long accountId) {
SearchCriteria<VlanMappingVO> sc = accountIdSearch.create();
sc.setParameters("account_id", accountId);
return lockRows(sc, null, true);
}
@Override
public VlanMappingVO lockByAccountIdAndHostId(long accountId, long hostId) {
return getByAccountIdAndHostId(accountId, hostId, true);
}
private VlanMappingVO getByAccountIdAndHostId(long accountId, long hostId, boolean lock) {
SearchCriteria<VlanMappingVO> sc = accountHostSearch.create();
sc.setParameters("account_id", accountId);
sc.setParameters("host_id", hostId);
if (!lock) {
return findOneBy(sc);
} else {
return lockOneRandomRow(sc, true);
}
}
}

View File

@ -1,21 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import com.cloud.utils.db.GenericDao;
public interface VlanMappingDirtyDao extends GenericDao<VlanMappingDirtyVO, Long> {
public boolean isDirty(long accountId);
public void markDirty(long accountId);
public void clean(long accountId);
}

View File

@ -1,73 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import javax.ejb.Local;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
@Local(value = { VlanMappingDirtyDao.class })
public class VlanMappingDirtyDaoImpl extends
GenericDaoBase<VlanMappingDirtyVO, Long> implements VlanMappingDirtyDao {
protected final SearchBuilder<VlanMappingDirtyVO> AccountIdSearch;
public VlanMappingDirtyDaoImpl() {
super();
AccountIdSearch = createSearchBuilder();
AccountIdSearch.and("account_id", AccountIdSearch.entity().getAccountId(), Op.EQ);
AccountIdSearch.done();
}
@Override
public boolean isDirty(long accountId) {
SearchCriteria<VlanMappingDirtyVO> sc = AccountIdSearch.create();
sc.setParameters("account_id", accountId);
VlanMappingDirtyVO vo = findOneBy(sc);
if (vo == null) {
return false;
}
return vo.isDirty();
}
@Override
public void markDirty(long accountId) {
SearchCriteria<VlanMappingDirtyVO> sc = AccountIdSearch.create();
sc.setParameters("account_id", accountId);
VlanMappingDirtyVO vo = findOneBy(sc);
if (vo == null) {
vo = new VlanMappingDirtyVO(accountId, true);
persist(vo);
} else {
vo.markDirty();
update(vo, sc);
}
}
@Override
public void clean(long accountId) {
SearchCriteria<VlanMappingDirtyVO> sc = AccountIdSearch.create();
sc.setParameters("account_id", accountId);
VlanMappingDirtyVO vo = findOneBy(sc);
if (vo == null) {
vo = new VlanMappingDirtyVO(accountId, false);
persist(vo);
} else {
vo.clean();
update(vo, sc);
}
}
}

View File

@ -1,67 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name=("ovs_vlan_mapping_dirty"))
public class VlanMappingDirtyVO {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
@Column(name = "dirty")
private boolean dirty;
@Column(name = "account_id")
private long accountId;
public VlanMappingDirtyVO() {
}
public VlanMappingDirtyVO(long accountId, boolean dirty) {
this.accountId = accountId;
this.dirty = dirty;
}
public long getId() {
return id;
}
public long getAccountId() {
return accountId;
}
public boolean isDirty() {
return dirty;
}
public void setDirty(boolean dirty) {
this.dirty = dirty;
}
public void markDirty() {
setDirty(true);
}
public void clean() {
setDirty(false);
}
}

View File

@ -1,91 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Column;
@Entity
@Table(name=("ovs_host_vlan_alloc"))
public class VlanMappingVO {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
@Column(name = "host_id")
private long hostId;
@Column(name = "account_id")
private long accountId;
@Column(name = "vlan")
private long vlan;
@Column(name = "ref")
int ref;
public VlanMappingVO(long accountId, long hostId, long vlan) {
this.hostId = hostId;
this.accountId = accountId;
this.vlan = vlan;
this.ref = 0;
}
public VlanMappingVO() {
}
public long getHostId() {
return hostId;
}
public long getAccountId() {
return accountId;
}
public void setAccountId(long accountId) {
this.accountId = accountId;
}
public long getVlan() {
return vlan;
}
public long getId() {
return id;
}
public int getRef() {
return ref;
}
public void setRef(int ref) {
this.ref = ref;
}
public void ref() {
ref++;
setRef(ref);
}
public int unref() {
ref--;
setRef(ref);
return getRef();
}
}

View File

@ -1,22 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import com.cloud.utils.db.GenericDao;
public interface VmFlowLogDao extends GenericDao<VmFlowLogVO, Long> {
VmFlowLogVO findByVmId(long vmId);
VmFlowLogVO findOrNewByVmId(long vmId, String name);
VmFlowLogVO findByName(String name);
void deleteByVmId(long vmId);
}

View File

@ -1,69 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import javax.ejb.Local;
@Local(value={VmFlowLogDao.class})
public class VmFlowLogDaoImpl extends GenericDaoBase<VmFlowLogVO, Long>
implements VmFlowLogDao {
private SearchBuilder<VmFlowLogVO> VmIdSearch;
private SearchBuilder<VmFlowLogVO> VmNameSearch;
@Override
public VmFlowLogVO findByVmId(long vmId) {
SearchCriteria<VmFlowLogVO> sc = VmIdSearch.create();
sc.setParameters("vmId", vmId);
return findOneIncludingRemovedBy(sc);
}
protected VmFlowLogDaoImpl() {
VmIdSearch = createSearchBuilder();
VmIdSearch.and("vmId", VmIdSearch.entity().getInstanceId(),
SearchCriteria.Op.EQ);
VmIdSearch.done();
VmNameSearch = createSearchBuilder();
VmNameSearch.and("name", VmNameSearch.entity().getName(),
SearchCriteria.Op.EQ);
VmNameSearch.done();
}
@Override
public VmFlowLogVO findOrNewByVmId(long vmId, String name) {
VmFlowLogVO log = findByVmId(vmId);
if (log == null) {
log = new VmFlowLogVO(vmId, name);
log = persist(log);
}
return log;
}
@Override
public void deleteByVmId(long vmId) {
SearchCriteria<VmFlowLogVO> sc = VmIdSearch.create();
sc.setParameters("vmId", vmId);
expunge(sc);
}
@Override
public VmFlowLogVO findByName(String name) {
SearchCriteria<VmFlowLogVO> sc = VmNameSearch.create();
sc.setParameters("name", name);
return findOneIncludingRemovedBy(sc);
}
}

View File

@ -1,79 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.ovs.dao;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.cloud.utils.db.GenericDao;
@Entity
@Table(name="ovs_vm_flow_log")
public class VmFlowLogVO {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private Long id;
@Column(name="instance_id", updatable=false, nullable=false)
private Long instanceId; // vm_instance id
@Column(name=GenericDao.CREATED_COLUMN)
private Date created;
@Column(name="logsequence")
long logsequence;
@Column(name="vm_name", updatable=false, nullable=false, length=255)
protected String name = null;
protected VmFlowLogVO() {
}
public VmFlowLogVO(Long instanceId, String name) {
super();
this.instanceId = instanceId;
this.name = name;
}
public Long getId() {
return id;
}
public Long getInstanceId() {
return instanceId;
}
public Date getCreated() {
return created;
}
public long getLogsequence() {
return logsequence;
}
public void incrLogsequence() {
logsequence++;
}
public String getName() {
return name;
}
}