• CLI

sdk
  1. Help Center
  2. CLI
  3. Developer Guide
  4. SDK
  5. JAVA
  6. CTS Java SDK Demo

CTS Java SDK Demo

Tracker

A tracker will be created after CTS is enabled. All traces recorded by CTS are associated with the tracker.

Creating a Tracker

You can create a tracker using OpenStack4j based on the following code. Currently, only one tracker system can be created.

public void CreateTracker() { 
Tracker create = osclient.cloudTraceV1().trackers().create(bucket_name,FilePrefixName); 
}

Deleting a Tracker

You can delete a tracker using OpenStack4j based on the following code:

public void DeleteTraker() {
ActionResponse delete = osclient.cloudTraceV1().trackers().delete(tracker_name);
Assert.assertTrue(delete.isSuccess());
List<Tracker> trackers = osclient.cloudTraceV1().trackers().list();
Assert.assertTrue(trackers.size() == 0);
}

Updating a Tracker

You can update a tracker using OpenStack4j based on the following code. The information that can be updated includes the bucket name, folder name, status, and the tracker name. The tracker name is optional and can be only system.

public void UpdateTraker() { 
TrackerUpdate update = TrackerUpdate.builder().trackerName(tracker_name) 
.bucketName(bucket_name).filePrefixName("SDK-unittest").status(TrackerStatus.Enabled").build(); 
Tracker updated = osclient.cloudTraceV1().trackers().update(update); 
}

Querying a Tracker

You can query a tracker using OpenStack4j based on the following code by specifying tracker_name:

public void GetTraker() {
Tracker get = osclient.cloudTraceV1().trackers().get(tracker_name);
}

Trace

This interface is used to query records of operations on resources during the last seven days.

Querying the Trace List

You can query a trace list using OpenStack4j based on the following code. You can filter out required traces by specifying multiple parameters.

/*v1 interface*/
/*v2 interface*/ 
public void ListTrace() { 
TraceListOptions options = TraceListOptions.create().limit(5).user("renxiaomei").serviceType("CTS"); 
List<Trace> list = osclient.cloudTraceV2().traces().list("system", options); 
if (list.size() > 0) { 
Trace trace = list.get(list.size() - 1); 
options.marker(trace.getId()); 
List<Trace> list2 = osclient.cloudTraceV2().traces().list("system", options); 
}