
org.apache.lens.client.LensMetadataClient Maven / Gradle / Ivy
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.lens.client;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;
import javax.ws.rs.client.*;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.*;
import org.apache.lens.api.APIResult;
import org.apache.lens.api.DateTime;
import org.apache.lens.api.StringList;
import org.apache.lens.api.jaxb.LensJAXBContext;
import org.apache.lens.api.metastore.*;
import com.google.common.base.Joiner;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class LensMetadataClient {
private final LensConnection connection;
private final LensConnectionParams params;
private final ObjectFactory objFact;
public static final Unmarshaller JAXB_UNMARSHALLER;
static {
try {
JAXBContext jaxbContext = new LensJAXBContext(ObjectFactory.class);
JAXB_UNMARSHALLER = jaxbContext.createUnmarshaller();
} catch (JAXBException e) {
log.error("Could not initialize JAXBContext. ", e);
throw new RuntimeException("Could not initialize JAXBContext. ", e);
}
}
public LensMetadataClient(LensConnection connection) {
this.connection = connection;
this.params = connection.getLensConnectionParams();
objFact = new ObjectFactory();
}
private WebTarget getMetastoreWebTarget(Client client) {
return client.target(params.getBaseConnectionUrl()).path(
params.getMetastoreResourcePath());
}
private WebTarget getMetastoreWebTarget() {
return getMetastoreWebTarget(connection.buildClient());
}
public List getAlldatabases() {
WebTarget target = getMetastoreWebTarget();
StringList databases = target.path("databases")
.queryParam("sessionid", connection.getSessionHandle())
.request().get(StringList.class);
return databases.getElements();
}
public String getCurrentDatabase() {
WebTarget target = getMetastoreWebTarget();
return target.path("databases").path("current")
.queryParam("sessionid", connection.getSessionHandle())
.request().get(String.class);
}
public APIResult setDatabase(String database) {
WebTarget target = getMetastoreWebTarget();
return target.path("databases").path("current")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML_TYPE)
.put(Entity.xml(database), APIResult.class);
}
public APIResult createDatabase(String database, boolean ignoreIfExists) {
WebTarget target = getMetastoreWebTarget();
return target.path("databases")
.queryParam("sessionid", this.connection.getSessionHandle())
.queryParam("ignoreIfExisting", ignoreIfExists)
.request(MediaType.APPLICATION_XML)
.post(Entity.xml(database), APIResult.class);
}
public APIResult createDatabase(String database) {
return createDatabase(database, false);
}
public APIResult dropDatabase(String database, boolean cascade) {
WebTarget target = getMetastoreWebTarget();
return target.path("databases").path(database)
.queryParam("sessionid", this.connection.getSessionHandle())
.queryParam("cascade", cascade)
.request().delete(APIResult.class);
}
public APIResult dropDatabase(String database) {
return dropDatabase(database, false);
}
public List getAllNativeTables() {
WebTarget target = getMetastoreWebTarget();
StringList nativetables = target.path("nativetables")
.queryParam("sessionid", connection.getSessionHandle())
.request().get(StringList.class);
return nativetables.getElements();
}
public XNativeTable getNativeTable(String tblName) {
WebTarget target = getMetastoreWebTarget();
JAXBElement htable = target.path("nativetables").path(tblName)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML).get(new GenericType>() {
});
return htable.getValue();
}
public List getAllCubes() {
WebTarget target = getMetastoreWebTarget();
StringList cubes = target.path("cubes")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML).get(StringList.class);
return cubes.getElements();
}
public APIResult dropAllCubes() {
WebTarget target = getMetastoreWebTarget();
return target.path("cubes")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML).delete(APIResult.class);
}
public APIResult createCube(XCube cube) {
WebTarget target = getMetastoreWebTarget();
return target.path("cubes")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.post(Entity.xml(new GenericEntity>(objFact.createXCube(cube)){}), APIResult.class);
}
private T readFromXML(String filename) throws JAXBException, IOException {
if (filename.startsWith("/")) {
return ((JAXBElement) JAXB_UNMARSHALLER.unmarshal(new File(filename))).getValue();
} else {
// load from classpath
InputStream file = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
if (file == null) {
throw new IOException("File not found:" + filename);
}
return ((JAXBElement) JAXB_UNMARSHALLER.unmarshal(file)).getValue();
}
}
public APIResult createCube(String cubeSpec) {
try {
return createCube(this.readFromXML(cubeSpec));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public APIResult updateCube(String cubeName, XCube cube) {
WebTarget target = getMetastoreWebTarget();
return target.path("cubes").path(cubeName)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.put(Entity.xml(new GenericEntity>(objFact.createXCube(cube)){}), APIResult.class);
}
public APIResult updateCube(String cubeName, String cubeSpec) {
try {
return updateCube(cubeName, this.readFromXML(cubeSpec));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public XCube getCube(String cubeName) {
WebTarget target = getMetastoreWebTarget();
JAXBElement cube = target.path("cubes").path(cubeName)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML).get(new GenericType>() {
});
return cube.getValue();
}
public XFlattenedColumns getQueryableFields(String tableName, boolean flattened) {
WebTarget target = getMetastoreWebTarget();
JAXBElement fields = target.path("flattened").path(tableName)
.queryParam("sessionid", this.connection.getSessionHandle())
.queryParam("add_chains", flattened)
.request(MediaType.APPLICATION_XML).get(new GenericType>() {
});
return fields.getValue();
}
public XJoinChains getJoinChains(String tableName) {
WebTarget target = getMetastoreWebTarget();
JAXBElement fields = target.path("chains").path(tableName)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML).get(new GenericType>() {
});
return fields.getValue();
}
public APIResult dropCube(String cubeName) {
WebTarget target = getMetastoreWebTarget();
return target.path("cubes").path(cubeName)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML).delete(APIResult.class);
}
public List getAllDimensions() {
WebTarget target = getMetastoreWebTarget();
StringList dimensions = target.path("dimensions")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML).get(StringList.class);
return dimensions.getElements();
}
public APIResult dropAllDimensions() {
WebTarget target = getMetastoreWebTarget();
return target.path("dimensions")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML).delete(APIResult.class);
}
public APIResult createDimension(XDimension dimension) {
WebTarget target = getMetastoreWebTarget();
return target.path("dimensions")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.post(Entity.xml(new GenericEntity>(objFact.createXDimension(dimension)){}),
APIResult.class);
}
public APIResult createDimension(String dimSpec) {
try {
return createDimension(this.readFromXML(dimSpec));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public APIResult updateDimension(String dimName, XDimension dimension) {
WebTarget target = getMetastoreWebTarget();
return target.path("dimensions").path(dimName)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.put(Entity.xml(new GenericEntity>(objFact.createXDimension(dimension)){}),
APIResult.class);
}
public APIResult updateDimension(String dimName, String dimSpec) {
try {
return updateDimension(dimName, this.readFromXML(dimSpec));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public XDimension getDimension(String dimName) {
WebTarget target = getMetastoreWebTarget();
JAXBElement dim = target.path("dimensions").path(dimName)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML).get(new GenericType>() {
});
return dim.getValue();
}
public APIResult dropDimension(String dimName) {
WebTarget target = getMetastoreWebTarget();
return target.path("dimensions").path(dimName)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML).delete(APIResult.class);
}
public List getAllStorages() {
WebTarget target = getMetastoreWebTarget();
StringList storages = target.path("storages")
.queryParam("sessionid", this.connection.getSessionHandle())
.request().get(StringList.class);
return storages.getElements();
}
public APIResult createNewStorage(XStorage storage) {
WebTarget target = getMetastoreWebTarget();
return target.path("storages")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.post(Entity.xml(new GenericEntity>(objFact.createXStorage(storage)){}), APIResult.class);
}
public APIResult createNewStorage(String storage) {
try {
return createNewStorage(this.readFromXML(storage));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public APIResult dropAllStorages() {
WebTarget target = getMetastoreWebTarget();
return target.path("storages")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.delete(APIResult.class);
}
public APIResult updateStorage(String storageName, XStorage storage) {
WebTarget target = getMetastoreWebTarget();
return target.path("storages").path(storageName)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.put(Entity.xml(new GenericEntity>(objFact.createXStorage(storage)){}), APIResult.class);
}
public APIResult updateStorage(String storageName, String storage) {
try {
return updateStorage(storageName, this.readFromXML(storage));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public XStorage getStorage(String storageName) {
WebTarget target = getMetastoreWebTarget();
JAXBElement result = target.path("storages").path(storageName)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.get(new GenericType>() {
});
return result.getValue();
}
public APIResult dropStorage(String storageName) {
WebTarget target = getMetastoreWebTarget();
return target.path("storages").path(storageName)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.delete(APIResult.class);
}
public List getAllFactTables(String cubeName) {
if (cubeName == null) {
return getAllFactTables();
}
WebTarget target = getMetastoreWebTarget();
StringList factTables;
factTables = target.path("cubes").path(cubeName).path("facts")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.get(StringList.class);
return factTables.getElements();
}
public List getAllFactTables() {
WebTarget target = getMetastoreWebTarget();
StringList factTables;
factTables = target.path("facts")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.get(StringList.class);
return factTables.getElements();
}
public APIResult deleteAllFactTables(boolean cascade) {
WebTarget target = getMetastoreWebTarget();
return target.path("facts")
.queryParam("sessionid", this.connection.getSessionHandle())
.queryParam("cascade", cascade)
.request(MediaType.APPLICATION_XML)
.delete(APIResult.class);
}
public XFactTable getFactTable(String factTableName) {
WebTarget target = getMetastoreWebTarget();
JAXBElement table = target.path("facts").path(factTableName)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.get(new GenericType>() {
});
return table.getValue();
}
public APIResult createFactTable(XFactTable f) {
WebTarget target = getMetastoreWebTarget();
return target.path("facts")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.post(Entity.xml(new GenericEntity>(objFact.createXFactTable(f)){}), APIResult.class);
}
public APIResult createFactTable(String factSpec) {
try {
return createFactTable(this.readFromXML(factSpec));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public APIResult updateFactTable(String factName, XFactTable table) {
WebTarget target = getMetastoreWebTarget();
return target.path("facts").path(factName)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML_TYPE)
.put(Entity.xml(new GenericEntity>(objFact.createXFactTable(table)){}), APIResult.class);
}
public APIResult updateFactTable(String factName, String table) {
try {
return updateFactTable(factName, this.readFromXML(table));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public APIResult dropFactTable(String factName, boolean cascade) {
WebTarget target = getMetastoreWebTarget();
return target.path("facts").path(factName)
.queryParam("sessionid", this.connection.getSessionHandle())
.queryParam("cascade", cascade)
.request(MediaType.APPLICATION_XML)
.delete(APIResult.class);
}
public APIResult dropFactTable(String factName) {
return dropFactTable(factName, false);
}
public List getAllStoragesOfFactTable(String factName) {
WebTarget target = getMetastoreWebTarget();
StringList storageList = target.path("facts").path(factName).path("storages")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.get(StringList.class);
return storageList.getElements();
}
public APIResult dropAllStoragesOfFactTable(String factName) {
WebTarget target = getMetastoreWebTarget();
return target.path("facts").path(factName).path("storages")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.delete(APIResult.class);
}
public APIResult addStorageToFactTable(String factname, XStorageTableElement storage) {
WebTarget target = getMetastoreWebTarget();
return target.path("facts").path(factname).path("storages")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.post(Entity.xml(new GenericEntity>(
objFact.createXStorageTableElement(storage)){}), APIResult.class);
}
public APIResult addStorageToFactTable(String factname, String storageSpec) {
try {
return addStorageToFactTable(factname, this.readFromXML(storageSpec));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public APIResult dropStorageFromFactTable(String factName, String storageName) {
WebTarget target = getMetastoreWebTarget();
return target.path("facts").path(factName).path("storages").path(storageName)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.delete(APIResult.class);
}
public XStorageTableElement getStorageOfFactTable(String factName, String storageName) {
WebTarget target = getMetastoreWebTarget();
JAXBElement element = target.path("facts")
.path(factName).path("storages").path(storageName)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.get(new GenericType>() {
});
return element.getValue();
}
public List getPartitionsOfFactTable(String factName, String storage, String filter) {
WebTarget target = getMetastoreWebTarget();
JAXBElement elements = target.path("facts").path(factName)
.path("storages").path(storage).path("partitions")
.queryParam("sessionid", this.connection.getSessionHandle())
.queryParam("filter", filter)
.request(MediaType.APPLICATION_XML)
.get(new GenericType>() {
});
return elements.getValue().getPartition();
}
public List getPartitionsOfFactTable(String factName, String storage) {
return getPartitionsOfFactTable(factName, storage, "");
}
public APIResult dropPartitionsOfFactTable(String factName, String storage, String filter) {
WebTarget target = getMetastoreWebTarget();
return target.path("facts").path(factName)
.path("storages").path(storage).path("partitions")
.queryParam("sessionid", this.connection.getSessionHandle())
.queryParam("filter", filter)
.request(MediaType.APPLICATION_XML)
.delete(APIResult.class);
}
public APIResult dropPartitionsOfFactTable(String factName, String storage) {
return dropPartitionsOfFactTable(factName, storage, "");
}
public APIResult dropPartitionsOfFactTable(String factName, String storage,
List partitions) {
String values = Joiner.on(",").skipNulls().join(partitions);
WebTarget target = getMetastoreWebTarget();
return target.path("facts").path(factName)
.path("storages").path(storage).path("partitions")
.queryParam("sessionid", this.connection.getSessionHandle())
.queryParam("values", values)
.request(MediaType.APPLICATION_XML)
.delete(APIResult.class);
}
public List getAllDimensionTables(String dimensionName) {
if (dimensionName == null) {
return getAllDimensionTables();
}
WebTarget target = getMetastoreWebTarget();
StringList dimtables;
dimtables = target.path("dimensions").path(dimensionName).path("dimtables")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.get(StringList.class);
return dimtables.getElements();
}
public List getAllDimensionTables() {
WebTarget target = getMetastoreWebTarget();
StringList dimtables;
dimtables = target.path("dimtables")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.get(StringList.class);
return dimtables.getElements();
}
public APIResult createDimensionTable(XDimensionTable table) {
WebTarget target = getMetastoreWebTarget();
return target.path("dimtables")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.post(Entity.xml(new GenericEntity>(objFact.createXDimensionTable(table)){}),
APIResult.class);
}
public APIResult createDimensionTable(String tableXml) {
try {
return createDimensionTable(this.readFromXML(tableXml));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public APIResult updateDimensionTable(XDimensionTable table) {
String dimTableName = table.getTableName();
WebTarget target = getMetastoreWebTarget();
return target.path("dimtables").path(dimTableName)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.put(Entity.xml(new GenericEntity>(objFact.createXDimensionTable(table)){}),
APIResult.class);
}
public APIResult updateDimensionTable(String dimTblName, String dimSpec) {
try {
XDimensionTable dimensionTable = readFromXML(dimSpec);
dimensionTable.setTableName(dimTblName);
return updateDimensionTable(dimensionTable);
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public APIResult dropDimensionTable(String table, boolean cascade) {
WebTarget target = getMetastoreWebTarget();
return target.path("dimtables").path(table)
.queryParam("sessionid", this.connection.getSessionHandle())
.queryParam("cascade", cascade)
.request(MediaType.APPLICATION_XML)
.delete(APIResult.class);
}
public APIResult dropDimensionTable(String table) {
return dropDimensionTable(table, false);
}
public XDimensionTable getDimensionTable(String table) {
WebTarget target = getMetastoreWebTarget();
JAXBElement result = target.path("dimtables").path(table)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.get(new GenericType>() {
});
return result.getValue();
}
public List getAllStoragesOfDimTable(String dimTblName) {
WebTarget target = getMetastoreWebTarget();
StringList list = target.path("dimtables").path(dimTblName).path("storages")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.get(StringList.class);
return list.getElements();
}
public APIResult addStorageToDimTable(String dimTblName, XStorageTableElement table) {
WebTarget target = getMetastoreWebTarget();
return target.path("dimtables").path(dimTblName).path("storages")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.post(Entity.xml(new GenericEntity>(
objFact.createXStorageTableElement(table)){}), APIResult.class);
}
public APIResult addStorageToDimTable(String dimTblName, String table) {
try {
return addStorageToDimTable(dimTblName, this.readFromXML(table));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public XStorageTableElement getStorageOfDimensionTable(String dimTblName, String storage) {
WebTarget target = getMetastoreWebTarget();
JAXBElement result = target.path("dimtables").path(dimTblName)
.path("storages").path(storage)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.get(new GenericType>() {
});
return result.getValue();
}
public APIResult dropAllStoragesOfDimension(String dimTblName) {
WebTarget target = getMetastoreWebTarget();
return target.path("dimtables").path(dimTblName).path("storages")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.delete(APIResult.class);
}
public APIResult dropStoragesOfDimensionTable(String dimTblName, String storage) {
WebTarget target = getMetastoreWebTarget();
return target.path("dimtables").path(dimTblName)
.path("storages").path(storage)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.delete(APIResult.class);
}
public List getAllPartitionsOfDimensionTable(String dimTblName, String storage,
String filter) {
WebTarget target = getMetastoreWebTarget();
JAXBElement partList = target.path("dimtables").path(dimTblName)
.path("storages").path(storage).path("partitions")
.queryParam("sessionid", this.connection.getSessionHandle())
.queryParam("filter", filter)
.request(MediaType.APPLICATION_XML)
.get(new GenericType>() {
});
return partList.getValue().getPartition();
}
public List getAllPartitionsOfDimensionTable(String dimTblName, String storage) {
return getAllPartitionsOfDimensionTable(dimTblName, storage, "");
}
public APIResult dropAllPartitionsOfDimensionTable(String dimTblName, String storage,
String filter) {
WebTarget target = getMetastoreWebTarget();
return target.path("dimtables").path(dimTblName)
.path("storages").path(storage).path("partitions")
.queryParam("sessionid", this.connection.getSessionHandle())
.queryParam("filter", filter)
.request(MediaType.APPLICATION_XML)
.delete(APIResult.class);
}
public APIResult dropAllPartitionsOfDimensionTable(String dimTblName, String storage) {
return dropAllPartitionsOfDimensionTable(dimTblName, storage, "");
}
public APIResult dropAllPartitionsOfDimensionTable(String dimTblName, String storage,
List vals) {
String values = Joiner.on(",").skipNulls().join(vals);
WebTarget target = getMetastoreWebTarget();
return target.path("dimtables").path(dimTblName)
.path("storages").path(storage).path("partitions")
.queryParam("sessionid", this.connection.getSessionHandle())
.queryParam("values", values)
.request(MediaType.APPLICATION_XML)
.delete(APIResult.class);
}
public APIResult addPartitionToDimensionTable(String dimTblName, String storage,
XPartition partition) {
WebTarget target = getMetastoreWebTarget();
return target.path("dimtables").path(dimTblName)
.path("storages").path(storage).path("partition")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.post(Entity.xml(new GenericEntity>(objFact.createXPartition(partition)){}),
APIResult.class);
}
public APIResult addPartitionToDimensionTable(String dimTblName, String storage,
String partitionSpec) {
try {
return addPartitionToDimensionTable(dimTblName, storage, (XPartition) readFromXML(partitionSpec));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public APIResult addPartitionsToDimensionTable(String dimTblName, String storage,
XPartitionList partitions) {
WebTarget target = getMetastoreWebTarget();
return target.path("dimtables").path(dimTblName)
.path("storages").path(storage).path("partitions")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.post(Entity.xml(new GenericEntity>(objFact.createXPartitionList(partitions)){}),
APIResult.class);
}
public APIResult addPartitionsToDimensionTable(String dimTblName, String storage,
String partitionsSpec) {
try {
return addPartitionsToDimensionTable(dimTblName, storage, (XPartitionList) readFromXML(partitionsSpec));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public APIResult addPartitionToFactTable(String fact, String storage,
XPartition partition) {
WebTarget target = getMetastoreWebTarget();
return target.path("facts").path(fact)
.path("storages").path(storage).path("partition")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.post(Entity.xml(new GenericEntity>(objFact.createXPartition(partition)){}),
APIResult.class);
}
public APIResult addPartitionToFactTable(String fact, String storage,
String partitionSpec) {
try {
return addPartitionToFactTable(fact, storage, (XPartition) readFromXML(partitionSpec));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public APIResult addPartitionsToFactTable(String fact, String storage,
XPartitionList partitions) {
WebTarget target = getMetastoreWebTarget();
return target.path("facts").path(fact)
.path("storages").path(storage).path("partitions")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.post(Entity.xml(new GenericEntity>(objFact.createXPartitionList(partitions)){}),
APIResult.class);
}
public APIResult addPartitionsToFactTable(String fact, String storage,
String partitionsSpec) {
try {
return addPartitionsToFactTable(fact, storage, (XPartitionList) readFromXML(partitionsSpec));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public APIResult updatePartitionOfDimensionTable(String dimTblName, String storage,
XPartition partition) {
WebTarget target = getMetastoreWebTarget();
return target.path("dimtables").path(dimTblName)
.path("storages").path(storage).path("partition")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.put(Entity.xml(new GenericEntity>(objFact.createXPartition(partition)){}),
APIResult.class);
}
public APIResult updatePartitionOfDimensionTable(String dimTblName, String storage,
String partitionSpec) {
try {
return updatePartitionOfDimensionTable(dimTblName, storage, (XPartition) readFromXML(partitionSpec));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public APIResult updatePartitionsOfDimensionTable(String dimTblName, String storage,
XPartitionList partitions) {
WebTarget target = getMetastoreWebTarget();
return target.path("dimtables").path(dimTblName)
.path("storages").path(storage).path("partitions")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.put(Entity.xml(new GenericEntity>(objFact.createXPartitionList(partitions)){}),
APIResult.class);
}
public APIResult updatePartitionsOfDimensionTable(String dimTblName, String storage,
String partitionsSpec) {
try {
return updatePartitionsOfDimensionTable(dimTblName, storage, (XPartitionList) readFromXML(partitionsSpec));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public APIResult updatePartitionOfFactTable(String fact, String storage,
XPartition partition) {
WebTarget target = getMetastoreWebTarget();
return target.path("facts").path(fact)
.path("storages").path(storage).path("partition")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.put(Entity.xml(new GenericEntity>(objFact.createXPartition(partition)){}),
APIResult.class);
}
public APIResult updatePartitionOfFactTable(String fact, String storage,
String partitionSpec) {
try {
return updatePartitionOfFactTable(fact, storage, (XPartition) readFromXML(partitionSpec));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public APIResult updatePartitionsOfFactTable(String fact, String storage,
XPartitionList partitions) {
WebTarget target = getMetastoreWebTarget();
return target.path("facts").path(fact)
.path("storages").path(storage).path("partitions")
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.put(Entity.xml(new GenericEntity>(objFact.createXPartitionList(partitions)){}),
APIResult.class);
}
public APIResult updatePartitionsOfFactTable(String fact, String storage,
String partitionsSpec) {
try {
return updatePartitionsOfFactTable(fact, storage, (XPartitionList) readFromXML(partitionsSpec));
} catch (JAXBException | IOException e) {
return failureAPIResult(e);
}
}
public Date getLatestDateOfCube(String cubeName, String timePartition) {
return getMetastoreWebTarget().path("cubes").path(cubeName).path("latestdate")
.queryParam("timeDimension", timePartition)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.get(DateTime.class).getDate();
}
public List getPartitionTimelines(String factName, String storageName, String updatePeriod,
String timeDimension) {
return getMetastoreWebTarget().path("facts").path(factName).path("timelines")
.queryParam("storage", storageName)
.queryParam("updatePeriod", updatePeriod)
.queryParam("timeDimension", timeDimension)
.queryParam("sessionid", this.connection.getSessionHandle())
.request(MediaType.APPLICATION_XML)
.get(StringList.class).getElements();
}
private APIResult failureAPIResult(Exception e) {
log.error("Failed", e);
return APIResult.failure(e);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy