Skip to content

Commit dd6c994

Browse files
committed
Spring Insight service always available
The Spring Insight framework is different than all of the other services because it downloads its dependency from the service itself, rather than from a central location. It does however honor the Internet availability flag even though it doesn't go to the Internet. This caused issues when an offline buildpack was used because it prevented the proper dependency from being downloaded. This change adds the ability to _temporarily_ override the value of Internet availability so that the Spring Insight framework can always download its dependencies, regardless of the current state of internet connectivity. [#70850900]
1 parent 876f77a commit dd6c994

4 files changed

Lines changed: 53 additions & 3 deletions

File tree

lib/java_buildpack/framework/spring_insight.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
# limitations under the License.
1616

1717
require 'java_buildpack/component/base_component'
18+
require 'java_buildpack/util/cache/internet_availability'
1819
require 'java_buildpack/framework'
20+
require 'java_buildpack/util/dash_case'
1921
require 'tmpdir'
2022
require 'fileutils'
2123
require 'uri'
@@ -41,7 +43,9 @@ def detect
4143

4244
# (see JavaBuildpack::Component::BaseComponent#compile)
4345
def compile
44-
download(@version, @uri.chomp('/') + AGENT_DOWNLOAD_URI_SUFFIX) { |file| expand file } # TODO: AGENT_DOWNLOAD_URI_SUFFIX To be removed once the full path is included in VCAP_SERVICES see issue 58873498
46+
JavaBuildpack::Util::Cache::InternetAvailability.instance.available(true, 'The Spring Insight download location is always accessible') do
47+
download(@version, @uri.chomp('/') + AGENT_DOWNLOAD_URI_SUFFIX) { |file| expand file } # TODO: AGENT_DOWNLOAD_URI_SUFFIX To be removed once the full path is included in VCAP_SERVICES see issue 58873498
48+
end
4549
end
4650

4751
# (see JavaBuildpack::Component::BaseComponent#release)

lib/java_buildpack/util/cache/internet_availability.rb

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,20 @@ def available?
4747
#
4848
# @param [Boolean] available whether the internet is available
4949
# @param [String, nil] message an optional message to be printed when the availability is set
50+
# @yields an environment with internet availability temporarily overridden if block given
5051
def available(available, message = nil)
5152
@monitor.synchronize do
52-
@available = available
53-
@logger.warn { "Internet availability set to #{available}: #{message}" } if message
53+
if block_given?
54+
preserve_availability do
55+
@available = available
56+
@logger.warn { "Internet availability temporarily set to #{available}: #{message}" } if message
57+
58+
yield
59+
end
60+
else
61+
@available = available
62+
@logger.warn { "Internet availability set to #{available}: #{message}" } if message
63+
end
5464
end
5565
end
5666

@@ -60,6 +70,15 @@ def remote_downloads?
6070
JavaBuildpack::Util::ConfigurationUtils.load('cache')['remote_downloads'] != 'disabled'
6171
end
6272

73+
def preserve_availability
74+
previous = @available
75+
begin
76+
yield
77+
ensure
78+
@available = previous
79+
end
80+
end
81+
6382
end
6483

6584
end

spec/java_buildpack/framework/spring_insight_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
require 'spec_helper'
1818
require 'component_helper'
1919
require 'fileutils'
20+
require 'internet_availability_helper'
2021
require 'java_buildpack/framework/spring_insight'
2122

2223
describe JavaBuildpack::Framework::SpringInsight do
2324
include_context 'component_helper'
25+
include_context 'internet_availability_helper'
2426

2527
it 'should not detect without spring-insight-n/a service' do
2628
expect(component.detect).to be_nil
@@ -51,6 +53,13 @@
5153
expect(sandbox + 'insight/conf/insight.properties').to exist
5254
end
5355

56+
it 'should guarantee that internet access is available when downloading' do
57+
expect_any_instance_of(JavaBuildpack::Util::Cache::InternetAvailability)
58+
.to receive(:available).with(true, 'The Spring Insight download location is always accessible')
59+
60+
component.compile
61+
end
62+
5463
it 'should update JAVA_OPTS',
5564
app_fixture: 'framework_spring_insight' do
5665

spec/java_buildpack/util/cache/internet_availability_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,22 @@
5555
expect(log_contents).to match(/Internet availability set to false: test message/)
5656
end
5757

58+
it 'should temporarily set internet unavailable' do
59+
expect(described_class.instance.available?).to be
60+
61+
described_class.instance.available(false) { expect(described_class.instance.available?).not_to be }
62+
63+
expect(described_class.instance.available?).to be
64+
end
65+
66+
it 'should temporarily set internet available',
67+
:disable_internet do
68+
69+
expect(described_class.instance.available?).not_to be
70+
71+
described_class.instance.available(true) { expect(described_class.instance.available?).to be }
72+
73+
expect(described_class.instance.available?).not_to be
74+
end
75+
5876
end

0 commit comments

Comments
 (0)