Example usage for javax.jms IllegalStateException IllegalStateException

List of usage examples for javax.jms IllegalStateException IllegalStateException

Introduction

In this page you can find the example usage for javax.jms IllegalStateException IllegalStateException.

Prototype

public IllegalStateException(String reason) 

Source Link

Document

Constructs an IllegalStateException with the specified reason.

Usage

From source file:org.broadleafcommerce.core.search.service.solr.SolrConfiguration.java

/**
 * Sets the SolrClient instance that points to the reindex core for the purpose of doing a full reindex, while the
 * primary core is still serving serving requests.  This is typically one of the following: 
 * <code>org.apache.solr.client.solrj.embedded.EmbeddedSolrServer</code>, 
 * <code>org.apache.solr.client.solrj.impl.HttpSolrServer</code>, 
 * <code>org.apache.solr.client.solrj.impl.LBHttpSolrServer</code>, 
 * or <code>org.apache.solr.client.solrj.impl.CloudSolrClient</code>
 * /*w  w  w. j  av a2  s . com*/
 * @param server
 * @throws IllegalStateException 
 */
public void setReindexServer(SolrClient server) throws IllegalStateException {
    if (server != null && CloudSolrClient.class.isAssignableFrom(server.getClass())) {
        CloudSolrClient cs = (CloudSolrClient) server;
        if (StringUtils.isBlank(cs.getDefaultCollection())) {
            cs.setDefaultCollection(getReindexName());
        }

        if (primaryServer != null) {
            //If we already have a reindex server set, make sure it's not the same instance as the primary
            if (server == primaryServer) {
                throw new IllegalArgumentException(
                        "The primary and reindex CloudSolrServers are the same instances. "
                                + "They must be different instances. Each instance must have a different defaultCollection or "
                                + "the defaultCollection must be unspecified and Broadleaf will set it.");
            }

            if (CloudSolrClient.class.isAssignableFrom(primaryServer.getClass())) {
                //Make sure that the primary and reindex servers are not using the same default collection name
                if (cs.getDefaultCollection()
                        .equals(((CloudSolrClient) primaryServer).getDefaultCollection())) {
                    throw new IllegalStateException(
                            "Primary and Reindex servers cannot have the same defaultCollection: "
                                    + cs.getDefaultCollection());
                }
            }
        }
    }
    reindexServer = server;
}

From source file:org.broadleafcommerce.core.search.service.solr.SolrConfiguration.java

@Override
public void afterPropertiesSet() throws SolrServerException, IOException, IllegalStateException {
    if (CloudSolrClient.class.isAssignableFrom(getServer().getClass())) {
        //We want to use the Solr APIs to make sure the correct collections are set up.
        CloudSolrClient primary = (CloudSolrClient) primaryServer;
        CloudSolrClient reindex = (CloudSolrClient) reindexServer;
        if (primary == null || reindex == null) {
            throw new IllegalStateException("The primary and reindex CloudSolrServers must not be null. Check "
                    + "your configuration and ensure that you are passing a different instance for each to the "
                    + "constructor of " + this.getClass().getName() + " and ensure that each has a null (empty)"
                    + " defaultCollection property, or ensure that defaultCollection is unique between"
                    + " the two instances. All other things, like Zookeeper addresses should be the same.");
        }/*from w  w w  .ja  v a 2 s.  c o  m*/

        if (primary == reindex) {
            //These are the same object instances.  They should be separate instances, with generally 
            //the same configuration, except for the defaultCollection name.
            throw new IllegalStateException(
                    "The primary and reindex CloudSolrServers must be different instances "
                            + "and their defaultCollection property must be unique or null.  All other things like the "
                            + "Zookeeper addresses should be the same.");
        }

        //check if the default collection is null
        if (StringUtils.isEmpty(primary.getDefaultCollection())) {
            throw new IllegalStateException(
                    "The primary CloudSolrServer must have a defaultCollection property set.");
        } else {
            this.setPrimaryName(primary.getDefaultCollection());
        }

        //check if the default collection is null
        if (StringUtils.isEmpty(reindex.getDefaultCollection())) {
            throw new IllegalStateException(
                    "The reindex CloudSolrServer must have a defaultCollection property set.");
        } else {
            this.setReindexName(reindex.getDefaultCollection());
        }

        if (Objects.equals(primary.getDefaultCollection(), reindex.getDefaultCollection())) {
            throw new IllegalStateException("The primary and reindex CloudSolrServers must have "
                    + "unique defaultCollection properties.  All other things like the "
                    + "Zookeeper addresses should be the same.");
        }

        primary.connect(); //This is required to ensure no NPE!

        //Get a list of existing collections so we don't overwrite one
        NamedList<Object> listResponse = new CollectionAdminRequest.List().process(primary).getResponse();
        List<String> collectionNames = listResponse.get("collections") == null
                ? collectionNames = new ArrayList<String>()
                : (List<String>) listResponse.get("collections");

        Aliases aliases = primary.getZkStateReader().getAliases();
        Map<String, String> aliasCollectionMap = aliases.getCollectionAliasMap();

        if (aliasCollectionMap == null || !aliasCollectionMap.containsKey(primary.getDefaultCollection())) {
            //Create a completely new collection
            String collectionName = null;
            for (int i = 0; i < 1000; i++) {
                collectionName = "blcCollection" + i;
                if (collectionNames.contains(collectionName)) {
                    collectionName = null;
                } else {
                    break;
                }
            }

            new CollectionAdminRequest.Create().setCollectionName(collectionName)
                    .setNumShards(solrCloudNumShards).setConfigName(solrCloudConfigName).process(primary);

            new CollectionAdminRequest.CreateAlias().setAliasName(primary.getDefaultCollection())
                    .setAliasedCollections(collectionName).process(primary);
        } else {
            //Aliases can be mapped to collections that don't exist.... Make sure the collection exists
            String collectionName = aliasCollectionMap.get(primary.getDefaultCollection());
            collectionName = collectionName.split(",")[0];
            if (!collectionNames.contains(collectionName)) {
                new CollectionAdminRequest.Create().setCollectionName(collectionName)
                        .setNumShards(solrCloudNumShards).setConfigName(solrCloudConfigName).process(primary);
            }
        }

        //Reload the collection names
        listResponse = new CollectionAdminRequest.List().process(primary).getResponse();
        collectionNames = listResponse.get("collections") == null ? collectionNames = new ArrayList<String>()
                : (List<String>) listResponse.get("collections");

        //Reload these maps for the next collection.
        aliases = primary.getZkStateReader().getAliases();
        aliasCollectionMap = aliases.getCollectionAliasMap();

        if (aliasCollectionMap == null || !aliasCollectionMap.containsKey(reindex.getDefaultCollection())) {
            //Create a completely new collection
            String collectionName = null;
            for (int i = 0; i < 1000; i++) {
                collectionName = "blcCollection" + i;
                if (collectionNames.contains(collectionName)) {
                    collectionName = null;
                } else {
                    break;
                }
            }

            new CollectionAdminRequest.Create().setCollectionName(collectionName)
                    .setNumShards(solrCloudNumShards).setConfigName(solrCloudConfigName).process(primary);

            new CollectionAdminRequest.CreateAlias().setAliasName(reindex.getDefaultCollection())
                    .setAliasedCollections(collectionName).process(primary);
        } else {
            //Aliases can be mapped to collections that don't exist.... Make sure the collection exists
            String collectionName = aliasCollectionMap.get(reindex.getDefaultCollection());
            collectionName = collectionName.split(",")[0];
            if (!collectionNames.contains(collectionName)) {
                new CollectionAdminRequest.Create().setCollectionName(collectionName)
                        .setNumShards(solrCloudNumShards).setConfigName(solrCloudConfigName).process(primary);
            }
        }
    }
}

From source file:org.broadleafcommerce.core.search.service.solr.SolrHelperServiceImpl.java

/**
 * This should only ever be called when using the Solr reindex service to do a full reindex. 
 *///  w  w  w .  j  a v  a 2s .c o  m
@Override
public synchronized void swapActiveCores() throws ServiceException {
    if (SolrContext.isSolrCloudMode()) {
        CloudSolrServer primary = (CloudSolrServer) SolrContext.getServer();
        CloudSolrServer reindex = (CloudSolrServer) SolrContext.getReindexServer();
        try {
            primary.connect();
            Aliases aliases = primary.getZkStateReader().getAliases();
            Map<String, String> aliasCollectionMap = aliases.getCollectionAliasMap();
            if (aliasCollectionMap == null || !aliasCollectionMap.containsKey(primary.getDefaultCollection())
                    || !aliasCollectionMap.containsKey(reindex.getDefaultCollection())) {
                throw new IllegalStateException("Could not determine the PRIMARY or REINDEX "
                        + "collection or collections from the Solr aliases.");
            }

            String primaryCollectionName = aliasCollectionMap.get(primary.getDefaultCollection());
            //Do this just in case primary is aliased to more than one collection
            primaryCollectionName = primaryCollectionName.split(",")[0];

            String reindexCollectionName = aliasCollectionMap.get(reindex.getDefaultCollection());
            //Do this just in case primary is aliased to more than one collection
            reindexCollectionName = reindexCollectionName.split(",")[0];

            //Essentially "swap cores" here by reassigning the aliases
            CollectionAdminRequest.createAlias(primary.getDefaultCollection(), reindexCollectionName, primary);
            CollectionAdminRequest.createAlias(reindex.getDefaultCollection(), primaryCollectionName, primary);
        } catch (Exception e) {
            LOG.error("An exception occured swapping cores.", e);
            throw new ServiceException("Unable to swap SolrCloud collections after a full reindex.", e);
        }
    } else {
        if (SolrContext.isSingleCoreMode()) {
            LOG.debug("In single core mode. There are no cores to swap.");
        } else {
            LOG.debug("Swapping active cores");

            CoreAdminRequest car = new CoreAdminRequest();
            car.setCoreName(SolrContext.PRIMARY);
            car.setOtherCoreName(SolrContext.REINDEX);
            car.setAction(CoreAdminAction.SWAP);

            try {
                SolrContext.getAdminServer().request(car);
            } catch (Exception e) {
                LOG.error(e);
                throw new ServiceException("Unable to swap cores", e);
            }
        }
    }
}

From source file:org.cloudifysource.shell.commands.StartLocalCloud.java

private void deployWebUI(Admin admin) throws Exception {
    final String webUIFileName = "tools" + File.separator + "gs-webui" + File.separator
            + "gs-webui-9.5.0-SNAPSHOT.war";

    File webUIFile = getGSFile(webUIFileName);

    this.adminFacade.installElastic(webUIFile, "management", "web-ui", "web-ui", null);

    ProcessingUnit pu = admin.getProcessingUnits().waitFor("web-ui", 10, TimeUnit.SECONDS);
    if (pu == null) {
        throw new IllegalStateException("Could not find 'web-ui' processing unit");
    }//from   w w  w  .j  a v  a 2 s.  co  m

    boolean res = pu.waitFor(1, 30, TimeUnit.SECONDS);
    if (!res) {
        throw new java.lang.IllegalStateException("Could not find instance of 'web-ui' processing unit");
    }

    String url = getWebProcessingUnitURL(pu);

    System.out.println("Web UI is available at: " + url);

}

From source file:org.ei.drishti.domain.OLocation.java

/**
 * @param child The child location to add.
 * @throws IllegalStateException /*from  w  w  w . j a  v a  2 s  .c  o  m*/
 * @since 1.5
 * @should return null given null parameter
 */
public void addChildLocation(OLocation child) throws IllegalStateException {
    if (child == null)
        return;

    if (getChildLocations() == null)
        childLocations = new HashSet<OLocation>();

    if (child.equals(this))
        throw new IllegalStateException("A location cannot be its own child!");

    // Traverse all the way up (down?) to the root, then check whether the child is already
    // anywhere in the tree
    OLocation root = this;
    while (root.getParentLocation() != null)
        root = root.getParentLocation();

    if (isInHierarchy(child, root))
        throw new IllegalStateException("Location hierarchy loop detected! You cannot add: '" + child
                + "' to the parent: '" + this
                + "' because it is in the parent hierarchy somewhere already and a location cannot be its own parent.");

    child.setParentLocation(this);
    childLocations.add(child);
}