Search in sources :

Example 1 with XmlBundleInfo

use of org.eclipse.kura.core.deployment.xml.XmlBundleInfo in project kura by eclipse.

the class CloudDeploymentHandlerV2 method doGetPackages.

private void doGetPackages(KuraResponsePayload response) {
    DeploymentPackage[] dps = this.m_deploymentAdmin.listDeploymentPackages();
    XmlDeploymentPackages xdps = new XmlDeploymentPackages();
    XmlDeploymentPackage[] axdp = new XmlDeploymentPackage[dps.length];
    for (int i = 0; i < dps.length; i++) {
        DeploymentPackage dp = dps[i];
        XmlDeploymentPackage xdp = new XmlDeploymentPackage();
        xdp.setName(dp.getName());
        xdp.setVersion(dp.getVersion().toString());
        BundleInfo[] bis = dp.getBundleInfos();
        XmlBundleInfo[] axbi = new XmlBundleInfo[bis.length];
        for (int j = 0; j < bis.length; j++) {
            BundleInfo bi = bis[j];
            XmlBundleInfo xbi = new XmlBundleInfo();
            xbi.setName(bi.getSymbolicName());
            xbi.setVersion(bi.getVersion().toString());
            axbi[j] = xbi;
        }
        xdp.setBundleInfos(axbi);
        axdp[i] = xdp;
    }
    xdps.setDeploymentPackages(axdp);
    try {
        String s = XmlUtil.marshal(xdps);
        response.setTimestamp(new Date());
        response.setBody(s.getBytes("UTF-8"));
    } catch (Exception e) {
        s_logger.error("Error getting resource {}: {}", RESOURCE_PACKAGES, e);
    }
}
Also used : DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) XmlDeploymentPackage(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage) XmlDeploymentPackage(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage) XmlBundleInfo(org.eclipse.kura.core.deployment.xml.XmlBundleInfo) XmlDeploymentPackages(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackages) Date(java.util.Date) ComponentException(org.osgi.service.component.ComponentException) KuraException(org.eclipse.kura.KuraException) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BundleInfo(org.osgi.service.deploymentadmin.BundleInfo) XmlBundleInfo(org.eclipse.kura.core.deployment.xml.XmlBundleInfo)

Example 2 with XmlBundleInfo

use of org.eclipse.kura.core.deployment.xml.XmlBundleInfo in project kura by eclipse.

the class XmlUtilTest method getSampleXmlDeploymentPackagesObject.

private static XmlDeploymentPackages getSampleXmlDeploymentPackagesObject() {
    XmlDeploymentPackages xmlDeploymentPackages = new XmlDeploymentPackages();
    XmlBundleInfo inputXmlBundleInfo = new XmlBundleInfo();
    inputXmlBundleInfo.setName("XmlBundleInfo");
    inputXmlBundleInfo.setVersion("3.0.1.201");
    XmlDeploymentPackage inputXmlDeploymentPackage = new XmlDeploymentPackage();
    inputXmlDeploymentPackage.setName("raspberry");
    inputXmlDeploymentPackage.setVersion("3.0.1");
    inputXmlDeploymentPackage.setBundleInfos(new XmlBundleInfo[] { inputXmlBundleInfo });
    xmlDeploymentPackages.setDeploymentPackages(new XmlDeploymentPackage[] { inputXmlDeploymentPackage });
    return xmlDeploymentPackages;
}
Also used : XmlDeploymentPackage(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage) XmlBundleInfo(org.eclipse.kura.core.deployment.xml.XmlBundleInfo) XmlDeploymentPackages(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackages)

Example 3 with XmlBundleInfo

use of org.eclipse.kura.core.deployment.xml.XmlBundleInfo in project kura by eclipse.

the class CloudDeploymentHandlerTest method testGetPackages.

@TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL })
@Test
@Ignore
public void testGetPackages() throws Exception {
    assertTrue(s_cloudCallService.isConnected());
    DeploymentPackage dp = s_deploymentAdmin.getDeploymentPackage(LOCAL_DP_NAME);
    if (dp == null) {
        s_logger.warn("Getting dp");
        InputStream is = getTestDpUrl().openStream();
        dp = s_deploymentAdmin.installDeploymentPackage(is);
    }
    StringBuilder sb = new StringBuilder(CloudletTopic.Method.GET.toString()).append("/").append(CloudDeploymentHandlerV2.RESOURCE_PACKAGES);
    KuraResponsePayload resp = s_cloudCallService.call(CloudDeploymentHandlerV2.APP_ID, sb.toString(), null, 5000);
    assertEquals(KuraResponsePayload.RESPONSE_CODE_OK, resp.getResponseCode());
    String s = new String(resp.getBody());
    // XmlDeploymentPackages xmlPackages = XmlUtil.unmarshal(s, XmlDeploymentPackages.class);
    XmlDeploymentPackages xmlPackages = CoreTestXmlUtil.unmarshal(s, XmlDeploymentPackages.class);
    XmlDeploymentPackage[] packages = xmlPackages.getDeploymentPackages();
    XmlDeploymentPackage xmlDp = null;
    if (packages != null) {
        for (int i = 0; i < packages.length; i++) {
            if (packages[i].getName().equals(LOCAL_DP_NAME)) {
                xmlDp = packages[i];
                break;
            }
        }
    }
    assertNotNull(xmlDp);
    assertEquals(LOCAL_DP_VERSION, xmlDp.getVersion());
    XmlBundleInfo[] bundleInfos = xmlDp.getBundleInfos();
    assertEquals(1, bundleInfos.length);
    assertEquals(LOCAL_BUNDLE_NAME, bundleInfos[0].getName());
    assertEquals(LOCAL_BUNDLE_VERSION, bundleInfos[0].getVersion());
}
Also used : InputStream(java.io.InputStream) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) XmlDeploymentPackage(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage) XmlDeploymentPackage(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage) KuraResponsePayload(org.eclipse.kura.message.KuraResponsePayload) XmlBundleInfo(org.eclipse.kura.core.deployment.xml.XmlBundleInfo) XmlDeploymentPackages(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackages) Ignore(org.junit.Ignore) TestTarget(org.eclipse.kura.test.annotation.TestTarget) Test(org.junit.Test)

Example 4 with XmlBundleInfo

use of org.eclipse.kura.core.deployment.xml.XmlBundleInfo in project kura by eclipse.

the class XmlJavaPackagesMapper method marshalDeploymentPackage.

// 
// Marshaller's private methods
// 
private static void marshalDeploymentPackage(Document doc, XmlDeploymentPackage xdp, Element packageInstalled) {
    // Extract data from XmlDeploymentPackage
    String packageName = xdp.getName();
    String packageVersion = xdp.getVersion();
    XmlBundleInfo[] xbiArray = xdp.getBundleInfos();
    // Create xml elements
    if (packageName != null && !packageName.trim().isEmpty()) {
        Element name = doc.createElement(PACKAGES_PACKAGE_NAME);
        name.setTextContent(packageName);
        packageInstalled.appendChild(name);
    }
    if (packageVersion != null && !packageVersion.trim().isEmpty()) {
        Element version = doc.createElement(PACKAGES_PACKAGE_VERSION);
        version.setTextContent(packageVersion);
        packageInstalled.appendChild(version);
    }
    Element bundles = doc.createElement(PACKAGES_PACKAGE_BUNDLES);
    packageInstalled.appendChild(bundles);
    if (xbiArray != null) {
        for (XmlBundleInfo xbi : xbiArray) {
            Element bundle = doc.createElement(PACKAGES_PACKAGE_BUNDLES_BUNDLE);
            marshalBundleInfo(doc, xbi, bundle);
            bundles.appendChild(bundle);
        }
    }
}
Also used : Element(org.w3c.dom.Element) XmlBundleInfo(org.eclipse.kura.core.deployment.xml.XmlBundleInfo)

Example 5 with XmlBundleInfo

use of org.eclipse.kura.core.deployment.xml.XmlBundleInfo in project kura by eclipse.

the class CoreTestXmlUtil method parseBundles.

private static XmlBundleInfo[] parseBundles(Node node) {
    List<XmlBundleInfo> bundleInfos = new ArrayList<XmlBundleInfo>();
    NodeList nodeList = node.getChildNodes();
    // Get information for each bundle
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node bundleNode = nodeList.item(i);
        if (bundleNode.getNodeType() == Node.ELEMENT_NODE) {
            XmlBundleInfo xbi = new XmlBundleInfo();
            NodeList infoList = bundleNode.getChildNodes();
            for (int j = 0; j < infoList.getLength(); j++) {
                Node tmpNode = infoList.item(j);
                // Set Bundle Name
                if (tmpNode.getNodeName().equals("name"))
                    xbi.setName(tmpNode.getTextContent());
                else // Set Bundle Version
                if (tmpNode.getNodeName().equals("version"))
                    xbi.setVersion(tmpNode.getTextContent());
            }
            // Add bundle to array
            bundleInfos.add(xbi);
        }
    }
    return bundleInfos.toArray(new XmlBundleInfo[bundleInfos.size()]);
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) XmlBundleInfo(org.eclipse.kura.core.deployment.xml.XmlBundleInfo)

Aggregations

XmlBundleInfo (org.eclipse.kura.core.deployment.xml.XmlBundleInfo)5 XmlDeploymentPackage (org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage)3 XmlDeploymentPackages (org.eclipse.kura.core.deployment.xml.XmlDeploymentPackages)3 DeploymentPackage (org.osgi.service.deploymentadmin.DeploymentPackage)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 KuraException (org.eclipse.kura.KuraException)1 KuraResponsePayload (org.eclipse.kura.message.KuraResponsePayload)1 TestTarget (org.eclipse.kura.test.annotation.TestTarget)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 BundleException (org.osgi.framework.BundleException)1 ComponentException (org.osgi.service.component.ComponentException)1 BundleInfo (org.osgi.service.deploymentadmin.BundleInfo)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1