4
4
5
5
import com .spotify .reaper .ReaperException ;
6
6
import com .spotify .reaper .cassandra .ClusterInfo ;
7
+ import com .spotify .reaper .cassandra .IClusterInfo ;
7
8
import com .spotify .reaper .core .Cluster ;
8
9
import com .spotify .reaper .storage .IStorage ;
9
10
12
13
13
14
import java .net .URI ;
14
15
import java .net .URL ;
16
+ import java .util .Collections ;
15
17
16
18
import javax .ws .rs .GET ;
17
19
import javax .ws .rs .POST ;
@@ -51,7 +53,7 @@ public Response addCluster(@Context UriInfo uriInfo, @QueryParam("host") Optiona
51
53
}
52
54
LOG .info ("add cluster called with host: {}" , host );
53
55
54
- ClusterInfo clusterInfo ;
56
+ IClusterInfo clusterInfo ;
55
57
try {
56
58
clusterInfo = ClusterInfo .getInstance (host .get ());
57
59
} catch (ReaperException e ) {
@@ -61,14 +63,23 @@ public Response addCluster(@Context UriInfo uriInfo, @QueryParam("host") Optiona
61
63
return Response .status (400 ).entity (errMsg ).build ();
62
64
}
63
65
66
+
64
67
URI createdURI = null ;
65
68
try {
66
- createdURI = (new URL (uriInfo .getAbsolutePath ().toURL (), "1" )).toURI ();
69
+ createdURI = (new URL (uriInfo .getAbsolutePath ().toURL (), clusterInfo . getSymbolicName () )).toURI ();
67
70
} catch (Exception e ) {
68
- LOG .error ("failed creating target URI: " + uriInfo .getAbsolutePath ());
71
+ String errMsg = "failed creating target for cluster: " + clusterInfo .getSymbolicName ();
72
+ LOG .error (errMsg );
69
73
e .printStackTrace ();
74
+ return Response .status (400 ).entity (errMsg ).build ();
70
75
}
71
76
77
+ storage .addCluster (new Cluster .Builder ()
78
+ .name (clusterInfo .getClusterName ())
79
+ .seedHosts (Collections .singleton (host .get ()))
80
+ .partitioner (clusterInfo .getPartitionerName ())
81
+ .build ());
82
+
72
83
String replyMsg = "cluster with name \" " + clusterInfo .getClusterName () + "\" created" ;
73
84
return Response .created (createdURI ).entity (replyMsg ).build ();
74
85
}
0 commit comments