Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Update #159: add new informations in InstanceStatus summary, add Inst…
Browse files Browse the repository at this point in the history
…ance Summaries and Classpath panels, update menu.
  • Loading branch information
hdsdi3g committed Dec 31, 2015
1 parent 9284274 commit a74f38d
Show file tree
Hide file tree
Showing 19 changed files with 949 additions and 223 deletions.
40 changes: 30 additions & 10 deletions app/controllers/ajs/Instances.java
Expand Up @@ -16,17 +16,26 @@
*/
package controllers.ajs;

import java.lang.reflect.Type;
import java.util.ArrayList;

import com.google.common.reflect.TypeToken;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;

import controllers.Check;
import hd3gtv.mydmam.manager.AJSgetItems;
import hd3gtv.mydmam.manager.AppManager;
import hd3gtv.mydmam.manager.InstanceStatus;
import hd3gtv.mydmam.web.AJSController;

public class Instances extends AJSController {

/*private static Type al_String_typeOfT = new TypeToken<ArrayList<String>>() {
}.getType();*/
private static Type al_String_typeOfT = new TypeToken<ArrayList<String>>() {
}.getType();

/*private static Type hm_StringJob_typeOfT = new TypeToken<HashMap<String, JobNG>>() {
}.getType();*/
Expand All @@ -41,15 +50,17 @@ public JsonElement serialize(AsyncJSBrokerResponseList src, Type typeOfSrc, Json
}
});*/

/*AJSController.registerTypeAdapter(InstanceStatusResponse.class, new JsonSerializer<InstanceStatusResponse>() {
public JsonElement serialize(InstanceStatusResponse src, Type typeOfSrc, JsonSerializationContext context) {
return src.list;
AJSController.registerTypeAdapter(AJSgetItems.class, new JsonDeserializer<AJSgetItems>() {
public AJSgetItems deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
AJSgetItems result = new AJSgetItems();
result.refs = AppManager.getSimpleGson().fromJson(json.getAsJsonObject().get("refs").getAsJsonArray(), al_String_typeOfT);
return result;
}
})*/;
});
}

/**
* @return raw Cassandra json items.
* @return instance ref -> raw JS
*/
@Check("showInstances")
public static JsonObject allSummaries() {
Expand All @@ -59,7 +70,7 @@ public static JsonObject allSummaries() {
}

/**
* @return raw Cassandra json items.
* @return instance ref -> raw JS
*/
@Check("showInstances")
public static JsonObject allThreads() {
Expand All @@ -69,7 +80,7 @@ public static JsonObject allThreads() {
}

/**
* @return raw Cassandra json items.
* @return instance ref -> raw JS
*/
@Check("showInstances")
public static JsonObject allClasspaths() {
Expand All @@ -79,7 +90,7 @@ public static JsonObject allClasspaths() {
}

/**
* @return raw Cassandra json items.
* @return instance ref -> raw JS
*/
@Check("showInstances")
public static JsonObject allItems() {
Expand All @@ -88,4 +99,13 @@ public static JsonObject allItems() {
return result;
}

/**
* @return instance ref -> CF -> raw JS
*/
@Check("showInstances")
public static JsonObject byrefs(AJSgetItems items) {
JsonObject result = current.getByKeys(items.refs, true);
return result;
}

}
Expand Up @@ -14,24 +14,12 @@
* Copyright (C) hdsdi3g for hd3g.tv 2015
*
*/
package hd3gtv.mydmam.manager;

manager.View = React.createClass({
getInitialState: function() {
return {
};
},
componentWillMount: function() {
},
componentDidMount: function(){
},
componentWillUnmount: function() {
},
render: function(){
return (
<mydmam.async.PageHeaderTitle title={i18n("manager.instances")} fluid="true">
</mydmam.async.PageHeaderTitle>
);
},
});
import java.util.ArrayList;

//mydmam.routes.push("broker-Jobs", "broker", manager.View, [{name: "broker", verb: "list"}]);
public class AJSgetItems {

public ArrayList<String> refs;

}
74 changes: 73 additions & 1 deletion app/hd3gtv/mydmam/manager/InstanceStatus.java
Expand Up @@ -24,7 +24,9 @@
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;

import com.google.gson.Gson;
Expand All @@ -36,8 +38,11 @@
import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.MutationBatch;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
import com.netflix.astyanax.model.Column;
import com.netflix.astyanax.model.ColumnFamily;
import com.netflix.astyanax.model.ColumnList;
import com.netflix.astyanax.model.Row;
import com.netflix.astyanax.model.Rows;
import com.netflix.astyanax.serializers.StringSerializer;

import hd3gtv.configuration.Configuration;
Expand Down Expand Up @@ -157,9 +162,26 @@ public class Summary {
private String app_version;
@SuppressWarnings("unused")
private String java_version;
@SuppressWarnings("unused")
private String java_vendor;
private String host_name;
private ArrayList<String> host_addresses;

@SuppressWarnings("unused")
private String os_arch;
@SuppressWarnings("unused")
private String os_name;
@SuppressWarnings("unused")
private String os_version;
@SuppressWarnings("unused")
private String user_country;
@SuppressWarnings("unused")
private String user_language;
@SuppressWarnings("unused")
private String user_name;
@SuppressWarnings("unused")
private String user_timezone;

/**
* Only if manager is set
*/
Expand Down Expand Up @@ -190,7 +212,15 @@ public Summary() {
} else {
app_version = "unknow";
}
java_version = System.getProperty("java.version");
java_version = System.getProperty("java.version", "0");
java_vendor = System.getProperty("java.vendor", "(No set)");
os_arch = System.getProperty("os.arch", "(No set)");
os_name = System.getProperty("os.name", "(No set)");
os_version = System.getProperty("os.version", "(No set)");
user_country = System.getProperty("user.country", "(No set)");
user_language = System.getProperty("user.language", "(No set)");
user_name = System.getProperty("user.name", "(No set)");
user_timezone = System.getProperty("user.timezone", "(No set)");

host_addresses = new ArrayList<String>();
try {
Expand Down Expand Up @@ -390,4 +420,46 @@ public void onFoundRow(Row<String, String> row) throws Exception {
return result;
}

/**
* @return raw Cassandra items.
*/
public JsonObject getByKeys(ArrayList<String> refs, boolean add_static_instance) {
if (refs == null) {
throw new NullPointerException("\"refs\" can't to be null");
}

final JsonObject result = new JsonObject();
final JsonParser parser = new JsonParser();

List<String> col_names = Arrays.asList(CF_COLS.COL_SUMMARY.toString(), CF_COLS.COL_ITEMS.toString());

try {
Rows<String, String> rows = keyspace.prepareQuery(CF_INSTANCES).getKeySlice(refs).withColumnSlice(col_names).execute().getResult();

for (Row<String, String> row : rows) {
JsonObject item = new JsonObject();
ColumnList<String> cols = row.getColumns();
for (Column<String> col : cols) {
String value = col.getStringValue();
if (value != null) {
item.add(col.getName(), parser.parse(value));
}
}
result.add(row.getKey(), item);
}
} catch (Exception e) {
manager.getServiceException().onCassandraError(e);
}

if (add_static_instance) {
JsonObject item = new JsonObject();
getStatic();
item.add(CF_COLS.COL_SUMMARY.toString(), AppManager.getSimpleGson().toJsonTree(is_static.summary));
item.add(CF_COLS.COL_ITEMS.toString(), is_static.getItems());
result.add(is_static.summary.getInstanceNamePid(), item);
}

return result;
}

}
118 changes: 118 additions & 0 deletions app/react/mydmam/async/manager/Classpaths.jsx
@@ -0,0 +1,118 @@
/*
* This file is part of MyDMAM.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* Copyright (C) hdsdi3g for hd3g.tv 2015
*
*/

manager.Classpaths = React.createClass({
getInitialState: function() {
return {
list: {},
instances: {},
};
},
componentWillMount: function() {
mydmam.async.request("instances", "allclasspaths", null, function(list) {
this.setState({list: list});
}.bind(this));
},
render: function() {
var items = [];
var declared_classpath = [];
var instance_refs_to_resolve = [];

/**
* Mergue all CP for create a reference list.
*/
var current_classpath;
for (var instance_ref in this.state.list) {
current_classpath = this.state.list[instance_ref];
for (var pos in current_classpath) {
if (declared_classpath.indexOf(current_classpath[pos]) == -1) {
declared_classpath.push(current_classpath[pos]);
}
}
}

for (pos in declared_classpath) {
for (var instance_ref in this.state.list) {
current_classpath = this.state.list[instance_ref];
if (current_classpath.indexOf(declared_classpath[pos]) == -1) {
var instance_info = instance_ref;
if (this.state.instances[instance_ref]) {
if (this.state.instances[instance_ref] !== "nope") {
var summary = this.state.instances[instance_ref].summary;
instance_info = summary.instance_name + " (" + summary.app_name + ") " + summary.host_name;
} else {
instance_info = i18n("manager.classpath.notfound") + " :: " + instance_ref;
}
} else {
instance_refs_to_resolve.push(instance_ref);
}

items.push(<tr key={md5(declared_classpath[pos] + instance_ref)}>
<td>{declared_classpath[pos]}</td>
<td>{instance_info}</td>
</tr>);
}
}
}

if (instance_refs_to_resolve.length > 0) {
mydmam.async.request("instances", "byrefs", {refs: instance_refs_to_resolve}, function(data) {
for (var pos in instance_refs_to_resolve) {
if (data[instance_refs_to_resolve[pos]] == null) {
data[instance_refs_to_resolve[pos]] = "nope";
}
}
this.setState({instances: jQuery.extend({}, this.state.instances, data)});
}.bind(this));
}

/*<thead>
<tr>
<th>{i18n("manager.instance.host")}</th>
<th>{i18n("manager.instance.manager")}</th>
<th>{i18n("manager.instance.version")}</th>
<th>{i18n("manager.instance.uptime")}</th>
<th>{i18n("manager.instance.jvm")}</th>
<th>{i18n("manager.instance.addr")}</th>
<th>{i18n("manager.instance.os")}</th>
<th>{i18n("manager.instance.user")}</th>
</tr>
*/
//items.push(<manager.InstanceClasspath key={instance_ref} instance={this.state.list[instance_ref]} />);

return (
<table className="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>{i18n("manager.classpath.missing")}</th>
<th>{i18n("manager.classpath.missingin")}</th>
</tr>
</thead>
<tbody>
{items}
</tbody>
</table>
);
},
});

manager.InstanceClasspath = React.createClass({
render: function() {
return null;
},
});

0 comments on commit a74f38d

Please sign in to comment.