http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7597a38f/server/src/com/cloud/user/AccountManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index e1b806d..9bf0de6 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -43,6 +43,8 @@ import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; import com.cloud.acl.ControlledEntity; + +import org.apache.cloudstack.api.view.dao.UserAccountJoinDao; import org.apache.cloudstack.api.view.vo.ControlledViewEntity; import org.apache.cloudstack.api.view.vo.UserAccountJoinVO; @@ -110,7 +112,6 @@ import com.cloud.template.VirtualMachineTemplate; import com.cloud.user.Account.State; import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserAccountDao; -import com.cloud.user.dao.UserAccountJoinDao; import com.cloud.user.dao.UserDao; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7597a38f/server/src/com/cloud/user/dao/UserAccountJoinDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/user/dao/UserAccountJoinDao.java b/server/src/com/cloud/user/dao/UserAccountJoinDao.java deleted file mode 100644 index 39a82d0..0000000 --- a/server/src/com/cloud/user/dao/UserAccountJoinDao.java +++ /dev/null @@ -1,40 +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 com.cloud.user.dao; - -import java.util.List; - -import org.apache.cloudstack.api.response.UserResponse; -import org.apache.cloudstack.api.view.vo.UserAccountJoinVO; - -import com.cloud.user.User; -import com.cloud.user.UserAccount; -import com.cloud.utils.db.GenericDao; - -public interface UserAccountJoinDao extends GenericDao<UserAccountJoinVO, Long> { - - UserResponse newUserResponse(UserAccountJoinVO usr); - - UserAccountJoinVO newUserView(User usr); - - UserAccountJoinVO newUserView(UserAccount usr); - - List<UserAccountJoinVO> searchByIds(Long... ids); - - List<UserAccountJoinVO> searchByAccountId(Long accountId); - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7597a38f/server/src/com/cloud/user/dao/UserAccountJoinDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/user/dao/UserAccountJoinDaoImpl.java b/server/src/com/cloud/user/dao/UserAccountJoinDaoImpl.java deleted file mode 100644 index e854ae5..0000000 --- a/server/src/com/cloud/user/dao/UserAccountJoinDaoImpl.java +++ /dev/null @@ -1,138 +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 com.cloud.user.dao; - -import java.util.List; - -import javax.ejb.Local; - -import org.apache.log4j.Logger; - -import com.cloud.api.ApiDBUtils; -import com.cloud.api.ApiResponseHelper; -import org.apache.cloudstack.api.response.InstanceGroupResponse; -import org.apache.cloudstack.api.response.UserResponse; -import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO; -import org.apache.cloudstack.api.view.vo.UserAccountJoinVO; - -import com.cloud.user.Account; -import com.cloud.user.User; -import com.cloud.user.UserAccount; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.vm.InstanceGroup; - - -@Local(value={UserAccountJoinDao.class}) -public class UserAccountJoinDaoImpl extends GenericDaoBase<UserAccountJoinVO, Long> implements UserAccountJoinDao { - public static final Logger s_logger = Logger.getLogger(UserAccountJoinDaoImpl.class); - - private SearchBuilder<UserAccountJoinVO> vrSearch; - - private SearchBuilder<UserAccountJoinVO> vrIdSearch; - - private SearchBuilder<UserAccountJoinVO> vrAcctIdSearch; - - - protected UserAccountJoinDaoImpl() { - - vrSearch = createSearchBuilder(); - vrSearch.and("idIN", vrSearch.entity().getId(), SearchCriteria.Op.IN); - vrSearch.done(); - - vrIdSearch = createSearchBuilder(); - vrIdSearch.and("id", vrIdSearch.entity().getId(), SearchCriteria.Op.EQ); - vrIdSearch.done(); - - vrAcctIdSearch = createSearchBuilder(); - vrAcctIdSearch.and("accountid", vrAcctIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ); - vrAcctIdSearch.done(); - - - this._count = "select count(distinct id) from user_view WHERE "; - } - - - - @Override - public UserResponse newUserResponse(UserAccountJoinVO usr) { - UserResponse userResponse = new UserResponse(); - userResponse.setAccountId(usr.getAccountUuid()); - userResponse.setAccountName(usr.getAccountName()); - userResponse.setAccountType(usr.getAccountType()); - userResponse.setCreated(usr.getCreated()); - userResponse.setDomainId(usr.getDomainUuid()); - userResponse.setDomainName(usr.getDomainName()); - userResponse.setEmail(usr.getEmail()); - userResponse.setFirstname(usr.getFirstname()); - userResponse.setId(usr.getUuid()); - userResponse.setLastname(usr.getLastname()); - userResponse.setState(usr.getState().toString()); - userResponse.setTimezone(usr.getTimezone()); - userResponse.setUsername(usr.getUsername()); - userResponse.setApiKey(usr.getApiKey()); - userResponse.setSecretKey(usr.getSecretKey()); - userResponse.setObjectName("user"); - - return userResponse; - } - - - @Override - public UserAccountJoinVO newUserView(User usr) { - SearchCriteria<UserAccountJoinVO> sc = vrIdSearch.create(); - sc.setParameters("id", usr.getId()); - List<UserAccountJoinVO> users = searchIncludingRemoved(sc, null, null, false); - assert users != null && users.size() == 1 : "No user found for user id " + usr.getId(); - return users.get(0); - } - - - - - @Override - public UserAccountJoinVO newUserView(UserAccount usr) { - SearchCriteria<UserAccountJoinVO> sc = vrIdSearch.create(); - sc.setParameters("id", usr.getId()); - List<UserAccountJoinVO> users = searchIncludingRemoved(sc, null, null, false); - assert users != null && users.size() == 1 : "No user found for user id " + usr.getId(); - return users.get(0); - } - - - - @Override - public List<UserAccountJoinVO> searchByIds(Long... ids) { - SearchCriteria<UserAccountJoinVO> sc = vrSearch.create(); - sc.setParameters("idIN", ids); - return searchIncludingRemoved(sc, null, null, false); - } - - - - @Override - public List<UserAccountJoinVO> searchByAccountId(Long accountId) { - SearchCriteria<UserAccountJoinVO> sc = vrAcctIdSearch.create(); - sc.setParameters("accountId", accountId); - return searchIncludingRemoved(sc, null, null, false); - } - - - - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7597a38f/server/src/com/cloud/vm/UserVmManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index a8241d0..2e14655 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -74,6 +74,7 @@ import org.apache.cloudstack.api.command.user.vm.ResetVMPasswordCmd; import org.apache.cloudstack.api.command.user.vm.RestoreVMCmd; import org.apache.cloudstack.api.command.user.vm.UpdateVMCmd; import org.apache.cloudstack.api.command.user.vm.UpgradeVMCmd; +import org.apache.cloudstack.api.view.dao.UserVmJoinDao; import org.apache.cloudstack.api.view.vo.UserVmJoinVO; import com.cloud.async.AsyncJobExecutor; import com.cloud.async.AsyncJobManager; @@ -230,7 +231,6 @@ import com.cloud.vm.dao.InstanceGroupVMMapDao; import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.UserVmDetailsDao; -import com.cloud.vm.dao.UserVmJoinDao; import com.cloud.vm.dao.VMInstanceDao; @Local(value = { UserVmManager.class, UserVmService.class }) http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7597a38f/server/src/com/cloud/vm/dao/DomainRouterJoinDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/dao/DomainRouterJoinDao.java b/server/src/com/cloud/vm/dao/DomainRouterJoinDao.java deleted file mode 100644 index 9bb03be..0000000 --- a/server/src/com/cloud/vm/dao/DomainRouterJoinDao.java +++ /dev/null @@ -1,36 +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 com.cloud.vm.dao; - -import java.util.List; - -import org.apache.cloudstack.api.response.DomainRouterResponse; -import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO; -import com.cloud.network.router.VirtualRouter; -import com.cloud.user.Account; -import com.cloud.utils.db.GenericDao; - -public interface DomainRouterJoinDao extends GenericDao<DomainRouterJoinVO, Long> { - - DomainRouterResponse newDomainRouterResponse(DomainRouterJoinVO uvo, Account caller); - - DomainRouterResponse setDomainRouterResponse(DomainRouterResponse userVmData, DomainRouterJoinVO uvo); - - List<DomainRouterJoinVO> newDomainRouterView(VirtualRouter vr); - - List<DomainRouterJoinVO> searchByIds(Long... ids); -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7597a38f/server/src/com/cloud/vm/dao/DomainRouterJoinDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/dao/DomainRouterJoinDaoImpl.java b/server/src/com/cloud/vm/dao/DomainRouterJoinDaoImpl.java deleted file mode 100644 index 38839e3..0000000 --- a/server/src/com/cloud/vm/dao/DomainRouterJoinDaoImpl.java +++ /dev/null @@ -1,202 +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 com.cloud.vm.dao; - -import java.util.ArrayList; -import java.util.List; - -import javax.ejb.Local; - -import org.apache.log4j.Logger; - -import com.cloud.api.ApiResponseHelper; -import org.apache.cloudstack.api.response.DomainRouterResponse; -import org.apache.cloudstack.api.response.NicResponse; -import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO; -import com.cloud.network.Networks.TrafficType; -import com.cloud.network.router.VirtualRouter; -import com.cloud.user.Account; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; - - -@Local(value={DomainRouterJoinDao.class}) -public class DomainRouterJoinDaoImpl extends GenericDaoBase<DomainRouterJoinVO, Long> implements DomainRouterJoinDao { - public static final Logger s_logger = Logger.getLogger(DomainRouterJoinDaoImpl.class); - - private SearchBuilder<DomainRouterJoinVO> vrSearch; - - private SearchBuilder<DomainRouterJoinVO> vrIdSearch; - - protected DomainRouterJoinDaoImpl() { - - vrSearch = createSearchBuilder(); - vrSearch.and("idIN", vrSearch.entity().getId(), SearchCriteria.Op.IN); - vrSearch.done(); - - vrIdSearch = createSearchBuilder(); - vrIdSearch.and("id", vrIdSearch.entity().getId(), SearchCriteria.Op.EQ); - vrIdSearch.done(); - - this._count = "select count(distinct id) from domain_router_view WHERE "; - } - - - @Override - public DomainRouterResponse newDomainRouterResponse(DomainRouterJoinVO router, Account caller) { - DomainRouterResponse routerResponse = new DomainRouterResponse(); - routerResponse.setId(router.getUuid()); - routerResponse.setZoneId(router.getDataCenterUuid()); - routerResponse.setName(router.getHostName()); - routerResponse.setTemplateId(router.getTemplateUuid()); - routerResponse.setCreated(router.getCreated()); - routerResponse.setState(router.getState()); - routerResponse.setIsRedundantRouter(router.isRedundantRouter()); - routerResponse.setRedundantState(router.getRedundantState().toString()); - - if (caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN - || caller.getType() == Account.ACCOUNT_TYPE_ADMIN) { - if (router.getHostId() != null) { - routerResponse.setHostId(router.getHostUuid()); - routerResponse.setHostName(router.getHostName()); - } - routerResponse.setPodId(router.getPodUuid()); - long nic_id = router.getNicId(); - if (nic_id > 0) { - TrafficType ty = router.getTrafficType(); - if (ty != null) { - // legacy code, public/control/guest nic info is kept in - // nics response object - if (ty == TrafficType.Public) { - routerResponse.setPublicIp(router.getIpAddress()); - routerResponse.setPublicMacAddress(router.getMacAddress()); - routerResponse.setPublicNetmask(router.getNetmask()); - routerResponse.setGateway(router.getGateway()); - routerResponse.setPublicNetworkId(router.getNetworkUuid()); - } else if (ty == TrafficType.Control) { - routerResponse.setLinkLocalIp(router.getIpAddress()); - routerResponse.setLinkLocalMacAddress(router.getMacAddress()); - routerResponse.setLinkLocalNetmask(router.getNetmask()); - routerResponse.setLinkLocalNetworkId(router.getNetworkUuid()); - } else if (ty == TrafficType.Guest) { - routerResponse.setGuestIpAddress(router.getIpAddress()); - routerResponse.setGuestMacAddress(router.getMacAddress()); - routerResponse.setGuestNetmask(router.getNetmask()); - routerResponse.setGuestNetworkId(router.getNetworkUuid()); - routerResponse.setNetworkDomain(router.getNetworkDomain()); - } - } - - NicResponse nicResponse = new NicResponse(); - nicResponse.setId(router.getNicUuid()); - nicResponse.setIpaddress(router.getIpAddress()); - nicResponse.setGateway(router.getGateway()); - nicResponse.setNetmask(router.getNetmask()); - nicResponse.setNetworkid(router.getNetworkUuid()); - nicResponse.setNetworkName(router.getNetworkName()); - nicResponse.setMacAddress(router.getMacAddress()); - if (router.getBroadcastUri() != null) { - nicResponse.setBroadcastUri(router.getBroadcastUri().toString()); - } - if (router.getIsolationUri() != null) { - nicResponse.setIsolationUri(router.getIsolationUri().toString()); - } - if (router.getTrafficType() != null) { - nicResponse.setTrafficType(router.getTrafficType().toString()); - } - if (router.getGuestType() != null) { - nicResponse.setType(router.getGuestType().toString()); - } - nicResponse.setIsDefault(router.isDefaultNic()); - nicResponse.setObjectName("nic"); - routerResponse.addNic(nicResponse); - } - } - - routerResponse.setServiceOfferingId(router.getServiceOfferingUuid()); - routerResponse.setServiceOfferingName(router.getServiceOfferingName()); - - // populate owner. - ApiResponseHelper.populateOwner(routerResponse, router); - - - routerResponse.setDomainId(router.getDomainUuid()); - routerResponse.setDomainName(router.getDomainName()); - - routerResponse.setZoneName(router.getDataCenterName()); - routerResponse.setDns1(router.getDns1()); - routerResponse.setDns2(router.getDns2()); - - routerResponse.setVpcId(router.getVpcUuid()); - - routerResponse.setObjectName("router"); - - return routerResponse; - } - - - @Override - public DomainRouterResponse setDomainRouterResponse(DomainRouterResponse vrData, DomainRouterJoinVO vr) { - long nic_id = vr.getNicId(); - if (nic_id > 0) { - NicResponse nicResponse = new NicResponse(); - nicResponse.setId(vr.getNicUuid()); - nicResponse.setIpaddress(vr.getIpAddress()); - nicResponse.setGateway(vr.getGateway()); - nicResponse.setNetmask(vr.getNetmask()); - nicResponse.setNetworkid(vr.getNetworkUuid()); - nicResponse.setMacAddress(vr.getMacAddress()); - if (vr.getBroadcastUri() != null) { - nicResponse.setBroadcastUri(vr.getBroadcastUri().toString()); - } - if (vr.getIsolationUri() != null) { - nicResponse.setIsolationUri(vr.getIsolationUri().toString()); - } - if (vr.getTrafficType() != null) { - nicResponse.setTrafficType(vr.getTrafficType().toString()); - } - if (vr.getGuestType() != null) { - nicResponse.setType(vr.getGuestType().toString()); - } - nicResponse.setIsDefault(vr.isDefaultNic()); - nicResponse.setObjectName("nic"); - vrData.addNic(nicResponse); - } - return vrData; - } - - - - - @Override - public List<DomainRouterJoinVO> searchByIds(Long... ids) { - SearchCriteria<DomainRouterJoinVO> sc = vrSearch.create(); - sc.setParameters("idIN", ids); - return searchIncludingRemoved(sc, null, null, false); - } - - - @Override - public List<DomainRouterJoinVO> newDomainRouterView(VirtualRouter vr) { - - SearchCriteria<DomainRouterJoinVO> sc = vrIdSearch.create(); - sc.setParameters("id", vr.getId()); - return searchIncludingRemoved(sc, null, null, false); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7597a38f/server/src/com/cloud/vm/dao/InstanceGroupJoinDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/dao/InstanceGroupJoinDao.java b/server/src/com/cloud/vm/dao/InstanceGroupJoinDao.java deleted file mode 100644 index 64599be..0000000 --- a/server/src/com/cloud/vm/dao/InstanceGroupJoinDao.java +++ /dev/null @@ -1,35 +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 com.cloud.vm.dao; - -import java.util.List; - -import org.apache.cloudstack.api.response.InstanceGroupResponse; -import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO; - -import com.cloud.utils.db.GenericDao; -import com.cloud.vm.InstanceGroup; - -public interface InstanceGroupJoinDao extends GenericDao<InstanceGroupJoinVO, Long> { - - InstanceGroupResponse newInstanceGroupResponse(InstanceGroupJoinVO group); - - InstanceGroupJoinVO newInstanceGroupView(InstanceGroup group); - - List<InstanceGroupJoinVO> searchByIds(Long... ids); - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7597a38f/server/src/com/cloud/vm/dao/InstanceGroupJoinDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/dao/InstanceGroupJoinDaoImpl.java b/server/src/com/cloud/vm/dao/InstanceGroupJoinDaoImpl.java deleted file mode 100644 index aa20b77..0000000 --- a/server/src/com/cloud/vm/dao/InstanceGroupJoinDaoImpl.java +++ /dev/null @@ -1,96 +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 com.cloud.vm.dao; - -import java.util.List; - -import javax.ejb.Local; - -import org.apache.log4j.Logger; - -import com.cloud.api.ApiResponseHelper; -import org.apache.cloudstack.api.response.InstanceGroupResponse; -import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO; - -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.vm.InstanceGroup; - - -@Local(value={InstanceGroupJoinDao.class}) -public class InstanceGroupJoinDaoImpl extends GenericDaoBase<InstanceGroupJoinVO, Long> implements InstanceGroupJoinDao { - public static final Logger s_logger = Logger.getLogger(InstanceGroupJoinDaoImpl.class); - - private SearchBuilder<InstanceGroupJoinVO> vrSearch; - - private SearchBuilder<InstanceGroupJoinVO> vrIdSearch; - - - protected InstanceGroupJoinDaoImpl() { - - vrSearch = createSearchBuilder(); - vrSearch.and("idIN", vrSearch.entity().getId(), SearchCriteria.Op.IN); - vrSearch.done(); - - vrIdSearch = createSearchBuilder(); - vrIdSearch.and("id", vrIdSearch.entity().getId(), SearchCriteria.Op.EQ); - vrIdSearch.done(); - - this._count = "select count(distinct id) from instance_group_view WHERE "; - } - - - - @Override - public InstanceGroupResponse newInstanceGroupResponse(InstanceGroupJoinVO group) { - InstanceGroupResponse groupResponse = new InstanceGroupResponse(); - groupResponse.setId(group.getUuid()); - groupResponse.setName(group.getName()); - groupResponse.setCreated(group.getCreated()); - - ApiResponseHelper.populateOwner(groupResponse, group); - - groupResponse.setObjectName("instancegroup"); - return groupResponse; - } - - - - @Override - public InstanceGroupJoinVO newInstanceGroupView(InstanceGroup group) { - SearchCriteria<InstanceGroupJoinVO> sc = vrIdSearch.create(); - sc.setParameters("id", group.getId()); - List<InstanceGroupJoinVO> grps = searchIncludingRemoved(sc, null, null, false); - assert grps != null && grps.size() == 1 : "No vm group found for group id " + group.getId(); - return grps.get(0); - - } - - - - @Override - public List<InstanceGroupJoinVO> searchByIds(Long... ids) { - SearchCriteria<InstanceGroupJoinVO> sc = vrSearch.create(); - sc.setParameters("idIN", ids); - return searchIncludingRemoved(sc, null, null, false); - } - - - - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7597a38f/server/src/com/cloud/vm/dao/UserVmJoinDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/dao/UserVmJoinDao.java b/server/src/com/cloud/vm/dao/UserVmJoinDao.java deleted file mode 100644 index 7788a62..0000000 --- a/server/src/com/cloud/vm/dao/UserVmJoinDao.java +++ /dev/null @@ -1,38 +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 com.cloud.vm.dao; - -import java.util.EnumSet; -import java.util.List; - -import org.apache.cloudstack.api.ApiConstants.VMDetails; -import org.apache.cloudstack.api.response.UserVmResponse; -import org.apache.cloudstack.api.view.vo.UserVmJoinVO; -import com.cloud.user.Account; -import com.cloud.uservm.UserVm; -import com.cloud.utils.db.GenericDao; - -public interface UserVmJoinDao extends GenericDao<UserVmJoinVO, Long> { - - UserVmResponse newUserVmResponse(String objectName, UserVmJoinVO userVm, EnumSet<VMDetails> details, Account caller); - - UserVmResponse setUserVmResponse(UserVmResponse userVmData, UserVmJoinVO uvo); - - List<UserVmJoinVO> newUserVmView(UserVm... userVms); - - List<UserVmJoinVO> searchByIds(Long... ids); -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7597a38f/server/src/com/cloud/vm/dao/UserVmJoinDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/dao/UserVmJoinDaoImpl.java b/server/src/com/cloud/vm/dao/UserVmJoinDaoImpl.java deleted file mode 100644 index b20e53f..0000000 --- a/server/src/com/cloud/vm/dao/UserVmJoinDaoImpl.java +++ /dev/null @@ -1,327 +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 com.cloud.vm.dao; - -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.Hashtable; -import java.util.List; - -import javax.ejb.Local; - -import org.apache.log4j.Logger; - -import com.cloud.api.ApiDBUtils; -import org.apache.cloudstack.api.ApiConstants.VMDetails; -import org.apache.cloudstack.api.response.NicResponse; -import org.apache.cloudstack.api.response.SecurityGroupResponse; -import org.apache.cloudstack.api.response.UserVmResponse; -import org.apache.cloudstack.api.view.vo.ResourceTagJoinVO; -import org.apache.cloudstack.api.view.vo.UserVmJoinVO; -import com.cloud.user.Account; -import com.cloud.uservm.UserVm; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.vm.VmStats; - - -@Local(value={UserVmJoinDao.class}) -public class UserVmJoinDaoImpl extends GenericDaoBase<UserVmJoinVO, Long> implements UserVmJoinDao { - public static final Logger s_logger = Logger.getLogger(UserVmJoinDaoImpl.class); - - private static final int VM_DETAILS_BATCH_SIZE=100; - - private SearchBuilder<UserVmJoinVO> VmDetailSearch; - - protected UserVmJoinDaoImpl() { - - VmDetailSearch = createSearchBuilder(); - VmDetailSearch.and("idIN", VmDetailSearch.entity().getId(), SearchCriteria.Op.IN); - VmDetailSearch.done(); - - this._count = "select count(distinct id) from user_vm_view WHERE "; - } - - public UserVmResponse newUserVmResponse(String objectName, UserVmJoinVO userVm, EnumSet<VMDetails> details, Account caller) { - UserVmResponse userVmResponse = new UserVmResponse(); - - if (userVm.getHypervisorType() != null){ - userVmResponse.setHypervisor(userVm.getHypervisorType().toString()); - } - userVmResponse.setId(userVm.getUuid()); - userVmResponse.setName(userVm.getName()); - - userVmResponse.setDisplayName(userVm.getDisplayName()); - - if (userVm.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) { - userVmResponse.setProjectId(userVm.getProjectUuid()); - userVmResponse.setProjectName(userVm.getProjectName()); - } else { - userVmResponse.setAccountName(userVm.getAccountName()); - } - - userVmResponse.setDomainId(userVm.getDomainUuid()); - userVmResponse.setDomainName(userVm.getDomainName()); - - userVmResponse.setCreated(userVm.getCreated()); - - if (userVm.getState() != null) { - userVmResponse.setState(userVm.getState().toString()); - } - userVmResponse.setHaEnable(userVm.isHaEnabled()); - if (details.contains(VMDetails.all) || details.contains(VMDetails.group)) { - userVmResponse.setGroupId(userVm.getInstanceGroupUuid()); - userVmResponse.setGroup(userVm.getInstanceGroupName()); - } - userVmResponse.setZoneId(userVm.getDataCenterUuid()); - userVmResponse.setZoneName(userVm.getDataCenterName()); - if ((caller == null) || (caller.getType() == Account.ACCOUNT_TYPE_ADMIN)) { - userVmResponse.setInstanceName(userVm.getInstanceName()); - userVmResponse.setHostId(userVm.getHostUuid()); - userVmResponse.setHostName(userVm.getHostName()); - } - - if (details.contains(VMDetails.all) || details.contains(VMDetails.tmpl)) { - userVmResponse.setTemplateId(userVm.getTemplateUuid()); - userVmResponse.setTemplateName(userVm.getTemplateName()); - userVmResponse.setTemplateDisplayText(userVm.getTemplateDisplayText()); - userVmResponse.setPasswordEnabled(userVm.isPasswordEnabled()); - } - if (details.contains(VMDetails.all) || details.contains(VMDetails.iso)) { - userVmResponse.setIsoId(userVm.getIsoUuid()); - userVmResponse.setIsoName(userVm.getIsoName()); - userVmResponse.setIsoDisplayText(userVm.getIsoDisplayText()); - } - if (details.contains(VMDetails.all) || details.contains(VMDetails.servoff)) { - userVmResponse.setServiceOfferingId(userVm.getServiceOfferingUuid()); - userVmResponse.setServiceOfferingName(userVm.getServiceOfferingName()); - userVmResponse.setCpuNumber(userVm.getCpu()); - userVmResponse.setCpuSpeed(userVm.getSpeed()); - userVmResponse.setMemory(userVm.getRamSize()); - } - userVmResponse.setGuestOsId(userVm.getGuestOsUuid()); - if (details.contains(VMDetails.all) || details.contains(VMDetails.volume)) { - userVmResponse.setRootDeviceId(userVm.getVolumeDeviceId()); - if (userVm.getVolumeType() != null) { - userVmResponse.setRootDeviceType(userVm.getVolumeType().toString()); - } - } - userVmResponse.setPassword(userVm.getPassword()); - userVmResponse.setJobUuid(userVm.getJobUuid()); - userVmResponse.setJobStatus(userVm.getJobStatus()); - //userVmResponse.setForVirtualNetwork(userVm.getForVirtualNetwork()); - - userVmResponse.setPublicIpId(userVm.getPublicIpUuid()); - userVmResponse.setPublicIp(userVm.getPublicIpAddress()); - userVmResponse.setKeyPairName(userVm.getKeypairName()); - - if (details.contains(VMDetails.all) || details.contains(VMDetails.stats)) { - DecimalFormat decimalFormat = new DecimalFormat("#.##"); - // stats calculation - String cpuUsed = null; - VmStats vmStats = ApiDBUtils.getVmStatistics(userVm.getId()); - if (vmStats != null) { - float cpuUtil = (float) vmStats.getCPUUtilization(); - cpuUsed = decimalFormat.format(cpuUtil) + "%"; - userVmResponse.setCpuUsed(cpuUsed); - - Double networkKbRead = Double.valueOf(vmStats.getNetworkReadKBs()); - userVmResponse.setNetworkKbsRead(networkKbRead.longValue()); - - Double networkKbWrite = Double.valueOf(vmStats.getNetworkWriteKBs()); - userVmResponse.setNetworkKbsWrite(networkKbWrite.longValue()); - } - } - - if (details.contains(VMDetails.all) || details.contains(VMDetails.secgrp)) { - Long securityGroupId = userVm.getSecurityGroupId(); - if (securityGroupId != null && securityGroupId.longValue() != 0) { - SecurityGroupResponse resp = new SecurityGroupResponse(); - resp.setId(userVm.getSecurityGroupUuid()); - resp.setName(userVm.getSecurityGroupName()); - resp.setDescription(userVm.getSecurityGroupDescription()); - resp.setObjectName("securitygroup"); - if (userVm.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) { - resp.setProjectId(userVm.getProjectUuid()); - resp.setProjectName(userVm.getProjectName()); - } else { - resp.setAccountName(userVm.getAccountName()); - } - userVmResponse.addSecurityGroup(resp); - } - } - - if (details.contains(VMDetails.all) || details.contains(VMDetails.nics)) { - long nic_id = userVm.getNicId(); - if (nic_id > 0) { - NicResponse nicResponse = new NicResponse(); - nicResponse.setId(userVm.getNicUuid()); - nicResponse.setIpaddress(userVm.getIpAddress()); - nicResponse.setGateway(userVm.getGateway()); - nicResponse.setNetmask(userVm.getNetmask()); - nicResponse.setNetworkid(userVm.getNetworkUuid()); - nicResponse.setMacAddress(userVm.getMacAddress()); - if (userVm.getBroadcastUri() != null) { - nicResponse.setBroadcastUri(userVm.getBroadcastUri().toString()); - } - if (userVm.getIsolationUri() != null) { - nicResponse.setIsolationUri(userVm.getIsolationUri().toString()); - } - if (userVm.getTrafficType() != null) { - nicResponse.setTrafficType(userVm.getTrafficType().toString()); - } - if (userVm.getGuestType() != null) { - nicResponse.setType(userVm.getGuestType().toString()); - } - nicResponse.setIsDefault(userVm.isDefaultNic()); - nicResponse.setObjectName("nic"); - userVmResponse.addNic(nicResponse); - } - } - - // update tag information - long tag_id = userVm.getTagId(); - if (tag_id > 0) { - ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id); - if ( vtag != null ){ - userVmResponse.addTag(ApiDBUtils.newResourceTagResponse(vtag, false)); - } - } - userVmResponse.setObjectName(objectName); - - return userVmResponse; - } - - public UserVmResponse setUserVmResponse(UserVmResponse userVmData, UserVmJoinVO uvo) { - Long securityGroupId = uvo.getSecurityGroupId(); - if (securityGroupId != null && securityGroupId.longValue() != 0) { - SecurityGroupResponse resp = new SecurityGroupResponse(); - resp.setId(uvo.getSecurityGroupUuid()); - resp.setName(uvo.getSecurityGroupName()); - resp.setDescription(uvo.getSecurityGroupDescription()); - resp.setObjectName("securitygroup"); - if (uvo.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) { - resp.setProjectId(uvo.getProjectUuid()); - resp.setProjectName(uvo.getProjectName()); - } else { - resp.setAccountName(uvo.getAccountName()); - } - userVmData.addSecurityGroup(resp); - } - - long nic_id = uvo.getNicId(); - if (nic_id > 0) { - NicResponse nicResponse = new NicResponse(); - nicResponse.setId(uvo.getNicUuid()); - nicResponse.setIpaddress(uvo.getIpAddress()); - nicResponse.setGateway(uvo.getGateway()); - nicResponse.setNetmask(uvo.getNetmask()); - nicResponse.setNetworkid(uvo.getNetworkUuid()); - nicResponse.setMacAddress(uvo.getMacAddress()); - if (uvo.getBroadcastUri() != null) { - nicResponse.setBroadcastUri(uvo.getBroadcastUri().toString()); - } - if (uvo.getIsolationUri() != null) { - nicResponse.setIsolationUri(uvo.getIsolationUri().toString()); - } - if (uvo.getTrafficType() != null) { - nicResponse.setTrafficType(uvo.getTrafficType().toString()); - } - if (uvo.getGuestType() != null) { - nicResponse.setType(uvo.getGuestType().toString()); - } - nicResponse.setIsDefault(uvo.isDefaultNic()); - nicResponse.setObjectName("nic"); - userVmData.addNic(nicResponse); - } - - long tag_id = uvo.getTagId(); - if (tag_id > 0) { - ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id); - if ( vtag != null ){ - userVmData.addTag(ApiDBUtils.newResourceTagResponse(vtag, false)); - } - } - return userVmData; - } - - - @Override - public List<UserVmJoinVO> searchByIds(Long... vmIds) { - SearchCriteria<UserVmJoinVO> sc = VmDetailSearch.create(); - sc.setParameters("idIN", vmIds); - return searchIncludingRemoved(sc, null, null, false); - } - - @Override - public List<UserVmJoinVO> newUserVmView(UserVm... userVms) { - - int curr_index = 0; - - Hashtable<Long, UserVm> userVmDataHash = new Hashtable<Long, UserVm>(); - for (UserVm vm : userVms){ - if ( !userVmDataHash.containsKey(vm.getId())){ - userVmDataHash.put(vm.getId(), vm); - } - } - - List<UserVmJoinVO> uvList = new ArrayList<UserVmJoinVO>(); - List<Long> userVmIdList = new ArrayList(userVmDataHash.keySet()); - if (userVmIdList.size() > VM_DETAILS_BATCH_SIZE) { - while ((curr_index + VM_DETAILS_BATCH_SIZE) <= userVmIdList.size()) { - // set current ids - Long[] vmIds = new Long[VM_DETAILS_BATCH_SIZE]; - for (int k = 0, j = curr_index; j < curr_index + VM_DETAILS_BATCH_SIZE; j++, k++) { - vmIds[k] = userVmIdList.get(j); - } - SearchCriteria<UserVmJoinVO> sc = VmDetailSearch.create(); - sc.setParameters("idIN", vmIds); - List<UserVmJoinVO> vms = searchIncludingRemoved(sc, null, null, false); - if (vms != null) { - for (UserVmJoinVO uvm : vms) { - uvList.add(uvm); - } - } - curr_index += VM_DETAILS_BATCH_SIZE; - } - } - - if (curr_index < userVmIdList.size()) { - int batch_size = (userVmIdList.size() - curr_index); - // set the ids value - Long[] vmIds = new Long[batch_size]; - for (int k = 0, j = curr_index; j < curr_index + batch_size; j++, k++) { - vmIds[k] = userVmIdList.get(j); - } - SearchCriteria<UserVmJoinVO> sc = VmDetailSearch.create(); - sc.setParameters("idIN", vmIds); - List<UserVmJoinVO> vms = searchIncludingRemoved(sc, null, null, false); - if (vms != null) { - for (UserVmJoinVO uvm : vms) { - UserVm vm = userVmDataHash.get(uvm.getId()); - assert vm != null : "We should not find details of vm not in the passed UserVm list"; - uvList.add(uvm); - } - } - } - return uvList; - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7597a38f/server/test/com/cloud/network/security/SecurityGroupManagerImpl2Test.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/network/security/SecurityGroupManagerImpl2Test.java b/server/test/com/cloud/network/security/SecurityGroupManagerImpl2Test.java index 46b7018..93bccf4 100644 --- a/server/test/com/cloud/network/security/SecurityGroupManagerImpl2Test.java +++ b/server/test/com/cloud/network/security/SecurityGroupManagerImpl2Test.java @@ -23,6 +23,7 @@ import javax.naming.ConfigurationException; import junit.framework.TestCase; +import org.apache.cloudstack.api.view.dao.SecurityGroupJoinDaoImpl; import org.junit.After; import org.junit.Before; import org.junit.Ignore; @@ -34,7 +35,6 @@ import com.cloud.domain.dao.DomainDaoImpl; import com.cloud.event.dao.UsageEventDaoImpl; import com.cloud.network.MockNetworkManagerImpl; import com.cloud.network.security.dao.SecurityGroupDaoImpl; -import com.cloud.network.security.dao.SecurityGroupJoinDaoImpl; import com.cloud.network.security.dao.SecurityGroupRuleDaoImpl; import com.cloud.network.security.dao.SecurityGroupRulesDaoImpl; import com.cloud.network.security.dao.SecurityGroupVMMapDaoImpl;
