Skip to content

Commit a715eb8

Browse files
author
Edison Su
committed
clean up storage related code, and add lru replacement algorithm for cache storage
1 parent 0acce2c commit a715eb8

109 files changed

Lines changed: 1204 additions & 2231 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

agent/src/com/cloud/agent/AgentShell.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public class AgentShell implements IAgentShell, Daemon {
8282
private int _pingRetries;
8383
private final List<Agent> _agents = new ArrayList<Agent>();
8484

85+
8586
public AgentShell() {
8687
}
8788

api/src/com/cloud/storage/StoragePool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public interface StoragePool extends Identity, InternalIdentity {
5858
/**
5959
* @return available storage in bytes
6060
*/
61-
long getAvailableBytes();
61+
long getUsedBytes();
6262

6363
Long getClusterId();
6464

client/tomcatconf/applicationContext.xml.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@
815815
<bean id="swiftImageStoreProviderImpl" class="org.apache.cloudstack.storage.datastore.provider.SwiftImageStoreProviderImpl" />
816816
<bean id="ApplicationLoadBalancerService" class="org.apache.cloudstack.network.lb.ApplicationLoadBalancerManagerImpl" />
817817
<bean id="InternalLoadBalancerVMManager" class="org.apache.cloudstack.network.lb.InternalLoadBalancerVMManagerImpl" />
818+
<bean id="StorageCacheReplacementAlgorithm" class="org.apache.cloudstack.storage.cache.manager.StorageCacheReplacementAlgorithmLRU" />
818819

819820

820821
<!--=======================================================================================================-->

client/tomcatconf/log4j-cloud.xml.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ under the License.
132132
<priority value="INFO"/>
133133
</category>
134134

135+
<category name="org.apache.cloudstack">
136+
<priority value="DEBUG"/>
137+
</category>
138+
135139
<category name="org.apache.cloudstack.api.command">
136140
<priority value="TRACE"/>
137141
</category>

core/test/org/apache/cloudstack/api/agent/test/BackupSnapshotCommandTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public long getCapacityBytes() {
8383
};
8484

8585
@Override
86-
public long getAvailableBytes() {
86+
public long getUsedBytes() {
8787
return 0L;
8888
};
8989

core/test/org/apache/cloudstack/api/agent/test/CheckNetworkAnswerTest.java

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,26 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.agent.test;
1818

19+
import static org.junit.Assert.assertEquals;
1920
import static org.junit.Assert.assertFalse;
2021
import static org.junit.Assert.assertTrue;
2122

23+
import com.cloud.agent.api.storage.ResizeVolumeCommand;
24+
import com.cloud.agent.api.to.StorageFilerTO;
25+
import com.cloud.storage.Storage;
26+
import com.cloud.storage.StoragePool;
27+
import com.cloud.storage.StoragePoolStatus;
2228
import org.junit.Before;
2329
import org.junit.Test;
2430
import org.mockito.Mockito;
2531

2632
import com.cloud.agent.api.CheckNetworkAnswer;
2733
import com.cloud.agent.api.CheckNetworkCommand;
2834

35+
import java.text.ParseException;
36+
import java.text.SimpleDateFormat;
37+
import java.util.Date;
38+
2939
public class CheckNetworkAnswerTest {
3040
CheckNetworkCommand cnc;
3141
CheckNetworkAnswer cna;
@@ -59,4 +69,199 @@ public void testExecuteInSequence() {
5969
boolean b = cna.executeInSequence();
6070
assertFalse(b);
6171
}
72+
73+
public static class ResizeVolumeCommandTest {
74+
75+
public StoragePool dummypool = new StoragePool() {
76+
@Override
77+
public long getId() {
78+
return 1L;
79+
};
80+
81+
@Override
82+
public String getName() {
83+
return "name";
84+
};
85+
86+
@Override
87+
public String getUuid() {
88+
return "bed9f83e-cac3-11e1-ac8a-0050568b007e";
89+
};
90+
91+
@Override
92+
public Storage.StoragePoolType getPoolType() {
93+
return Storage.StoragePoolType.Filesystem;
94+
};
95+
96+
@Override
97+
public Date getCreated() {
98+
Date date = null;
99+
try {
100+
date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
101+
.parse("01/01/1970 12:12:12");
102+
} catch (ParseException e) {
103+
e.printStackTrace();
104+
}
105+
return date;
106+
}
107+
108+
@Override
109+
public Date getUpdateTime() {
110+
return new Date();
111+
};
112+
113+
@Override
114+
public long getDataCenterId() {
115+
return 0L;
116+
};
117+
118+
@Override
119+
public long getCapacityBytes() {
120+
return 0L;
121+
};
122+
123+
@Override
124+
public long getUsedBytes() {
125+
return 0L;
126+
};
127+
128+
@Override
129+
public Long getClusterId() {
130+
return 0L;
131+
};
132+
133+
@Override
134+
public String getHostAddress() {
135+
return "hostAddress";
136+
};
137+
138+
@Override
139+
public String getPath() {
140+
return "path";
141+
};
142+
143+
@Override
144+
public String getUserInfo() {
145+
return "userInfo";
146+
};
147+
148+
@Override
149+
public boolean isShared() {
150+
return false;
151+
};
152+
153+
@Override
154+
public boolean isLocal() {
155+
return false;
156+
};
157+
158+
@Override
159+
public StoragePoolStatus getStatus() {
160+
return StoragePoolStatus.Up;
161+
};
162+
163+
@Override
164+
public int getPort() {
165+
return 25;
166+
};
167+
168+
@Override
169+
public Long getPodId() {
170+
return 0L;
171+
}
172+
173+
@Override
174+
public String getStorageProviderName() {
175+
// TODO Auto-generated method stub
176+
return null;
177+
}
178+
179+
@Override
180+
public boolean isInMaintenance() {
181+
// TODO Auto-generated method stub
182+
return false;
183+
};
184+
};
185+
186+
Long newSize = 4194304L;
187+
Long currentSize = 1048576L;
188+
189+
ResizeVolumeCommand rv = new ResizeVolumeCommand("dummydiskpath",
190+
new StorageFilerTO(dummypool), currentSize, newSize, false,
191+
"vmName");
192+
193+
@Test
194+
public void testExecuteInSequence() {
195+
boolean b = rv.executeInSequence();
196+
assertFalse(b);
197+
}
198+
199+
@Test
200+
public void testGetPath() {
201+
String path = rv.getPath();
202+
assertTrue(path.equals("dummydiskpath"));
203+
}
204+
205+
@Test
206+
public void testGetPoolUuid() {
207+
String poolUuid = rv.getPoolUuid();
208+
assertTrue(poolUuid.equals("bed9f83e-cac3-11e1-ac8a-0050568b007e"));
209+
}
210+
211+
@Test
212+
public void testGetPool() {
213+
StorageFilerTO pool = rv.getPool();
214+
215+
Long id = pool.getId();
216+
Long expectedL = 1L;
217+
assertEquals(expectedL, id);
218+
219+
String uuid = pool.getUuid();
220+
assertTrue(uuid.equals("bed9f83e-cac3-11e1-ac8a-0050568b007e"));
221+
222+
String host = pool.getHost();
223+
assertTrue(host.equals("hostAddress"));
224+
225+
String path = pool.getPath();
226+
assertTrue(path.equals("path"));
227+
228+
String userInfo = pool.getUserInfo();
229+
assertTrue(userInfo.equals("userInfo"));
230+
231+
Integer port = pool.getPort();
232+
Integer expectedI = 25;
233+
assertEquals(expectedI, port);
234+
235+
Storage.StoragePoolType type = pool.getType();
236+
assertEquals(Storage.StoragePoolType.Filesystem, type);
237+
238+
String str = pool.toString();
239+
assertTrue(str.equals("Pool[" + id.toString() + "|" + host + ":"
240+
+ port.toString() + "|" + path + "]"));
241+
}
242+
243+
@Test
244+
public void testGetNewSize() {
245+
long newSize = rv.getNewSize();
246+
assertTrue(newSize == 4194304L);
247+
}
248+
249+
@Test
250+
public void testGetCurrentSize() {
251+
long currentSize = rv.getCurrentSize();
252+
assertTrue(currentSize == 1048576L);
253+
}
254+
255+
@Test
256+
public void testGetShrinkOk() {
257+
assertFalse(rv.getShrinkOk());
258+
}
259+
260+
@Test
261+
public void testGetInstanceName() {
262+
String vmName = rv.getInstanceName();
263+
assertTrue(vmName.equals("vmName"));
264+
}
265+
266+
}
62267
}

core/test/org/apache/cloudstack/api/agent/test/SnapshotCommandTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public long getCapacityBytes() {
7474
return 0L;
7575
};
7676

77-
public long getAvailableBytes() {
77+
public long getUsedBytes() {
7878
return 0L;
7979
};
8080

0 commit comments

Comments
 (0)