Search in sources :

Example 1 with SolrSchemaField

use of org.platformlayer.service.solr.model.SolrSchemaField in project platformlayer by platformlayer.

the class ITSolrService method testCreateAndDeleteItem.

@Test
public void testCreateAndDeleteItem() throws Exception {
    String id = random.randomAlphanumericString(8);
    SolrCluster solr = new SolrCluster();
    solr.dnsName = id + ".test.platformlayer.org";
    solr = putItem(id, solr);
    solr = waitForHealthy(solr);
    InetSocketAddress socketAddress = getUniqueEndpoint(solr);
    Assert.assertFalse(isPortOpen(socketAddress));
    openFirewall(solr, SolrConstants.API_PORT);
    Assert.assertTrue(isPortOpen(socketAddress));
    // TODO: Make endpoint http://<ip>:<port>/<path>...
    String url = "http://" + socketAddress.getAddress().getHostAddress() + ":" + socketAddress.getPort() + "/solr";
    testSolr(url);
    String customFieldKey = "customfield1";
    SolrSchemaField field = new SolrSchemaField();
    field.name = customFieldKey;
    field.type = "text_general";
    field.getTags().add(Tag.buildParentTag(solr.getKey()));
    // TODO: Our scoping of keys is problematic now...
    // If two clusters both have the same key "customfield1", they can't have the same ID
    field = putItem(id + "-" + customFieldKey, field);
    waitForHealthy(field);
    // Currently, we need to do a manual configure operation...
    // TODO: trigger this automatically
    SolrServer server = getItem(id + "-0", SolrServer.class);
    JobData configureJob = getContext().doConfigure(server);
    waitForJobComplete(configureJob, TimeSpan.FIVE_MINUTES);
    testSolrCustomField(url, customFieldKey);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) JobData(org.platformlayer.jobs.model.JobData) SolrServer(org.platformlayer.service.solr.model.SolrServer) CommonsHttpSolrServer(org.apache.solr.client.solrj.impl.CommonsHttpSolrServer) SolrCluster(org.platformlayer.service.solr.model.SolrCluster) SolrSchemaField(org.platformlayer.service.solr.model.SolrSchemaField) Test(org.testng.annotations.Test) PlatformLayerApiTest(org.platformlayer.tests.PlatformLayerApiTest)

Example 2 with SolrSchemaField

use of org.platformlayer.service.solr.model.SolrSchemaField in project platformlayer by platformlayer.

the class SolrSchemaFile method getContentsBytes.

@Override
protected byte[] getContentsBytes() throws OpsException {
    InputStream is = getClass().getResourceAsStream("schema.xml");
    Document dom;
    try {
        boolean isNamespaceAware = true;
        dom = XmlHelper.parseXmlDocument(is, isNamespaceAware);
    } catch (ParserConfigurationException e) {
        throw new OpsException("Error parsing XML template", e);
    } catch (SAXException e) {
        throw new OpsException("Error parsing XML template", e);
    } catch (IOException e) {
        throw new OpsException("Error parsing XML template", e);
    }
    SolrTemplateData template = OpsContext.get().getInjector().getInstance(SolrTemplateData.class);
    Element fieldsElement;
    {
        NodeList fieldsList = dom.getElementsByTagName("fields");
        if (fieldsList.getLength() != 1) {
            throw new OpsException("Expected exactly one fields element");
        }
        fieldsElement = (Element) fieldsList.item(0);
    }
    // TODO: Turn off default dynamic fields??
    for (SolrSchemaField field : template.getFields()) {
        boolean isDynamic = field.name.contains("*");
        Element el = dom.createElement(isDynamic ? "dynamicField" : "field");
        el.setAttribute("name", field.name);
        el.setAttribute("type", field.type);
        el.setAttribute("indexed", String.valueOf(field.indexed));
        el.setAttribute("stored", String.valueOf(field.stored));
        el.setAttribute("multiValued", String.valueOf(field.multiValued));
        // Compression removed in 1.4.1
        // if (field.compressThreshold >= 0) {
        // el.setAttribute("compressed", "true");
        // el.setAttribute("compressThreshold", String.valueOf(field.compressThreshold));
        // }
        fieldsElement.appendChild(el);
    }
    return Utf8.getBytes(DomUtils.toXml(dom));
}
Also used : OpsException(org.platformlayer.ops.OpsException) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SolrSchemaField(org.platformlayer.service.solr.model.SolrSchemaField) SAXException(org.xml.sax.SAXException)

Example 3 with SolrSchemaField

use of org.platformlayer.service.solr.model.SolrSchemaField in project platformlayer by platformlayer.

the class SolrTemplateData method getFields.

public List<SolrSchemaField> getFields() throws OpsException {
    SolrCluster cluster = getCluster();
    List<SolrSchemaField> fields = Lists.newArrayList();
    for (SolrSchemaField field : platformLayer.listItems(SolrSchemaField.class, TagFilter.byParent(cluster))) {
        fields.add(field);
    }
    return fields;
}
Also used : SolrCluster(org.platformlayer.service.solr.model.SolrCluster) SolrSchemaField(org.platformlayer.service.solr.model.SolrSchemaField)

Aggregations

SolrSchemaField (org.platformlayer.service.solr.model.SolrSchemaField)3 SolrCluster (org.platformlayer.service.solr.model.SolrCluster)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 CommonsHttpSolrServer (org.apache.solr.client.solrj.impl.CommonsHttpSolrServer)1 JobData (org.platformlayer.jobs.model.JobData)1 OpsException (org.platformlayer.ops.OpsException)1 SolrServer (org.platformlayer.service.solr.model.SolrServer)1 PlatformLayerApiTest (org.platformlayer.tests.PlatformLayerApiTest)1 Test (org.testng.annotations.Test)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1 SAXException (org.xml.sax.SAXException)1