/** * @return the raw architecture. */ public String getArchitecture() { return architecture.getInstanceDescription().getDescription() .toString().replace("\t", " ").replace(" ", " "); }
/** * Prints instance description. * @param name : instance name * @param out : default print stream * @param err : error print stream (if the instance is not found) */ private void printInstance(String name, PrintStream out, PrintStream err) { for (int i = 0; i < m_archs.length; i++) { InstanceDescription instance = m_archs[i].getInstanceDescription(); if (instance.getName().equalsIgnoreCase(name)) { out.println(instance.getDescription()); return; } } err.println("Instance " + name + " not found"); }
/** * Prints instance list. * @param out : default print stream */ private void printInstances(PrintStream out) { for (int i = 0; i < m_archs.length; i++) { InstanceDescription instance = m_archs[i].getInstanceDescription(); if (instance.getState() == ComponentInstance.VALID) { out.println("Instance " + instance.getName() + " -> valid"); } if (instance.getState() == ComponentInstance.INVALID) { out.println("Instance " + instance.getName() + " -> invalid"); } if (instance.getState() == ComponentInstance.STOPPED) { out.println("Instance " + instance.getName() + " -> stopped"); } } }
/** * Creates the Json representation for an invalid controller. * * @param description the instance's description * @param json the json service * @return the json representation */ public static JsonNode from(InstanceDescription description, Json json) { ObjectNode node = json.newObject(); node.put("classname", description.getComponentDescription().getName()) .put("invalid", description.getState() == ComponentInstance.INVALID) .put("reason", extractInvalidityReason(description)); return node; }
if (arch.getInstanceDescription().getName().equals(name)) { instance = arch.getInstanceDescription(); pw.object(); pw.key("name"); pw.value(instance.getName()); pw.key("state"); pw.value(StateUtils.getInstanceState(instance.getState())); pw.key("factory"); pw.value(instance.getComponentDescription().getName()); getProvidedServiceDetail(pw, instance.getHandlerDescription("org.apache.felix.ipojo:provides")); getRequiredServiceDetail(pw, instance.getHandlerDescription("org.apache.felix.ipojo:requires")); pw.value(instance.getDescription().toString());
instance.addAttribute(new Attribute("name", getName())); // Name int state = getState(); if (state == ComponentInstance.STOPPED) { instance.addAttribute(new Attribute("state", "stopped")); instance.addAttribute(new Attribute("bundle", Long.toString(getBundleId())));
/** * Writes the JSON object containing the info for all instances. * @param pw the writer where the json object is printed. * @throws IOException the JSON object cannot be written */ private void getAllInstances(JSONWriter pw) throws IOException { pw.object(); // Statline: pw.key("count"); pw.value( m_archs.size()); pw.key("valid_count"); pw.value( StateUtils.getValidInstancesCount(m_archs)); pw.key("invalid_count"); pw.value( StateUtils.getInvalidInstancesCount(m_archs)); // End statline pw.key("data"); pw.array(); for (Architecture arch : m_archs) { pw.object(); pw.key("name"); pw.value(arch.getInstanceDescription().getName()); pw.key("factory"); pw.value(arch.getInstanceDescription().getComponentDescription().getName()); pw.key("state"); pw.value(StateUtils.getInstanceState(arch.getInstanceDescription().getState())); pw.endObject(); } pw.endArray(); pw.endObject(); }
/** * Gets the instance list created by the given factory. * @param archs the list of instance architectures * @param factory the factory name * @return the list containing the created instances (name) */ public static List<String> getInstanceList(List<Architecture> archs, String factory) { List<String> list = new ArrayList<String>(); for (Architecture arch : archs) { // Cannot be null, an empty list is returned. String n = arch.getInstanceDescription().getComponentDescription().getName(); if (factory.equals(n)) { list.add(arch.getInstanceDescription().getName()); } } return list; }
private List<InstanceDescription> getInvalidControllers() { List<InstanceDescription> invalid = new ArrayList<>(); for (Architecture architecture : architectures) { final InstanceDescription description = architecture.getInstanceDescription(); // Is it invalid ? if (description.getState() == ComponentInstance.INVALID) { // Is it a controller ProvidedServiceHandlerDescription hd = (ProvidedServiceHandlerDescription) description.getHandlerDescription("org.apache.felix.ipojo:provides"); if (hd != null) { for (ProvidedServiceDescription psd : hd.getProvidedServices()) { if (Arrays.asList(psd.getServiceSpecifications()).contains(org.wisdom.api.Controller.class .getName())) { invalid.add(description); } } } } } return invalid; }
/** * Gets the number of invalid instances. * @param archs the instance architecture list * @return the number of invalid instances. */ public static int getInvalidInstancesCount(List<Architecture> archs) { int i = 0; for (Architecture a : archs) { // Cannot be null, an empty list is returned. if (a.getInstanceDescription().getState() == ComponentInstance.INVALID) { i ++; } } return i; }
/** * @return the instance name. */ public String getName() { return architecture.getInstanceDescription().getName(); }
private static String extractInvalidityReason(InstanceDescription description) { // As it generally comes from the @Requires, let's have a look DependencyHandlerDescription deps = (DependencyHandlerDescription) description.getHandlerDescription("org.apache.felix.ipojo:requires"); if (deps != null && !deps.isValid()) { for (DependencyDescription dd : deps.getDependencies()) { if (dd.getState() == DependencyModel.UNRESOLVED) { if (dd.getSpecification().equals(Template.class.getName())) { // View case return "Missing template : " + extractTemplateName(dd.getFilter()); } else if (dd.getSpecification().equals(Crud.class.getName())) { // Crud case return "Missing model : " + extractModelName(dd.getFilter()); } // General case return "Missing service : " + dd.getSpecification(); } } } // It's not the dependency handler for (HandlerDescription hd : description.getHandlers()) { if (!hd.isValid()) { return "Invalid handler " + hd.getHandlerName(); } } return ""; }
/** * @return the list of provided services */ public List<ProvidedServiceModel> getServices() { ProvidedServiceHandlerDescription pshd = (ProvidedServiceHandlerDescription) architecture.getInstanceDescription().getHandlerDescription("org" + ".apache.felix.ipojo:provides"); if (pshd == null) { return Collections.emptyList(); } else { List<ProvidedServiceModel> list = new ArrayList<>(pshd.getProvidedServices().length); for (ProvidedServiceDescription description : pshd.getProvidedServices()) { list.add(new ProvidedServiceModel(description)); } return list; } }
/** * @return the factory's name. */ public String getFactory() { return architecture.getInstanceDescription().getComponentDescription().getName(); }
instance.addAttribute(new Attribute("name", getName())); // Name int state = getState(); if (state == ComponentInstance.STOPPED) { instance.addAttribute(new Attribute("state", "stopped")); instance.addAttribute(new Attribute("bundle", Long.toString(getBundleId())));
/** * Gets the number of valid instances. * @param archs the instance architecture list * @return the number of valid instances. */ public static int getValidInstancesCount(List<Architecture> archs) { int i = 0; for (Architecture a : archs) { // Cannot be null, an empty list is returned. if (a.getInstanceDescription().getState() == ComponentInstance.VALID) { i ++; } } return i; }
/** * @return the list of required services */ public List<ServiceDependencyModel> getDependencies() { DependencyHandlerDescription handler = (DependencyHandlerDescription) architecture.getInstanceDescription() .getHandlerDescription("org.apache.felix.ipojo:requires"); if (handler == null) { return Collections.emptyList(); } else { List<ServiceDependencyModel> list = new ArrayList<>(handler.getDependencies().length); for (DependencyDescription dependency : handler.getDependencies()) { list.add(new ServiceDependencyModel(dependency)); } return list; } }
/** * Gets the instance description. * Overridden to add created objects. * @return the instance description */ public Element getDescription() { Element elem = super.getDescription(); elem.addElement(getInternalServices()); InstanceDescription[] descs = getContainedInstances(); if (descs.length > 0) { Element inst = new Element("ContainedInstances", ""); for (int i = 0; i < descs.length; i++) { inst.addElement(descs[i].getDescription()); } elem.addElement(inst); } return elem; }
if (id.getName().equalsIgnoreCase(instance)) { sb.append(id.getDescription()); sb.append('\n');
for (Architecture m_arch : m_archs) { InstanceDescription instance = m_arch.getInstanceDescription(); if (instance.getState() == ComponentInstance.VALID) { buffer.append(format("Instance %s -> valid%n", instance.getName())); if (instance.getState() == ComponentInstance.INVALID) { buffer.append(format("Instance %s -> invalid%n", instance.getName())); if (instance.getState() == ComponentInstance.STOPPED) { buffer.append(format("Instance %s -> stopped%n", instance.getName()));