On create keyspace.

@return the ks def
@throws Exception
the exception
502411
private KsDef onCreateKeyspace() throws Exception
    {
        try
        {
            createdKeyspaces.add(databaseName);
            createKeyspace();
        }
        catch (InvalidRequestException irex)
        {
            // Ignore and add a log.debug
            // keyspace already exists.
            // remove from list if already created.
            createdKeyspaces.remove(databaseName);
        }
        cassandra_client.set_keyspace(databaseName);
        return cassandra_client.describe_keyspace(databaseName);
    }
164847
@Override
  public final M create(final Map<String, Object> pAddParam) throws Exception {
    M object = this.objectClass.newInstance();
    return object;
  }
1335177
private T getOrCreate() throws E {
    try {
      T client = elements.poll();
      // a client was available, all good. otherwise, create one
      if (client != null) {
        return client;
      }
      return create();
    } catch (Exception e) {
      // if an exception is thrown after acquiring the semaphore, release the
      // semaphore before propagating the exception
      semaphore.release();
      throw e;
    }
  }
442285
private KieFileSystem createKieFileSystemWithKProject(String kbaseName, String ksessionName) {
        KieModuleModel kproj = config.getKieProject();
        KieFileSystem kfs = config.getKieServicesInstance().newKieFileSystem();
        kfs.writeKModuleXML(kproj.toXML());
        return kfs;
    }
326433
private Session getOrCreateSession(@NotNull String keyspace) {
        Timer timer = getMetricsFactory().getTimer("cassandraClient.getOrCreateSession");

        Session currentSession = sessionsByKeyspace.computeIfAbsent(keyspace, key -> {
            LOGGER.debug("Create session for [{}]", keyspace);

            Session session = getCluster().connect(key);
            session.init();

            return session;
        });

        timer.stop();

        return currentSession;
    }
1070124
public Keyspace build() {
        final AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
            .forCluster(clusterName)
            .forKeyspace(keyspaceName)
            .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
                .setDiscoveryType(RING_DESCRIBE)
            )
            .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("ConnectionPool")
                .setPort(thriftPort)
                .setSeeds(hosts)
            )
            .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
            .buildKeyspace(ThriftFamilyFactory.getInstance());

        context.start();

        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public synchronized void run() {
                context.shutdown();
            }
        });

        return context.getClient();
    }
695395
protected T createInstance() {
        try {
            Constructor<T> ctor = clazz.getDeclaredConstructor();
            ctor.setAccessible(true);
            return ctor.newInstance();
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (SecurityException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
1009947
private void dropKeyspaceOrCFs() throws InvalidRequestException, SchemaDisagreementException, TException, Exception
    {
        if (createdKeyspaces.contains(databaseName))// drop if created during
                                                    // create-drop call.
        {
            cassandra_client.system_drop_keyspace(databaseName);
        }
        else
        {
            cassandra_client.set_keyspace(databaseName);
            for (TableInfo tableInfo : tableInfos)
            {
                dropColumnFamily(tableInfo);
            }
        }
    }
502155
public static Keyspace createKeyspace(String keyspace, Cluster cluster,
      ConsistencyLevelPolicy consistencyLevelPolicy) {
    return createKeyspace(keyspace, cluster, consistencyLevelPolicy,
        FailoverPolicy.ON_FAIL_TRY_ALL_AVAILABLE);
  }
975
protected KeyPair generateKeyPair() {
        KeyPair keyPair = null;
        DHParameterSpec keySpec = new DHParameterSpec(DH_MODULUS, DH_BASE);
        try {
            KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH");
            keyGen.initialize(keySpec);
            keyPair = keyGen.generateKeyPair();
            keyAgreement = KeyAgreement.getInstance("DH");
            // key agreement is initialized with "this" ends private key
            keyAgreement.init(keyPair.getPrivate());
        } catch (Exception e) {
            log.error("Error generating keypair", e);
        }
        return keyPair;
    }
345980
public Map<String, CFMetaData> getKeyspaceMetaData(String keyspaceName)
    {
        assert keyspaceName != null;
        KSMetaData ksm = keyspaces.get(keyspaceName);
        assert ksm != null;
        return ksm.cfMetaData();
    }
591528
public static function generateKeypair() : Keypair
    {
        try {
            $keypair = \sodium_crypto_box_keypair();
            return new Keypair(
                \sodium_crypto_box_secretkey($keypair),
                \sodium_crypto_box_publickey($keypair)
            );
        } catch (SodiumException $e) {
            throw new Exception($e->getMessage());
        }
    }
924591
private DBConn createAndConnectConn(String keyspace) throws DBNotAvailableException, RuntimeException {
        DBConn dbConn = new DBConn(this, keyspace);
        connectDBConn(dbConn);
        return dbConn;
    }
857533
protected String createSpace(final String spaceId) {
        try {
            Retrier retrier = new Retrier();
            return retrier.execute(new Retriable() {
                @Override
                public String retry() throws Exception {
                    // The actual method being executed
                    snapshotProvider.createSpace(spaceId);
                    return spaceId;
                }
            });
        } catch (Exception e) {
            throw new TaskException("Unable to initialize snapshot restore, " +
                                    "failed creating restore space due to: " +
                                    e.getMessage(), e);
        }
    }
423406
@Override
	public void createResource() throws Exception {
		cluster = builder.getCluster();
		session = cluster.connect();

		session.execute(String.format("CREATE KEYSPACE IF NOT EXISTS %s with replication={'class':'SimpleStrategy', 'replication_factor':1};", keySpace));
		session.execute(String.format("CREATE TABLE IF NOT EXISTS %s.%s (sink_id text, sub_id int, checkpoint_id bigint, PRIMARY KEY (sink_id, sub_id));", keySpace, table));

		try {
			session.close();
		} catch (Exception e) {
			LOG.error("Error while closing session.", e);
		}
		try {
			cluster.close();
		} catch (Exception e) {
			LOG.error("Error while closing cluster.", e);
		}
	}
384108
public function createInstance()
    {
        $classname = $this->getPlatformClassname();

        if (!class_exists($classname)) {
            throw new \Exception(
                sprintf('Unable to locate class %s', $classname)
            );
        }

        return new $classname();
    }
1248935
public static void setOutputKeyspace(Configuration conf, String keyspace)
    {
        if (keyspace == null)
            throw new UnsupportedOperationException("keyspace may not be null");

        conf.set(OUTPUT_KEYSPACE_CONFIG, keyspace);
    }