Skip to content

Commit 8d7fb38

Browse files
committed
Merge branch 'main' into bug6240
2 parents a45954c + 8e7915c commit 8d7fb38

File tree

6 files changed

+36
-7
lines changed

6 files changed

+36
-7
lines changed

configuration/environments_scripts/sailing_server/files/usr/local/bin/refreshInstance.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ install_environment ()
153153
load_from_release_file ()
154154
{
155155
if [[ ${INSTALL_FROM_RELEASE} == "" ]]; then
156-
GITHUB_RELEASE=$( curl -L "https://api.github.com/repos/SAP/sailing-analytics/releases?per_page=100" 2>/dev/null | jq -r 'sort_by(.created_at) | reverse | map(select(.name | startswith("main-")))[0].assets[] | select(.content_type=="application/x-tar")' )
156+
GITHUB_RELEASE=$( curl -L "https://api.github.com/repos/SAP/sailing-analytics/releases?per_page=100" 2>/dev/null | jq -r 'map(select(.name | startswith("main-")) | .assets[] | select(.content_type=="application/x-tar")) | sort_by(.created_at) | reverse | first' )
157157
INSTALL_FROM_RELEASE=$( echo "${GITHUB_RELEASE}" | jq -r '.name' | sed -e 's/\.tar\.gz$//' )
158158
echo "You didn't provide a release. Defaulting to latest main branch build ${INSTALL_FROM_RELEASE}"
159159
else
160-
GITHUB_RELEASE=$( curl -L "https://api.github.com/repos/SAP/sailing-analytics/releases?per_page=100" 2>/dev/null | jq -r 'sort_by(.created_at) | reverse | map(select(.name=="'${INSTALL_FROM_RELEASE}'"))[0].assets[] | select(.content_type=="application/x-tar")' )
160+
GITHUB_RELEASE=$( curl -L "https://api.github.com/repos/SAP/sailing-analytics/releases?per_page=100" 2>/dev/null | jq -r 'map(select(.name=="'${INSTALL_FROM_RELEASE}'") | .assets[] | select(.content_type=="application/x-tar")) | sort_by(.created_at) | reverse | first' )
161161
fi
162162
if which mail; then
163163
if [ -n "${BUILD_COMPLETE_NOTIFY}" ]; then

java/com.sap.sailing.server/SailingServer (No Proxy).launch

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<setAttribute key="deselected_workspace_bundles"/>
1515
<booleanAttribute key="includeOptional" value="false"/>
1616
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
17+
<mapAttribute key="org.eclipse.debug.core.environmentVariables">
18+
<mapEntry key="GITHUB_TOKEN" value="${GITHUB_TOKEN}"/>
19+
</mapAttribute>
1720
<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.pde.ui.launcher.PDESourceLookupDirector"/>
1821
<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;sourceLookupDirector&gt;&#13;&#10; &lt;sourceContainers duplicates=&quot;false&quot;&gt;&#13;&#10; &lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;directory nest=&amp;quot;false&amp;quot; path=&amp;quot;C:\Users\georg\Documents\Business\Kunden\OIO\SAPsailing\jetty.project\apache-jsp\src\main\java&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.debug.core.containerType.directory&quot;/&gt;&#13;&#10; &lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;classpathContainer path=&amp;quot;com.google.gwt.eclipse.core.GWT_CONTAINER&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.jdt.launching.sourceContainer.classpathContainer&quot;/&gt;&#13;&#10; &lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;default/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.debug.core.containerType.default&quot;/&gt;&#13;&#10; &lt;/sourceContainers&gt;&#13;&#10;&lt;/sourceLookupDirector&gt;&#13;&#10;"/>
1922
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">

java/com.sap.sse.landscape/src/com/sap/sse/landscape/impl/GithubReleasesRepository.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.io.InputStream;
55
import java.io.InputStreamReader;
6+
import java.net.HttpURLConnection;
67
import java.net.MalformedURLException;
78
import java.net.URL;
89
import java.net.URLConnection;
@@ -24,6 +25,7 @@
2425

2526
import com.sap.sse.common.Duration;
2627
import com.sap.sse.common.TimePoint;
28+
import com.sap.sse.common.Util;
2729
import com.sap.sse.common.Util.Pair;
2830
import com.sap.sse.landscape.Release;
2931
import com.sap.sse.landscape.ReleaseRepository;
@@ -153,8 +155,8 @@ private ReleaseIterator() throws MalformedURLException, IOException, ParseExcept
153155
} else {
154156
logger.fine(()->"Need to fetch page with newest releases because last request was at "+
155157
(lastFetchOfNewestReleases==null?"<never>":lastFetchOfNewestReleases));
156-
lastFetchOfNewestReleases = now;
157158
fillCacheWithNewestReleases();
159+
lastFetchOfNewestReleases = now;
158160
}
159161
cachedReleasesIterator = releasesByPublishingTimePoint.descendingMap().values().iterator();
160162
}
@@ -215,14 +217,36 @@ public GithubReleasesRepository(String owner, String repositoryName, String defa
215217
* cache when this method is invoked.
216218
* <p>
217219
*
220+
* If the {@code GITHUB_TOKEN} environment variable is set, it is used as a bearer token forthe Github requests,
221+
* resulting in a higher rate limit. If no token is set, or if using the token results in a 401 response code
222+
* (authentication failed), an unauthenticated request is tried instead.
223+
* <p>
224+
*
218225
* The method makes no changes to the cache or any other state of this instance.
219226
*
220227
* @return the link to the next page in the returned pair's {@link Pair#getA() A component}, and the sequence of
221228
* releases loaded from that page with their publishing time points, ordered from newest to oldest.
222229
*/
223230
private synchronized Pair<String, Iterable<Pair<TimePoint, GithubRelease>>> getReleasesFromPage(String pageURL) throws IOException, ParseException {
224231
logger.info("Requesting releases page "+pageURL);
225-
final URLConnection connection = HttpUrlConnectionHelper.redirectConnection(new URL(pageURL));
232+
final URLConnection connection;
233+
final String githubToken = System.getenv("GITHUB_TOKEN");
234+
if (Util.hasLength(githubToken)) {
235+
final HttpURLConnection authenticatedConnectionAttempt = (HttpURLConnection) HttpUrlConnectionHelper
236+
.redirectConnectionWithBearerToken(new URL(pageURL), githubToken);
237+
if (authenticatedConnectionAttempt.getResponseCode() == 401) {
238+
try {
239+
authenticatedConnectionAttempt.disconnect();
240+
} catch (Exception e) {
241+
logger.warning("Couldn't disconnect from Github: "+e.getMessage());
242+
}
243+
connection = HttpUrlConnectionHelper.redirectConnection(new URL(pageURL));
244+
} else {
245+
connection = authenticatedConnectionAttempt;
246+
}
247+
} else {
248+
connection = HttpUrlConnectionHelper.redirectConnection(new URL(pageURL));
249+
}
226250
final InputStream index = (InputStream) connection.getContent();
227251
final String xRatelimitRemaining = connection.getHeaderField("x-ratelimit-remaining");
228252
logger.fine(()->""+xRatelimitRemaining+" requests left in this hour");

java/target/compareServers

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ if [ "${useRestApi}" = "1" ]; then
6868
shift
6969
done
7070
CURL_OUTPUT=$( curl -sL --dump-header "${HEADERS}" -H 'Content-Type: multipart/form-data' "${NEWSERVER}/sailingserver/api/v1/compareservers" -d "server2=${OLDSERVER}" ${AUTH} ${LEADERBOARD_GROUPS} 2>${WGET_ERR} )
71-
echo "${CURL_OUTPUT}" | jq
71+
echo "${CURL_OUTPUT}"
7272
HTTP_STATUS=$( cat "${HEADERS}" | grep "^HTTP\/[0-9.]* [0-9]\{3\}" | tail -1 | sed -e 's/^HTTP\/[0-9.]* \([0-9]\{3\}\).*$/\1/' )
7373
rm -f "${HEADERS}"
7474
MESSAGE_SUFFIX=". HTTP_STATUS was ${HTTP_STATUS}."
7575
if [[ "${HTTP_STATUS}" =~ 2.. ]]; then
76-
echo "Success${MESSAGE_SUFFIX}"
76+
echo "Success${MESSAGE_SUFFIX}" >&2
7777
exit 0
7878
else
79-
echo "Failed${MESSAGE_SUFFIX}"
79+
echo "Failed${MESSAGE_SUFFIX}" >&2
8080
exit ${HTTP_STATUS}
8181
fi
8282
else

java/target/env-default-rules.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,4 @@ fi
140140
if [ -n "${GEONAMES_ORG_USERNAMES}" ]; then
141141
ADDITIONAL_JAVA_ARGS="${ADDITIONAL_JAVA_ARGS} -Dgeonames.org.usernames=${GEONAMES_ORG_USERNAMES}"
142142
fi
143+
export GITHUB_TOKEN

wiki/howto/onboarding.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Go to Window ⇒ Preferences and change the following two settings:
115115
- For YouTube API access, provide an Eclipse variable ``YOUTUBE_API_KEY``. You can use your own Google developer account to create such a key; see [here](https://console.cloud.google.com).
116116
- In case you need to test with the payment provider (ChargeBee) active, you need to provide Eclipse variables (Run/Rebug ⇒ String Substitution) ``CHARGEBEE_SITE`` and ``CHARGEBEE_API_KEY`` where the recommendation is to use ``sailytics-test`` for the site and a corresponding test API key; there is one launch configuration running against the live ChargeBee site, but its use is not recommended for obvious reasons. For it, define the variables ``CHARGEBEE_SITE_LIVE`` and ``CHARGEBEE_API_KEY_LIVE``, respectively.
117117
- To successfully obtain polar and wind estimation data from ``sapsailing.com``, you need to define the Eclipse variables (Run/Debug ⇒ String Substitution) ``POLAR_DATA_BEARER_TOKEN`` and ``WIND_ESTIMATION_MODEL_BEARER_TOKEN`` that need to authenticate a user with permissions to read the respective models.
118+
- Define a ``GITHUB_TOKEN`` variable; it may be empty (but has to be generally present), or you can use it to set a personal access token (PAT) which will then be used, in particular, for requesting application releases from GitHub.
118119
- To work with the wind estimation model training launch configuration (e.g., SimpleModelsTrainingPart1.launch), define an Eclipse variable (Run/Debug ⇒ String Substitution) ``SAPSAILING_BEARER_TOKEN`` which needs to authenticate a user eligible to read all maneuver data from sapsailing.com
119120
- In "GWT ⇒ Errors/Warnings" set "Missing SDK" to "Ignore"
120121
- In "GWT ⇒ GWT Settings ⇒ Add..." add the GWT SDK you downloaded and unpacked earlier

0 commit comments

Comments
 (0)