|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.apache.cloudstack.vnf.dao; |
| 19 | + |
| 20 | +import org.apache.cloudstack.vnf.entity.VnfApplianceVO; |
| 21 | +import org.apache.cloudstack.vnf.entity.VnfApplianceVO.VnfState; |
| 22 | +import org.apache.cloudstack.vnf.entity.VnfApplianceVO.HealthStatus; |
| 23 | +import org.springframework.stereotype.Component; |
| 24 | +import com.cloud.utils.db.GenericDaoBase; |
| 25 | +import com.cloud.utils.db.SearchBuilder; |
| 26 | +import com.cloud.utils.db.SearchCriteria; |
| 27 | + |
| 28 | +import java.util.List; |
| 29 | +import java.util.Date; |
| 30 | + |
| 31 | +@Component |
| 32 | +public class VnfApplianceDaoImpl extends GenericDaoBase<VnfApplianceVO, Long> implements VnfApplianceDao { |
| 33 | + |
| 34 | + private final SearchBuilder<VnfApplianceVO> uuidSearch; |
| 35 | + private final SearchBuilder<VnfApplianceVO> networkIdSearch; |
| 36 | + private final SearchBuilder<VnfApplianceVO> vmInstanceIdSearch; |
| 37 | + private final SearchBuilder<VnfApplianceVO> templateIdSearch; |
| 38 | + private final SearchBuilder<VnfApplianceVO> stateSearch; |
| 39 | + private final SearchBuilder<VnfApplianceVO> healthStatusSearch; |
| 40 | + private final SearchBuilder<VnfApplianceVO> activeSearch; |
| 41 | + private final SearchBuilder<VnfApplianceVO> staleContactSearch; |
| 42 | + |
| 43 | + public VnfApplianceDaoImpl() { |
| 44 | + uuidSearch = createSearchBuilder(); |
| 45 | + uuidSearch.and("uuid", uuidSearch.entity().getUuid(), SearchCriteria.Op.EQ); |
| 46 | + uuidSearch.done(); |
| 47 | + |
| 48 | + networkIdSearch = createSearchBuilder(); |
| 49 | + networkIdSearch.and("networkId", networkIdSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); |
| 50 | + networkIdSearch.and("removed", networkIdSearch.entity().getRemoved(), SearchCriteria.Op.NULL); |
| 51 | + networkIdSearch.done(); |
| 52 | + |
| 53 | + vmInstanceIdSearch = createSearchBuilder(); |
| 54 | + vmInstanceIdSearch.and("vmInstanceId", vmInstanceIdSearch.entity().getVmInstanceId(), SearchCriteria.Op.EQ); |
| 55 | + vmInstanceIdSearch.and("removed", vmInstanceIdSearch.entity().getRemoved(), SearchCriteria.Op.NULL); |
| 56 | + vmInstanceIdSearch.done(); |
| 57 | + |
| 58 | + templateIdSearch = createSearchBuilder(); |
| 59 | + templateIdSearch.and("templateId", templateIdSearch.entity().getTemplateId(), SearchCriteria.Op.EQ); |
| 60 | + templateIdSearch.and("removed", templateIdSearch.entity().getRemoved(), SearchCriteria.Op.NULL); |
| 61 | + templateIdSearch.done(); |
| 62 | + |
| 63 | + stateSearch = createSearchBuilder(); |
| 64 | + stateSearch.and("state", stateSearch.entity().getState(), SearchCriteria.Op.EQ); |
| 65 | + stateSearch.and("removed", stateSearch.entity().getRemoved(), SearchCriteria.Op.NULL); |
| 66 | + stateSearch.done(); |
| 67 | + |
| 68 | + healthStatusSearch = createSearchBuilder(); |
| 69 | + healthStatusSearch.and("healthStatus", healthStatusSearch.entity().getHealthStatus(), SearchCriteria.Op.EQ); |
| 70 | + healthStatusSearch.and("removed", healthStatusSearch.entity().getRemoved(), SearchCriteria.Op.NULL); |
| 71 | + healthStatusSearch.done(); |
| 72 | + |
| 73 | + activeSearch = createSearchBuilder(); |
| 74 | + activeSearch.and("removed", activeSearch.entity().getRemoved(), SearchCriteria.Op.NULL); |
| 75 | + activeSearch.done(); |
| 76 | + |
| 77 | + staleContactSearch = createSearchBuilder(); |
| 78 | + staleContactSearch.and("lastContact", staleContactSearch.entity().getLastContact(), SearchCriteria.Op.LT); |
| 79 | + staleContactSearch.and("removed", staleContactSearch.entity().getRemoved(), SearchCriteria.Op.NULL); |
| 80 | + staleContactSearch.done(); |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public VnfApplianceVO findByUuid(String uuid) { |
| 85 | + SearchCriteria<VnfApplianceVO> sc = uuidSearch.create(); |
| 86 | + sc.setParameters("uuid", uuid); |
| 87 | + return findOneBy(sc); |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + public VnfApplianceVO findByNetworkId(Long networkId) { |
| 92 | + SearchCriteria<VnfApplianceVO> sc = networkIdSearch.create(); |
| 93 | + sc.setParameters("networkId", networkId); |
| 94 | + return findOneBy(sc); |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + public VnfApplianceVO findByVmInstanceId(Long vmInstanceId) { |
| 99 | + SearchCriteria<VnfApplianceVO> sc = vmInstanceIdSearch.create(); |
| 100 | + sc.setParameters("vmInstanceId", vmInstanceId); |
| 101 | + return findOneBy(sc); |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + public List<VnfApplianceVO> listByTemplateId(Long templateId) { |
| 106 | + SearchCriteria<VnfApplianceVO> sc = templateIdSearch.create(); |
| 107 | + sc.setParameters("templateId", templateId); |
| 108 | + return listBy(sc); |
| 109 | + } |
| 110 | + |
| 111 | + @Override |
| 112 | + public List<VnfApplianceVO> listByState(VnfState state) { |
| 113 | + SearchCriteria<VnfApplianceVO> sc = stateSearch.create(); |
| 114 | + sc.setParameters("state", state.toString()); |
| 115 | + return listBy(sc); |
| 116 | + } |
| 117 | + |
| 118 | + @Override |
| 119 | + public List<VnfApplianceVO> listByHealthStatus(HealthStatus healthStatus) { |
| 120 | + SearchCriteria<VnfApplianceVO> sc = healthStatusSearch.create(); |
| 121 | + sc.setParameters("healthStatus", healthStatus.toString()); |
| 122 | + return listBy(sc); |
| 123 | + } |
| 124 | + |
| 125 | + @Override |
| 126 | + public List<VnfApplianceVO> listActive() { |
| 127 | + SearchCriteria<VnfApplianceVO> sc = activeSearch.create(); |
| 128 | + return listBy(sc); |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + public List<VnfApplianceVO> listStaleContacts(int minutesStale) { |
| 133 | + Date staleThreshold = new Date(System.currentTimeMillis() - (minutesStale * 60 * 1000)); |
| 134 | + SearchCriteria<VnfApplianceVO> sc = staleContactSearch.create(); |
| 135 | + sc.setParameters("lastContact", staleThreshold); |
| 136 | + return listBy(sc); |
| 137 | + } |
| 138 | +} |
0 commit comments