Skip to content

Commit 892fd64

Browse files
author
Adrian Moreno
committed
Sharing feature implemented. Created storage manager to interact with
OpenStack Swift.
1 parent 60b5af7 commit 892fd64

Some content is hidden

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

52 files changed

+1428
-659
lines changed

config.properties

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,32 @@ omq.num_threads=4
5050
# Exchange queue.
5151
# Must be the same as the one the clients send their requests.
5252
omq.rpc_exchange=rpc_global_exchange
53+
#
54+
#
55+
#
56+
# OpenStack Swift configuration
57+
# =============================
58+
#
59+
# Keystone host
60+
swift.host=10.30.235.91
61+
#
62+
# Keystone host
63+
swift.keystone_host=10.30.235.91
64+
#
65+
# Keystone port
66+
swift.keystone_port=5000
67+
#
68+
# Keystone admin port
69+
swift.keystone_admin_port=35357
70+
#
71+
# Keystone protocol
72+
swift.keystone_protocol=http
73+
#
74+
# Tenant
75+
swift.tenant=stacksync
76+
#
77+
# User
78+
swift.user=stacksync_admin
79+
#
80+
# Password
81+
swift.password=secrete

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<dependency>
3232
<groupId>com.stacksync</groupId>
3333
<artifactId>stacksync-commons</artifactId>
34-
<version>1.3.3</version>
34+
<version>1.3.7</version>
3535
</dependency>
3636
<dependency>
3737
<groupId>objectmq</groupId>
@@ -93,6 +93,11 @@
9393
<artifactId>postgresql</artifactId>
9494
<version>9.1-901.jdbc4</version>
9595
</dependency>
96+
<dependency>
97+
<groupId>org.apache.httpcomponents</groupId>
98+
<artifactId>httpclient</artifactId>
99+
<version>4.1.2</version>
100+
</dependency>
96101
</dependencies>
97102
<build>
98103
<resources>

src/main/java/com/stacksync/syncservice/SyncServiceDaemon.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
import com.stacksync.syncservice.omq.SyncServiceImp;
2222
import com.stacksync.syncservice.rpc.XmlRpcSyncHandler;
2323
import com.stacksync.syncservice.rpc.XmlRpcSyncServer;
24+
import com.stacksync.syncservice.storage.StorageFactory;
25+
import com.stacksync.syncservice.storage.StorageManager;
26+
import com.stacksync.syncservice.storage.StorageManager.StorageType;
2427
import com.stacksync.syncservice.util.Config;
2528
import com.stacksync.syncservice.util.Constants;
2629

@@ -81,6 +84,18 @@ public void init(DaemonContext dc) throws DaemonInitException, Exception {
8184
logger.error("Connection to database failed.", e);
8285
System.exit(4);
8386
}
87+
88+
logger.info("Connecting to OpenStack Swift...");
89+
90+
try{
91+
StorageManager storageManager = StorageFactory.getStorageManager(StorageType.SWIFT);
92+
storageManager.login();
93+
logger.info("Connected to OpenStack Swift successfully");
94+
}catch (Exception e) {
95+
logger.fatal("Could not connect to Swift.", e);
96+
System.exit(7);
97+
}
98+
8499

85100
logger.info("Initializing the messaging middleware...");
86101
try {

src/main/java/com/stacksync/syncservice/db/DAOUtil.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.ArrayList;
1111
import java.util.Arrays;
1212
import java.util.List;
13+
import java.util.UUID;
1314

1415
import com.stacksync.commons.models.Chunk;
1516
import com.stacksync.commons.models.Item;
@@ -231,15 +232,14 @@ public static ItemMetadata getItemMetadataFromResultSet(ResultSet result)
231232
metadata.setId(getLongFromResultSet(result, "item_id"));
232233
metadata.setParentId(getLongFromResultSet(result, "parent_id"));
233234
metadata.setParentVersion((getLongFromResultSet(result, "client_parent_file_version")));
234-
metadata.setDeviceId(result.getLong("device_id"));
235+
metadata.setDeviceId(UUID.fromString(result.getString("device_id")));
235236
metadata.setFilename(result.getString("filename"));
236237
metadata.setVersion(result.getLong("version"));
237238
metadata.setIsFolder(result.getBoolean("is_folder"));
238239
metadata.setStatus(result.getString("status"));
239240
metadata.setMimetype(result.getString("mimetype"));
240241
metadata.setChecksum(result.getLong("checksum"));
241242
metadata.setSize(result.getLong("size"));
242-
metadata.setPath(result.getString("path"));
243243
metadata.setModifiedAt(result.getTimestamp("modified_at"));
244244

245245
metadata.setLevel(getIntFromResultSet(result, "level"));
@@ -279,9 +279,10 @@ public static Item getItemFromResultSet(ResultSet result) throws SQLException {
279279
item.setFilename(result.getString("filename"));
280280
item.setMimetype(result.getString("mimetype"));
281281
item.setIsFolder(result.getBoolean("is_folder"));
282+
item.setClientParentFileVersion((getLongFromResultSet(result, "client_parent_file_version")));
282283

283284
Workspace w = new Workspace();
284-
w.setId(result.getLong("workspace_id"));
285+
w.setId(UUID.fromString(result.getString("workspace_id")));
285286
item.setWorkspace(w);
286287

287288
Item parent = new Item();
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package com.stacksync.syncservice.db;
22

3-
import java.util.Collection;
3+
import java.util.UUID;
44

55
import com.stacksync.commons.models.Device;
66
import com.stacksync.syncservice.exceptions.dao.DAOException;
77

88
public interface DeviceDAO {
9-
public Device get(Long id) throws DAOException;
10-
11-
public Collection<Device> findAll() throws DAOException;
9+
10+
public Device get(UUID id) throws DAOException;
1211

1312
public void add(Device device) throws DAOException;
1413

1514
public void update(Device device) throws DAOException;
1615

17-
public void delete(Long id) throws DAOException;
16+
public void delete(UUID id) throws DAOException;
1817

1918
}

src/main/java/com/stacksync/syncservice/db/ItemDAO.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.stacksync.syncservice.db;
22

33
import java.util.List;
4+
import java.util.UUID;
45

56
import com.stacksync.commons.models.Item;
67
import com.stacksync.commons.models.ItemMetadata;
@@ -9,8 +10,6 @@
910
public interface ItemDAO {
1011
public Item findById(Long id) throws DAOException;
1112

12-
public List<Item> findByWorkspaceId(long workspaceId) throws DAOException;
13-
1413
public void add(Item item) throws DAOException;
1514

1615
public void update(Item item) throws DAOException;
@@ -20,13 +19,13 @@ public interface ItemDAO {
2019
public void delete(Long id) throws DAOException;
2120

2221
// ItemMetadata information
23-
public List<ItemMetadata> getItemsByWorkspaceId(Long workspaceId) throws DAOException;
22+
public List<ItemMetadata> getItemsByWorkspaceId(UUID workspaceId) throws DAOException;
2423

2524
public List<ItemMetadata> getItemsById(Long id) throws DAOException;
2625

2726
public ItemMetadata findById(Long id, Boolean includeList, Long version, Boolean includeDeleted, Boolean includeChunks) throws DAOException;
2827

29-
public ItemMetadata findByServerUserId(String serverUserId, Boolean includeDeleted) throws DAOException;
28+
public ItemMetadata findByUserId(UUID serverUserId, Boolean includeDeleted) throws DAOException;
3029

3130
public ItemMetadata findItemVersionsById(Long id) throws DAOException;
3231

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package com.stacksync.syncservice.db;
22

33
import java.util.List;
4+
import java.util.UUID;
45

56
import com.stacksync.commons.models.User;
67
import com.stacksync.syncservice.exceptions.dao.DAOException;
78

89
public interface UserDAO {
910

10-
public User findByPrimaryKey(Long id) throws DAOException;
11-
12-
public User findByCloudId(String cloudId) throws DAOException;
11+
public User findByPrimaryKey(UUID id) throws DAOException;
1312

14-
public User findByEmail(String email) throws DAOException;
13+
public User getByEmail(String email) throws DAOException;
1514

1615
public List<User> findAll() throws DAOException;
1716

@@ -21,7 +20,5 @@ public interface UserDAO {
2120

2221
public void update(User user) throws DAOException;
2322

24-
public void delete(Long id) throws DAOException;
25-
26-
public void delete(String cloudId) throws DAOException;
23+
public void delete(UUID id) throws DAOException;
2724
}
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
package com.stacksync.syncservice.db;
22

3-
import java.util.Collection;
43
import java.util.List;
4+
import java.util.UUID;
55

66
import com.stacksync.commons.models.User;
77
import com.stacksync.commons.models.Workspace;
88
import com.stacksync.syncservice.exceptions.dao.DAOException;
99

1010
public interface WorkspaceDAO {
1111

12-
public Workspace findById(Long id) throws DAOException;
12+
public Workspace findById(UUID id) throws DAOException;
1313

14-
public Collection<Workspace> findAll() throws DAOException;
15-
16-
public List<Workspace> findByUserCloudId(String userCloudId) throws DAOException;
14+
public List<Workspace> findByUserId(UUID userId) throws DAOException;
1715

1816
public Workspace getByItemId(Long itemId) throws DAOException;
1917

2018
public void add(Workspace workspace) throws DAOException;
2119

22-
public void update(Workspace workspace) throws DAOException;
20+
public void update(User user, Workspace workspace) throws DAOException;
2321

24-
public void addUser(User user, Workspace workspace, String folderName) throws DAOException;
22+
public void addUser(User user, Workspace workspace) throws DAOException;
2523

26-
public void delete(Long id) throws DAOException;
24+
public void delete(UUID id) throws DAOException;
2725

2826
}

src/main/java/com/stacksync/syncservice/db/postgresql/PostgresqlDAO.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ protected ResultSet executeQuery(String query, Object[] values) throws DAOExcept
3838
return resultSet;
3939
}
4040

41-
protected Long executeUpdate(String query, Object[] values) throws DAOException {
41+
protected Object executeUpdate(String query, Object[] values) throws DAOException {
4242

43-
Long key = null;
43+
Object key = null;
4444
PreparedStatement preparedStatement = null;
4545
ResultSet generatedKeys = null;
4646

@@ -55,7 +55,7 @@ protected Long executeUpdate(String query, Object[] values) throws DAOException
5555
generatedKeys = preparedStatement.getGeneratedKeys();
5656

5757
if (generatedKeys.next()) {
58-
key = generatedKeys.getLong(1);
58+
key = generatedKeys.getObject(1);
5959
} else {
6060
throw new DAOException("Creating object failed, no generated key obtained.");
6161
}

src/main/java/com/stacksync/syncservice/db/postgresql/PostgresqlDeviceDAO.java

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
import java.sql.Connection;
44
import java.sql.ResultSet;
55
import java.sql.SQLException;
6-
import java.util.ArrayList;
7-
import java.util.Collection;
6+
import java.util.UUID;
87

98
import org.apache.log4j.Logger;
109

1110
import com.stacksync.commons.models.Device;
1211
import com.stacksync.commons.models.User;
13-
import com.stacksync.syncservice.db.DAOError;
1412
import com.stacksync.syncservice.db.DeviceDAO;
1513
import com.stacksync.syncservice.exceptions.dao.DAOException;
1614

@@ -23,11 +21,11 @@ public PostgresqlDeviceDAO(Connection connection) {
2321
}
2422

2523
@Override
26-
public Device get(Long deviceID) throws DAOException {
24+
public Device get(UUID deviceID) throws DAOException {
2725
ResultSet resultSet = null;
2826
Device device = null;
2927

30-
String query = "SELECT * FROM device WHERE id = ?";
28+
String query = "SELECT * FROM device WHERE id = ?::uuid";
3129

3230
try {
3331
resultSet = executeQuery(query, new Object[] { deviceID });
@@ -42,26 +40,6 @@ public Device get(Long deviceID) throws DAOException {
4240
return device;
4341
}
4442

45-
46-
@Override
47-
public Collection<Device> findAll() throws DAOException {
48-
ResultSet resultSet = null;
49-
Collection<Device> list = new ArrayList<Device>();
50-
51-
String query = "SELECT * FROM CLIENTS";
52-
try {
53-
resultSet = executeQuery(query, null);
54-
55-
while (resultSet.next()) {
56-
list.add(mapDevice(resultSet));
57-
}
58-
} catch (SQLException e) {
59-
logger.error(e);
60-
throw new DAOException(DAOError.INTERNAL_SERVER_ERROR);
61-
}
62-
return list;
63-
}
64-
6543
@Override
6644
public void add(Device device) throws DAOException {
6745
if (!device.isValid()) {
@@ -72,9 +50,9 @@ public void add(Device device) throws DAOException {
7250
device.getLastIp(), device.getAppVersion() };
7351

7452
String query = "INSERT INTO device (name, user_id, os, created_at, last_access_at, last_ip, app_version) "
75-
+ "VALUES (?, ?, ?, now(), now(), ?::inet, ?)";
53+
+ "VALUES (?, ?::uuid, ?, now(), now(), ?::inet, ?)";
7654

77-
Long id = executeUpdate(query, values);
55+
UUID id = (UUID) executeUpdate(query, values);
7856

7957
if (id != null) {
8058
device.setId(id);
@@ -90,7 +68,7 @@ public void update(Device device) throws DAOException {
9068
Object[] values = { device.getLastIp(), device.getAppVersion(), device.getId(), device.getUser().getId() };
9169

9270
String query = "UPDATE device SET last_access_at = now(), last_ip = ?::inet, app_version = ? "
93-
+ "WHERE id = ? and user_id = ?";
71+
+ "WHERE id = ?::uuid and user_id = ?::uuid";
9472

9573
try {
9674
executeUpdate(query, values);
@@ -101,22 +79,22 @@ public void update(Device device) throws DAOException {
10179
}
10280

10381
@Override
104-
public void delete(Long deviceID) throws DAOException {
82+
public void delete(UUID deviceID) throws DAOException {
10583
Object[] values = { deviceID };
10684

107-
String query = "DELETE FROM device WHERE id = ?";
85+
String query = "DELETE FROM device WHERE id = ?::uuid";
10886

10987
executeUpdate(query, values);
11088
}
11189

11290
private Device mapDevice(ResultSet resultSet) throws SQLException {
11391

11492
Device device = new Device();
115-
device.setId(resultSet.getLong("id"));
93+
device.setId(UUID.fromString(resultSet.getString("id")));
11694
device.setName(resultSet.getString("name"));
11795

11896
User user = new User();
119-
user.setId(resultSet.getLong("user_id"));
97+
user.setId(UUID.fromString(resultSet.getString("user_id")));
12098

12199
device.setUser(user);
122100

0 commit comments

Comments
 (0)