ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [01/65] [abbrv] incubator-ignite git commit: # ignite-63
Date Thu, 22 Jan 2015 21:26:48 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-63 550d60336 -> b458bd090


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/rest-http/src/main/java/org/gridgain/grid/kernal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/gridgain/grid/kernal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java
b/modules/rest-http/src/main/java/org/gridgain/grid/kernal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java
deleted file mode 100644
index cc89aa4..0000000
--- a/modules/rest-http/src/main/java/org/gridgain/grid/kernal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java
+++ /dev/null
@@ -1,409 +0,0 @@
-/*
- * 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.gridgain.grid.kernal.processors.rest.protocols.http.jetty;
-
-import org.apache.ignite.*;
-import org.apache.ignite.internal.*;
-import org.apache.ignite.spi.*;
-import org.eclipse.jetty.server.*;
-import org.eclipse.jetty.util.*;
-import org.eclipse.jetty.util.log.*;
-import org.eclipse.jetty.util.thread.*;
-import org.eclipse.jetty.xml.*;
-import org.gridgain.grid.kernal.processors.rest.*;
-import org.gridgain.grid.kernal.processors.rest.protocols.*;
-import org.apache.ignite.internal.util.typedef.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.jetbrains.annotations.*;
-import org.xml.sax.*;
-
-import java.io.*;
-import java.net.*;
-import java.util.*;
-
-import static org.apache.ignite.IgniteSystemProperties.*;
-import static org.apache.ignite.spi.IgnitePortProtocol.*;
-
-/**
- * Jetty REST protocol implementation.
- */
-public class GridJettyRestProtocol extends GridRestProtocolAdapter {
-    /**
-     *
-     */
-    static {
-        if (!IgniteSystemProperties.getBoolean(GG_JETTY_LOG_NO_OVERRIDE)) {
-            Properties p = new Properties();
-
-            p.setProperty("org.eclipse.jetty.LEVEL", "WARN");
-            p.setProperty("org.eclipse.jetty.util.log.LEVEL", "OFF");
-            p.setProperty("org.eclipse.jetty.util.component.LEVEL", "OFF");
-
-            StdErrLog.setProperties(p);
-
-            try {
-                Class<?> logCls = Class.forName("org.apache.log4j.Logger");
-
-                String ctgrJetty = "org.eclipse.jetty";                         // WARN for
this category.
-                String ctgrJettyUtil = "org.eclipse.jetty.util.log";            // ERROR
for this...
-                String ctgrJettyUtilComp = "org.eclipse.jetty.util.component";  // ...and
this.
-
-                Object logJetty = logCls.getMethod("getLogger", String.class).invoke(logCls,
ctgrJetty);
-                Object logJettyUtil = logCls.getMethod("getLogger", String.class).invoke(logCls,
ctgrJettyUtil);
-                Object logJettyUtilComp = logCls.getMethod("getLogger", String.class).invoke(logCls,
ctgrJettyUtilComp);
-
-                Class<?> lvlCls = Class.forName("org.apache.log4j.Level");
-
-                Object warnLvl = lvlCls.getField("WARN").get(null);
-                Object errLvl = lvlCls.getField("ERROR").get(null);
-
-                logJetty.getClass().getMethod("setLevel", lvlCls).invoke(logJetty, warnLvl);
-                logJettyUtil.getClass().getMethod("setLevel", lvlCls).invoke(logJetty, errLvl);
-                logJettyUtilComp.getClass().getMethod("setLevel", lvlCls).invoke(logJetty,
errLvl);
-            }
-            catch (Exception ignored) {
-                // No-op.
-            }
-        }
-    }
-
-    /** Jetty handler. */
-    private GridJettyRestHandler jettyHnd;
-
-    /** HTTP server. */
-    private Server httpSrv;
-
-    /**
-     * @param ctx Context.
-     */
-    public GridJettyRestProtocol(GridKernalContext ctx) {
-        super(ctx);
-    }
-
-    /** {@inheritDoc} */
-    @Override public String name() {
-        return "Jetty REST";
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("BusyWait")
-    @Override public void start(GridRestProtocolHandler hnd) throws IgniteCheckedException
{
-        assert ctx.config().getClientConnectionConfiguration() != null;
-
-        InetAddress locHost;
-
-        try {
-            locHost = U.resolveLocalHost(ctx.config().getLocalHost());
-        }
-        catch (IOException e) {
-            throw new IgniteCheckedException("Failed to resolve local host to bind address:
" + ctx.config().getLocalHost(), e);
-        }
-
-        System.setProperty(GG_JETTY_HOST, locHost.getHostAddress());
-
-        jettyHnd = new GridJettyRestHandler(hnd, new C1<String, Boolean>() {
-            @Override public Boolean apply(String tok) {
-                return F.isEmpty(secretKey) || authenticate(tok);
-            }
-        }, log);
-
-        String jettyPath = config().getRestJettyPath();
-
-        final URL cfgUrl;
-
-        if (jettyPath == null) {
-            cfgUrl = null;
-
-            if (log.isDebugEnabled())
-                log.debug("Jetty configuration file is not provided, using defaults.");
-        }
-        else {
-            cfgUrl = U.resolveGridGainUrl(jettyPath);
-
-            if (cfgUrl == null)
-                throw new IgniteSpiException("Invalid Jetty configuration file: " + jettyPath);
-            else if (log.isDebugEnabled())
-                log.debug("Jetty configuration file: " + cfgUrl);
-        }
-
-        loadJettyConfiguration(cfgUrl);
-
-        AbstractNetworkConnector connector = getJettyConnector();
-
-        try {
-            host = InetAddress.getByName(connector.getHost());
-        }
-        catch (UnknownHostException e) {
-            throw new IgniteCheckedException("Failed to resolve Jetty host address: " + connector.getHost(),
e);
-        }
-
-        int initPort = connector.getPort();
-
-        int lastPort = initPort + config().getRestPortRange() - 1;
-
-        for (port = initPort; port <= lastPort; port++) {
-            connector.setPort(port);
-
-            if (startJetty()) {
-                if (log.isInfoEnabled())
-                    log.info(startInfo());
-
-                return;
-            }
-        }
-
-        U.warn(log, "Failed to start Jetty REST server (possibly all ports in range are in
use) " +
-            "[firstPort=" + initPort + ", lastPort=" + lastPort + ']');
-    }
-
-    /**
-     * Checks {@link org.apache.ignite.IgniteSystemProperties#GG_JETTY_PORT} system property
-     * and overrides default connector port if it present.
-     * Then initializes {@code port} with the found value.
-     *
-     * @param con Jetty connector.
-     */
-    private void override(AbstractNetworkConnector con) {
-        String host = System.getProperty(GG_JETTY_HOST);
-
-        if (!F.isEmpty(host))
-            con.setHost(host);
-
-        int currPort = con.getPort();
-
-        Integer overridePort = Integer.getInteger(GG_JETTY_PORT);
-
-        if (overridePort != null && overridePort != 0)
-            currPort = overridePort;
-
-        con.setPort(currPort);
-        port = currPort;
-    }
-
-    /**
-     * @throws IgniteCheckedException If failed.
-     * @return {@code True} if Jetty started.
-     */
-    @SuppressWarnings("IfMayBeConditional")
-    private boolean startJetty() throws IgniteCheckedException {
-        try {
-            httpSrv.start();
-
-            if (httpSrv.isStarted()) {
-                for (Connector con : httpSrv.getConnectors()) {
-                    int connPort = ((NetworkConnector)con).getPort();
-
-                    if (connPort > 0)
-                        ctx.ports().registerPort(connPort, TCP, getClass());
-                }
-
-                return true;
-            }
-
-            return  false;
-        }
-        catch (SocketException ignore) {
-            if (log.isDebugEnabled())
-                log.debug("Failed to bind HTTP server to configured port.");
-
-            stopJetty();
-
-            return false;
-        }
-        catch (MultiException e) {
-            if (log.isDebugEnabled())
-                log.debug("Caught multi exception: " + e);
-
-            for (Object obj : e.getThrowables())
-                if (!(obj instanceof SocketException))
-                    throw new IgniteCheckedException("Failed to start Jetty HTTP server.",
e);
-
-            if (log.isDebugEnabled())
-                log.debug("Failed to bind HTTP server to configured port.");
-
-            stopJetty();
-
-            return false;
-        }
-        catch (Exception e) {
-            throw new IgniteCheckedException("Failed to start Jetty HTTP server.", e);
-        }
-    }
-
-    /**
-     * Loads jetty configuration from the given URL.
-     *
-     * @param cfgUrl URL to load configuration from.
-     * @throws IgniteCheckedException if load failed.
-     */
-    private void loadJettyConfiguration(@Nullable URL cfgUrl) throws IgniteCheckedException
{
-        if (cfgUrl == null) {
-            HttpConfiguration httpCfg = new HttpConfiguration();
-
-            httpCfg.setSecureScheme("https");
-            httpCfg.setSecurePort(8443);
-            httpCfg.setSendServerVersion(true);
-            httpCfg.setSendDateHeader(true);
-
-            String srvPortStr = System.getProperty(GG_JETTY_PORT, "8080");
-
-            int srvPort;
-
-            try {
-                srvPort = Integer.valueOf(srvPortStr);
-            }
-            catch (NumberFormatException ignore) {
-                throw new IgniteCheckedException("Failed to start Jetty server because GRIDGAIN_JETTY_PORT
system property " +
-                    "cannot be cast to integer: " + srvPortStr);
-            }
-
-            httpSrv = new Server(new QueuedThreadPool(20, 200));
-
-            ServerConnector srvConn = new ServerConnector(httpSrv, new HttpConnectionFactory(httpCfg));
-
-            srvConn.setHost(System.getProperty(GG_JETTY_HOST, "localhost"));
-            srvConn.setPort(srvPort);
-            srvConn.setIdleTimeout(30000L);
-            srvConn.setReuseAddress(true);
-
-            httpSrv.addConnector(srvConn);
-
-            httpSrv.setStopAtShutdown(false);
-        }
-        else {
-            XmlConfiguration cfg;
-
-            try {
-                cfg = new XmlConfiguration(cfgUrl);
-            }
-            catch (FileNotFoundException e) {
-                throw new IgniteSpiException("Failed to find configuration file: " + cfgUrl,
e);
-            }
-            catch (SAXException e) {
-                throw new IgniteSpiException("Failed to parse configuration file: " + cfgUrl,
e);
-            }
-            catch (IOException e) {
-                throw new IgniteSpiException("Failed to load configuration file: " + cfgUrl,
e);
-            }
-            catch (Exception e) {
-                throw new IgniteSpiException("Failed to start HTTP server with configuration
file: " + cfgUrl, e);
-            }
-
-            try {
-                httpSrv = (Server)cfg.configure();
-            }
-            catch (Exception e) {
-                throw new IgniteCheckedException("Failed to start Jetty HTTP server.", e);
-            }
-        }
-
-        assert httpSrv != null;
-
-        httpSrv.setHandler(jettyHnd);
-
-        override(getJettyConnector());
-    }
-
-    /**
-     * Checks that the only connector configured for the current jetty instance
-     * and returns it.
-     *
-     * @return Connector instance.
-     * @throws IgniteCheckedException If no or more than one connectors found.
-     */
-    private AbstractNetworkConnector getJettyConnector() throws IgniteCheckedException {
-        if (httpSrv.getConnectors().length == 1) {
-            Connector connector = httpSrv.getConnectors()[0];
-
-            if (!(connector instanceof AbstractNetworkConnector))
-                throw new IgniteCheckedException("Error in jetty configuration. Jetty connector
should extend " +
-                    "AbstractNetworkConnector class." );
-
-            return (AbstractNetworkConnector)connector;
-        }
-        else
-            throw new IgniteCheckedException("Error in jetty configuration [connectorsFound="
+
-                httpSrv.getConnectors().length + "connectorsExpected=1]");
-    }
-
-    /**
-     * Stops Jetty.
-     */
-    private void stopJetty() {
-        // Jetty does not really stop the server if port is busy.
-        try {
-            if (httpSrv != null) {
-                // If server was successfully started, deregister ports.
-                if (httpSrv.isStarted())
-                    ctx.ports().deregisterPorts(getClass());
-
-                // Record current interrupted status of calling thread.
-                boolean interrupted = Thread.interrupted();
-
-                try {
-                    httpSrv.stop();
-                }
-                finally {
-                    // Reset interrupted flag on calling thread.
-                    if (interrupted)
-                        Thread.currentThread().interrupt();
-                }
-            }
-        }
-        catch (InterruptedException ignored) {
-            if (log.isDebugEnabled())
-                log.debug("Thread has been interrupted.");
-
-            Thread.currentThread().interrupt();
-        }
-        catch (Exception e) {
-            U.error(log, "Failed to stop Jetty HTTP server.", e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void stop() {
-        stopJetty();
-
-        httpSrv = null;
-        jettyHnd = null;
-
-        if (log.isInfoEnabled())
-            log.info(stopInfo());
-    }
-
-    /** {@inheritDoc} */
-    @Override protected String getAddressPropertyName() {
-        return GridNodeAttributes.ATTR_REST_JETTY_ADDRS;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected String getHostNamePropertyName() {
-        return GridNodeAttributes.ATTR_REST_JETTY_HOST_NAMES;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected String getPortPropertyName() {
-        return GridNodeAttributes.ATTR_REST_JETTY_PORT;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(GridJettyRestProtocol.class, this);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/rest-http/src/main/java/org/gridgain/grid/kernal/processors/rest/protocols/http/jetty/favicon.ico
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/gridgain/grid/kernal/processors/rest/protocols/http/jetty/favicon.ico
b/modules/rest-http/src/main/java/org/gridgain/grid/kernal/processors/rest/protocols/http/jetty/favicon.ico
deleted file mode 100644
index 6f6ed44..0000000
Binary files a/modules/rest-http/src/main/java/org/gridgain/grid/kernal/processors/rest/protocols/http/jetty/favicon.ico
and /dev/null differ

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/rest-http/src/main/java/org/gridgain/grid/kernal/processors/rest/protocols/http/jetty/package.html
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/gridgain/grid/kernal/processors/rest/protocols/http/jetty/package.html
b/modules/rest-http/src/main/java/org/gridgain/grid/kernal/processors/rest/protocols/http/jetty/package.html
deleted file mode 100644
index e8d499d..0000000
--- a/modules/rest-http/src/main/java/org/gridgain/grid/kernal/processors/rest/protocols/http/jetty/package.html
+++ /dev/null
@@ -1,23 +0,0 @@
-<!--
-  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.
-  -->
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<body>
-    <!-- Package description. -->
-    REST HTTP Jetty protocol handler.
-</body>
-</html>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/rest-http/src/main/java/org/gridgain/grid/kernal/processors/rest/protocols/http/jetty/rest.html
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/gridgain/grid/kernal/processors/rest/protocols/http/jetty/rest.html
b/modules/rest-http/src/main/java/org/gridgain/grid/kernal/processors/rest/protocols/http/jetty/rest.html
deleted file mode 100644
index 06cb905..0000000
--- a/modules/rest-http/src/main/java/org/gridgain/grid/kernal/processors/rest/protocols/http/jetty/rest.html
+++ /dev/null
@@ -1,96 +0,0 @@
-<!--
-  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.
-  -->
-
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<head>
-    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
-    <meta http-equiv="Expires" content="-1">
-    <meta http-equiv="Pragma" content="no-cache">
-    <meta http-equiv="Cache-Control" content="no-cache">
-    <meta http-equiv="Content-language" content="en-US">
-    <meta http-equiv="Content-Type" content="text/html; CHARSET=UTF-8">
-    <meta http-equiv="Author" content="GridGain Systems, Inc., http://www.gridgain.com/">
-    <title>GridGain - In-Memory Data Fabric</title>
-    <style type="text/css">
-        body {
-            font-family: helvetica, verdana, arial, sans-serif;
-            font-size: 14px;
-            line-height: 1.5em;
-            color: #333;
-            margin: 10px;
-        }
-        a, a:visited, a:active, a:hover {
-            color: #333;
-            text-decoration: none;
-            border-bottom: 1px dotted;
-        }
-
-        a.img_link, a.img_link:visited, a.img_link:active, a.img_link:hover {
-            text-decoration: none;
-            border-bottom: 0;
-        }
-
-        img {
-            border: none;
-        }
-    </style>
-    <link rel="icon" type="image/x-icon" href="/favicon.ico"/>
-</head>
-<body>
-    <br>
-    <br>
-    <center>
-        <a class="img_link" href="http://www.gridgain.com" title="GridGain Systems">
-            <img src="http://gridgain.com/wp-content/uploads/2014/09/gridgain-red-logo-standard.png"
alt="GridGain - In-Memory Data Fabric">
-        </a>
-        <p>
-        <div style="width: 650px; text-align: justify; padding-top: 20px">
-            <h2>REST API</h2>
-            GridGain REST API supports
-            external connectivity to GridGain via REST over HTTP. It comes in handy whenever
GridGain Java API is not
-            available directly, but it is still needed to execute GridGain tasks or retrieve
cached data. For example,
-            you can conveniently use GridGain REST API over HTTP from other non-JVM languages,
such as Ruby, PHP or Python,
-            or any other language, whenever local instance of GridGain is not available.
-            <p>
-            Note that PHP REST example is included with GridGain distribution.
-            <p>
-            All REST HTTP commands have the following format: <code>http://1.2.3.4:8080/gridgain?cmd=CMD&amp;...</code>,
where
-            <code>'cmd'</code> is the name of the command followed by other command
parameters. Every command may have
-            different parameters, some of which may be mandatory and some optional. The commands
parameters may be
-            passed either via HTTP GET or POST, whichever one is preferred.
-        </div>
-        <br>
-        <br>
-        <a target=facebook class='img_link' href='http://www.facebook.com/profile.php?id=6458239494'>
-            <img border=0 align=absmiddle src='http://www.gridgain.com/images/facebook_small.png'>
-        </a>
-        &nbsp;&nbsp;
-        <a class='img_link' target=meetup href='http://www.meetup.com/GridGain-Bay-Area-Meetup-Group/'>
-            <img border=0 align=absmiddle src='http://www.gridgain.com/images/meetup_logo_small.png'
alt='Join GridGain Meetup'/>
-        </a>
-        &nbsp;&nbsp;
-        <a class='img_link' target=twitter href='http://www.twitter.com/gridgain'>
-            <img border=0 align=absmiddle src='http://www.gridgain.com/images/twitter.gif'
alt='Follow GridGain on Twitter'/>
-        </a>
-        &nbsp;&nbsp;
-        <a class='img_link' target=vimeo href='http://www.vimeo.com/gridgain'>
-            <img border=0 align=absmiddle src='http://www.gridgain.com/images/vimeo.png'
alt='Follow GridGain on Vimeo'/>
-        </a>
-    </center>
-</body>
-</html>


Mime
View raw message