Skip to content

Commit 921debb

Browse files
author
Build2 CI
committed
Task 6: DAO Implementations complete
- VnfApplianceDaoImpl: find by UUID/network/VM, list by template/state/health, stale contacts - VnfDictionaryDaoImpl: find by UUID/template/network, list by vendor, list active - VnfBrokerAuditDaoImpl: list by appliance/operation, list failed, delete old logs - VnfReconciliationLogDaoImpl: find latest, list by network/status/appliance, list with drift - All extend GenericDaoBase with proper SearchBuilder patterns - All queries filter by removed=NULL for soft deletes - BUILD SUCCESS verified
1 parent f391fe3 commit 921debb

File tree

4 files changed

+418
-0
lines changed

4 files changed

+418
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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.VnfBrokerAuditVO;
21+
import org.springframework.stereotype.Component;
22+
import com.cloud.utils.db.GenericDaoBase;
23+
import com.cloud.utils.db.SearchBuilder;
24+
import com.cloud.utils.db.SearchCriteria;
25+
26+
import java.util.Date;
27+
import java.util.List;
28+
29+
@Component
30+
public class VnfBrokerAuditDaoImpl extends GenericDaoBase<VnfBrokerAuditVO, Long> implements VnfBrokerAuditDao {
31+
32+
private final SearchBuilder<VnfBrokerAuditVO> applianceIdSearch;
33+
private final SearchBuilder<VnfBrokerAuditVO> failedSearch;
34+
private final SearchBuilder<VnfBrokerAuditVO> operationSearch;
35+
private final SearchBuilder<VnfBrokerAuditVO> olderThanSearch;
36+
37+
public VnfBrokerAuditDaoImpl() {
38+
applianceIdSearch = createSearchBuilder();
39+
applianceIdSearch.and("vnfApplianceId", applianceIdSearch.entity().getVnfApplianceId(), SearchCriteria.Op.EQ);
40+
applianceIdSearch.done();
41+
42+
failedSearch = createSearchBuilder();
43+
failedSearch.and("vnfApplianceId", failedSearch.entity().getVnfApplianceId(), SearchCriteria.Op.EQ);
44+
failedSearch.and("statusCode", failedSearch.entity().getStatusCode(), SearchCriteria.Op.GTEQ);
45+
failedSearch.done();
46+
47+
operationSearch = createSearchBuilder();
48+
operationSearch.and("operation", operationSearch.entity().getOperation(), SearchCriteria.Op.EQ);
49+
operationSearch.done();
50+
51+
olderThanSearch = createSearchBuilder();
52+
olderThanSearch.and("requestTimestamp", olderThanSearch.entity().getRequestTimestamp(), SearchCriteria.Op.LT);
53+
olderThanSearch.done();
54+
}
55+
56+
@Override
57+
public List<VnfBrokerAuditVO> listByApplianceId(Long vnfApplianceId) {
58+
SearchCriteria<VnfBrokerAuditVO> sc = applianceIdSearch.create();
59+
sc.setParameters("vnfApplianceId", vnfApplianceId);
60+
return listBy(sc);
61+
}
62+
63+
@Override
64+
public List<VnfBrokerAuditVO> listFailed(Long vnfApplianceId) {
65+
SearchCriteria<VnfBrokerAuditVO> sc = failedSearch.create();
66+
sc.setParameters("vnfApplianceId", vnfApplianceId);
67+
sc.setParameters("statusCode", 400); // HTTP 400+ are errors
68+
return listBy(sc);
69+
}
70+
71+
@Override
72+
public List<VnfBrokerAuditVO> listByOperation(String operation) {
73+
SearchCriteria<VnfBrokerAuditVO> sc = operationSearch.create();
74+
sc.setParameters("operation", operation);
75+
return listBy(sc);
76+
}
77+
78+
@Override
79+
public int deleteOlderThan(Date cutoffDate) {
80+
SearchCriteria<VnfBrokerAuditVO> sc = olderThanSearch.create();
81+
sc.setParameters("requestTimestamp", cutoffDate);
82+
return expunge(sc);
83+
}
84+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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.VnfDictionaryVO;
21+
import org.springframework.stereotype.Component;
22+
import com.cloud.utils.db.GenericDaoBase;
23+
import com.cloud.utils.db.SearchBuilder;
24+
import com.cloud.utils.db.SearchCriteria;
25+
26+
import java.util.List;
27+
28+
@Component
29+
public class VnfDictionaryDaoImpl extends GenericDaoBase<VnfDictionaryVO, Long> implements VnfDictionaryDao {
30+
31+
private final SearchBuilder<VnfDictionaryVO> uuidSearch;
32+
private final SearchBuilder<VnfDictionaryVO> templateIdSearch;
33+
private final SearchBuilder<VnfDictionaryVO> networkIdSearch;
34+
private final SearchBuilder<VnfDictionaryVO> vendorSearch;
35+
private final SearchBuilder<VnfDictionaryVO> activeSearch;
36+
37+
public VnfDictionaryDaoImpl() {
38+
uuidSearch = createSearchBuilder();
39+
uuidSearch.and("uuid", uuidSearch.entity().getUuid(), SearchCriteria.Op.EQ);
40+
uuidSearch.done();
41+
42+
templateIdSearch = createSearchBuilder();
43+
templateIdSearch.and("templateId", templateIdSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
44+
templateIdSearch.and("removed", templateIdSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
45+
templateIdSearch.done();
46+
47+
networkIdSearch = createSearchBuilder();
48+
networkIdSearch.and("networkId", networkIdSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
49+
networkIdSearch.and("removed", networkIdSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
50+
networkIdSearch.done();
51+
52+
vendorSearch = createSearchBuilder();
53+
vendorSearch.and("vendor", vendorSearch.entity().getVendor(), SearchCriteria.Op.EQ);
54+
vendorSearch.and("removed", vendorSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
55+
vendorSearch.done();
56+
57+
activeSearch = createSearchBuilder();
58+
activeSearch.and("removed", activeSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
59+
activeSearch.done();
60+
}
61+
62+
@Override
63+
public VnfDictionaryVO findByUuid(String uuid) {
64+
SearchCriteria<VnfDictionaryVO> sc = uuidSearch.create();
65+
sc.setParameters("uuid", uuid);
66+
return findOneBy(sc);
67+
}
68+
69+
@Override
70+
public VnfDictionaryVO findByTemplateId(Long templateId) {
71+
SearchCriteria<VnfDictionaryVO> sc = templateIdSearch.create();
72+
sc.setParameters("templateId", templateId);
73+
return findOneBy(sc);
74+
}
75+
76+
@Override
77+
public VnfDictionaryVO findByNetworkId(Long networkId) {
78+
SearchCriteria<VnfDictionaryVO> sc = networkIdSearch.create();
79+
sc.setParameters("networkId", networkId);
80+
return findOneBy(sc);
81+
}
82+
83+
@Override
84+
public List<VnfDictionaryVO> listByVendor(String vendor) {
85+
SearchCriteria<VnfDictionaryVO> sc = vendorSearch.create();
86+
sc.setParameters("vendor", vendor);
87+
return listBy(sc);
88+
}
89+
90+
@Override
91+
public List<VnfDictionaryVO> listActive() {
92+
SearchCriteria<VnfDictionaryVO> sc = activeSearch.create();
93+
return listBy(sc);
94+
}
95+
}

0 commit comments

Comments
 (0)