Hector + Cassandra: Get Column Family List - list

I am trying to get all the column families in the current keyspace I am using because I want to get rid of the error:
InvalidRequestException(why:[column family] already exists in keyspace)
My logic is to get all the Column Families in the current key space & check whether or not a particular column family appears in the returned list. So, I try:
KeyspaceDefinition keyspaceDef = HFactory.createKeyspaceDefinition("test");
...
List<ColumnFamilyDefinition> lsCf = keyspaceDef.getCfDefs();
There seems to be a problem with creating the
List<ColumnFamilyDefinition> lsCf = keyspaceDef.getCfDefs();
I did a System.out.println(keyspaceDef.getCfDefs()) and it returned
[]
an empty list - which is what I expected. What I cannot understand is why List<ColumnFamilyDefinition> lsCf = keyspaceDef.getCfDefs(); is incorrect. Eclipse disagrees with the "List" portion of this line. Other than that, it appears that he code is right. Can some one please help me understand why this line is wrong or whether my approach is off?
Here's the full code snippet:
package org.cassandra.examples;
import me.prettyprint.cassandra.model.BasicColumnFamilyDefinition;
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
import me.prettyprint.cassandra.service.ThriftCfDef;
import me.prettyprint.cassandra.service.ThriftCluster;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.*;
import me.prettyprint.cassandra.model.BasicColumnDefinition;
import me.prettyprint.cassandra.model.BasicColumnFamilyDefinition;
import me.prettyprint.cassandra.model.thrift.ThriftConverter;
import org.apache.cassandra.db.ColumnFamily;
import org.apache.cassandra.thrift.Cassandra;
import me.prettyprint.cassandra.service.ThriftKsDef;
import me.prettyprint.hector.api.*;
import me.prettyprint.hector.api.beans.HColumn;
import me.prettyprint.hector.api.beans.HSuperColumn;
import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
import me.prettyprint.hector.api.ddl.ColumnIndexType;
import me.prettyprint.hector.api.ddl.ComparatorType;
import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.mutation.Mutator;
import me.prettyprint.cassandra.service.template.ColumnFamilyTemplate;
import me.prettyprint.cassandra.service.template.ColumnFamilyUpdater;
import me.prettyprint.cassandra.service.template.ThriftColumnFamilyTemplate;
import me.prettyprint.hector.api.mutation.Mutator;
import me.prettyprint.hector.api.query.ColumnQuery;
import me.prettyprint.hector.api.query.QueryResult;
import me.prettyprint.hector.api.query.SuperColumnQuery;
public class HectorTest {
private static String keyspaceName = "test3";
private static KeyspaceDefinition newKeyspaceDef;
private static Cluster cluster;
private static Keyspace ksp;
public static void main(String[] args) {
cluster = HFactory.getOrCreateCluster("test cluster", "xxx.xxx.x.xx:9160");
newKeyspaceDef = HFactory.createKeyspaceDefinition(keyspaceName);
ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("MyKeyspace",
"ColumnFamilyName",
ComparatorType.BYTESTYPE);
List<ColumnFamilyDefinition> lCf = newKeyspaceDef.getCfDefs(); //= new ArrayList<ColumnFamilyDefinition>();
if((cluster.describeKeyspace(keyspaceName)) == null){
createSchema();
}
ksp = HFactory.createKeyspace(keyspaceName, cluster);
//Articles art = new Articles(cluster, newKeyspaceDef);
//cluster.dropColumnFamily(keyspaceName, "Articles");
}
public static void createSchema(){
cluster.addKeyspace(newKeyspaceDef,true);
}
}
Error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
List cannot be resolved to a type
at org.cassandra.examples.HectorTest.main(HectorTest.java:55)

Add
import java.util.List;
to you imports. In eclipse, CTRL-SHIFT-O will organize your imports for you, and add anything that is missing.

Related

How to solve KeyError?

I was trying to create some steps in the Abaqus by using the following python code. Unfortunately having this error. Anybody, please help me...
KeyError:model_name
Python Code:
from abaqus import *
from abaqusConstants import *
import __main__
import section
import regionToolset
import displayGroupMdbToolset as dgm
import part
import material
import assembly
import step
import interaction
import load
import mesh
import optimization
import job
import sketch
import visualization
import xyPlot
import displayGroupOdbToolset as dgo
import connectorBehavior
def create_step(model_name, new_step, previous_step):
mdb.models['model_name'].StaticStep(name='new_step', previous='previous_step', initialInc=0.025,
maxInc=0.025)
session.viewports['Viewport: 1'].assemblyDisplay.setValues(step='new_step')
model_name = 'Model-' + str(0)
new_step = 'C4'
previous_step = 'C3'
create_step(model_name, new_step, previous_step)
Replace mdb.models['model_name'].Stat... with mdb.models[model_name].Stat...
def create_step(model_name, new_step, previous_step):
mdb.models['model_name'].StaticStep(name='new_step', previous='previous_step', initialInc=0.025,
maxInc=0.025)
session.viewports['Viewport: 1'].assemblyDisplay.setValues(step='new_step')
2nd line should be,
mdb.models[model_name].StaticStep(name='new_step', previous='previous_step', initialInc=0.025,
maxInc=0.025)

One Chrome browser window in selenium webdriver --python

I have some issue with the init constructor related to selenium webdriver's chrome instances.
Here are the pieces of my scripts:
First one named methods.py
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import paths
class PagePatterns(object):
def __init__(self, title=None):
self.driver = webdriver.Chrome('C:\Python27\chromedriver.exe')
self.title = title
def get_page_title(self):
return self.get_driver().title
Second one named login.py
from utils.methods import PagePatterns
from selenium.webdriver.common.by import By
from utils import paths
methods = PagePatterns()
class LoginPage(object):
def login(self):
country_choose = (By.XPATH, paths.country_list_login)
methods.click(country_choose)
Next one - register.py
from utils.methods import PagePatterns
from selenium.webdriver.common.by import By
from utils import utils, paths
from selenium.webdriver.support.wait import WebDriverWait
methods = PagePatterns()
class MainPage(object):
def open_homepage(self):
methods.open_base_page()
title_check = methods.get_page_title()
assert title_check == paths.page_title
The last one main_test.py is using LoginPage class
from register import MainPage
from login import LoginPage
MainPage().open_homepage()
LoginPage().login()
That's all about the code. My question is - when I am running main_test.py Chrome is called two times (two windows), but I want only one window of the browser - how to make it?
Thanks.

How to separate flask routes to another modules

I have hundreds of routes in my flask main module,
I think it need to separate those hundred of routes from the main module.
How to do it ?
#!/usr/bin/env python3
# -*- coding: utf8 -*-
from flask import request, url_for
from flask import Flask, request, jsonify
from flask_request_params import bind_request_params
from flask import g
import datetime
import pandas as pd
import pymongo
from webargs import Arg
from webargs.flaskparser import use_args, use_kwargs
import yaml
import time, functools
from pdb import set_trace
from pandas_helper import PandasHelper
import errors
from app_helper import *
from release_schedule import ReleaseSchedule
from mongo import Mongo
#app.route('/next_release', methods=["GET"])
#return_json
def next_release():
schedules = ReleaseSchedule.next_release(DB)
return pd.DataFrame([sche for sche in schedules])
...
#app.route('/last_release', methods=["GET"])
This is what blueprints were made to do.
Another alternative is flask-classy (which is awesome). I'm going to talk about the blueprint approach since that's what I know better.
If I was in your position I would want to split my routes up based on common imports.
Without knowning your application I'm going to guess that a distribution like this
parse_user_data_views.py
from webargs import Arg
from webargs.flaskparser import use_args, use_kwargs
import yaml
push_to_db_views.py
from pandas_helper import PandasHelper
from mongo import Mongo
import pymongo
import pandas as pd
import datetime
release_views.py
from release_schedule import ReleaseSchedule
import pandas as pd
#app.route('/next_release', methods=["GET"])
#return_json
def next_release():
schedules = ReleaseSchedule.next_release(DB)
return pd.DataFrame([sche for sche in schedules])
is likely distribution. We can't answer this for you, only you can.
But this allows you to separate out your application in some pretty nice ways.
in __init__.py
from flask import Flask
from yourapplication.release_views import release_views
from yourapplication.push_to_db_views import push_to_db_views
from yourapplication.parse_user_data_views import parse_user_data_views
app = Flask(__name__)
app.register_blueprint(release_views)
app.register_blueprint(push_to_db_views)
app.register_blueprint(parse_user_data_views)
Create a new file called views.py and add all your routes there. Then import views.py in your __ init __.py .

SAML generate metadata from entityId

I am trying to generate SAML metadata for Service provider,I have created simple servlet and trying to generate metadata in a methoad doGet()
this is the code I have tried below
import java.io.IOException;
import java.io.PrintWriter;
import java.net.HttpRetryException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.namespace.QName;
import org.opensaml.Configuration;
import org.opensaml.saml2.metadata.EntityDescriptor;
import org.opensaml.xml.XMLObjectBuilderFactory;
public class MetadataProviderServlet extends HttpServlet{
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
PrintWriter writer = response.getWriter();
response.setContentType("text/html");
writer.println("Hello world");
String entityId = "www.sampleEntityId.com";
XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
EntityDescriptor descriptor = (EntityDescriptor)(builderFactory.getBuilder(EntityDescriptor.DEFAULT_ELEMENT_NAME).buildObject(EntityDescriptor.DEFAULT_ELEMENT_NAME));
descriptor.setEntityID(entityId);
}
}
But when I run the web application using one application server I got the NUllpointer Exception in particularly creation the object Entity Descriptor.Can Anyone please figure out what went wrong?
You need to initialise the OpenSAML library first. OpenSAML is initialised using the bootstrap method.
DefaultBootstrap.bootstrap();
I write about this on my blog here

django import module with a system name

I would like to import a function from the views.py file of my import module.
The following code does not work: from import.views import myFunction. How to do?
**
Edit:
** So far I was able to import other files from the import module:
sys.path.append(settings.SITE_ROOT+'import')
import myFile as test
It doesn't seem to work for the view though, don't know why!