forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMockVpcDaoImpl.java
More file actions
141 lines (119 loc) · 3.94 KB
/
Copy pathMockVpcDaoImpl.java
File metadata and controls
141 lines (119 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// 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.vpc.dao;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.Vpc.State;
import com.cloud.network.vpc.VpcVO;
import com.cloud.network.vpc.dao.VpcDao;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
@Local(value = VpcDao.class)
@DB(txn = false)
public class MockVpcDaoImpl extends GenericDaoBase<VpcVO, Long> implements VpcDao{
private static final Logger s_logger = Logger.getLogger(MockNetworkOfferingDaoImpl.class);
/* (non-Javadoc)
* @see com.cloud.network.vpc.Dao.VpcDao#getVpcCountByOfferingId(long)
*/
@Override
public int getVpcCountByOfferingId(long offId) {
return 100;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.Dao.VpcDao#getActiveVpcById(long)
*/
@Override
public Vpc getActiveVpcById(long vpcId) {
Vpc vpc = findById(vpcId);
if (vpc != null && vpc.getState() == Vpc.State.Enabled) {
return vpc;
}
return null;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.Dao.VpcDao#listByAccountId(long)
*/
@Override
public List<? extends Vpc> listByAccountId(long accountId) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.Dao.VpcDao#listInactiveVpcs()
*/
@Override
public List<VpcVO> listInactiveVpcs() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.Dao.VpcDao#countByAccountId(long)
*/
@Override
public long countByAccountId(long accountId) {
// TODO Auto-generated method stub
return 0;
}
@Override
public VpcVO persist(VpcVO vpc, Map<String, String> serviceProviderMap) {
return null;
}
@Override
public void persistVpcServiceProviders(long vpcId, Map<String, String> serviceProviderMap) {
return;
}
@Override
public VpcVO findById(Long id) {
VpcVO vo = null;
if (id.longValue() == 1) {
vo = new VpcVO(1, "new vpc", "new vpc", 1,1 , 1, "0.0.0.0/0", "vpc domain");
} else if (id.longValue() == 2) {
vo = new VpcVO(1, "new vpc", "new vpc", 1,1 , 1, "0.0.0.0/0", "vpc domain");
vo.setState(State.Inactive);
}
vo = setId(vo, id);
return vo;
}
private VpcVO setId(VpcVO vo, long id) {
VpcVO voToReturn = vo;
Class<?> c = voToReturn.getClass();
try {
Field f = c.getDeclaredField("id");
f.setAccessible(true);
f.setLong(voToReturn, id);
} catch (NoSuchFieldException ex) {
s_logger.warn(ex);
return null;
} catch (IllegalAccessException ex) {
s_logger.warn(ex);
return null;
}
return voToReturn;
}
@Override
public boolean remove(Long id) {
return true;
}
@Override
public boolean update(Long id, VpcVO vo) {
return true;
}
}