diff --git a/lens-server-api/src/main/java/org/apache/lens/server/api/metastore/DatabaseResourcesService.java b/lens-server-api/src/main/java/org/apache/lens/server/api/metastore/DatabaseResourcesService.java new file mode 100644 index 000000000..a7a26999e --- /dev/null +++ b/lens-server-api/src/main/java/org/apache/lens/server/api/metastore/DatabaseResourcesService.java @@ -0,0 +1,50 @@ +/** + * 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.server.api.metastore; + +import java.util.Date; +import java.util.List; + +import org.apache.lens.api.LensSessionHandle; +import org.apache.lens.api.metastore.*; +import org.apache.lens.server.api.LensService; +import org.apache.lens.server.api.error.LensException; + +import org.apache.hadoop.hive.ql.metadata.HiveException; + +/** + * Server api for OLAP Cube Databse. + */ +public interface DatabaseResourcesService extends LensService { + + /** The constant NAME */ + String NAME = "database"; + + + /** + * refresh database resources + * + * @param dbName + * @throws LensException + */ + void refreshDatabaseResources(String dbName) throws LensException; + + +} + diff --git a/lens-server/src/main/java/org/apache/lens/server/LensServices.java b/lens-server/src/main/java/org/apache/lens/server/LensServices.java index 48b3e002a..73b7fc97a 100644 --- a/lens-server/src/main/java/org/apache/lens/server/LensServices.java +++ b/lens-server/src/main/java/org/apache/lens/server/LensServices.java @@ -29,6 +29,7 @@ import org.apache.lens.server.api.ServiceProvider; import org.apache.lens.server.api.events.LensEventService; import org.apache.lens.server.api.metrics.MetricsService; +import org.apache.lens.server.metastore.DatabaseResourcesServiceImpl; import org.apache.lens.server.metrics.MetricsServiceImpl; import org.apache.lens.server.model.LogSegregationContext; import org.apache.lens.server.model.MappedDiagnosticLogSegregationContext; @@ -190,6 +191,7 @@ public synchronized void init(HiveConf hiveConf) { addService(new EventServiceImpl(LensEventService.NAME)); addService(new MetricsServiceImpl(MetricsService.NAME)); addService(new StatisticsService(StatisticsService.STATS_SVC_NAME)); + addService(new DatabaseResourcesServiceImpl(DatabaseResourcesServiceImpl.NAME)); // Add configured services, these are instances of LensService which need a CLIService instance // for session management diff --git a/lens-server/src/main/java/org/apache/lens/server/metastore/DatabaseResource.java b/lens-server/src/main/java/org/apache/lens/server/metastore/DatabaseResource.java new file mode 100644 index 000000000..df80fb5c2 --- /dev/null +++ b/lens-server/src/main/java/org/apache/lens/server/metastore/DatabaseResource.java @@ -0,0 +1,100 @@ +/** + * 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.server.metastore; + +import static org.apache.lens.api.APIResult.*; + +import java.util.List; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.xml.bind.JAXBElement; + +import org.apache.lens.api.APIResult; +import org.apache.lens.api.APIResult.*; +import org.apache.lens.api.DateTime; +import org.apache.lens.api.LensSessionHandle; +import org.apache.lens.api.StringList; +import org.apache.lens.api.metastore.*; +import org.apache.lens.server.LensServices; +import org.apache.lens.server.api.error.LensException; +import org.apache.lens.server.api.metastore.CubeMetastoreService; +import org.apache.lens.server.api.metastore.DatabaseResourcesService; + +import org.apache.commons.lang.NotImplementedException; +import org.apache.commons.lang3.StringUtils; +import org.apache.hadoop.hive.ql.metadata.HiveException; + +import com.google.common.collect.Lists; +import lombok.extern.slf4j.Slf4j; + +/** + * Database resource api + *
+ * This provides api for all things database. + */ +@Path("database") +@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) +@Slf4j +public class DatabaseResource { + + public static DatabaseResourcesService getSvc() { + return LensServices.get().getService(DatabaseResourcesService.NAME); + } + + private static LensException processLensException(LensException exc) { + if (exc != null) { + exc.buildLensErrorTO(LensServices.get().getErrorCollection()); + } + return exc; + } + + /** + * API to know if database service is up and running + * + * @return Simple text saying it up + */ + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getMessage() { + return "Database is up"; + } + + + /** + * Create a new database + * + * @param dbName The db name + * @return {@link APIResult} with state {@link Status#SUCCEEDED}, if create was successful. {@link APIResult} with + * state {@link Status#FAILED}, if create has failed + */ + @POST + @Path("refresh") + public APIResult refreshDatabaseResources(String dbName) { + log.info("Refresh database : ", dbName); + try { + getSvc().refreshDatabaseResources(dbName); + return success(); + } catch (LensException e) { + log.error("Error in refreshing database {}", dbName, e); + return failure(processLensException(e)); + } + } + +} \ No newline at end of file diff --git a/lens-server/src/main/java/org/apache/lens/server/metastore/DatabaseResourcesServiceImpl.java b/lens-server/src/main/java/org/apache/lens/server/metastore/DatabaseResourcesServiceImpl.java new file mode 100644 index 000000000..e590e580e --- /dev/null +++ b/lens-server/src/main/java/org/apache/lens/server/metastore/DatabaseResourcesServiceImpl.java @@ -0,0 +1,355 @@ +/** + * 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.server.metastore; + +import static org.apache.lens.server.metastore.JAXBUtils.*; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.*; + +import javax.ws.rs.BadRequestException; +import javax.ws.rs.NotFoundException; + +import org.apache.lens.api.LensSessionHandle; +import org.apache.lens.api.metastore.*; +import org.apache.lens.cube.metadata.*; +import org.apache.lens.cube.metadata.timeline.PartitionTimeline; +import org.apache.lens.server.BaseLensService; +import org.apache.lens.server.LensServerConf; +import org.apache.lens.server.LensServices; +import org.apache.lens.server.api.LensConfConstants; +import org.apache.lens.server.api.error.LensException; +import org.apache.lens.server.api.health.HealthStatus; +import org.apache.lens.server.api.metastore.CubeMetastoreService; +import org.apache.lens.server.api.metastore.DatabaseResourcesService; +import org.apache.lens.server.api.metrics.MetricsService; +import org.apache.lens.server.session.DatabaseResourceService; +import org.apache.lens.server.session.LensSessionImpl; +import org.apache.lens.server.util.ScannedPaths; + +import org.apache.commons.lang.StringUtils; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.metastore.IMetaStoreClient; +import org.apache.hadoop.hive.metastore.api.*; +import org.apache.hadoop.hive.ql.metadata.Hive; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.metadata.Partition; +import org.apache.hadoop.hive.ql.metadata.Table; +import org.apache.hive.service.AbstractService; +import org.apache.hive.service.cli.CLIService; + +import com.google.common.collect.Lists; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class DatabaseResourcesServiceImpl extends AbstractService implements DatabaseResourcesService { + + /** The Constant STATS_SVC_NAME. */ + public static final String NAME = "db-resources"; + + private Map