http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/main/resources/brooklyn/entity/network/bind/named.loopback ---------------------------------------------------------------------- diff --git a/software/network/src/main/resources/brooklyn/entity/network/bind/named.loopback b/software/network/src/main/resources/brooklyn/entity/network/bind/named.loopback deleted file mode 100644 index 38d701d..0000000 --- a/software/network/src/main/resources/brooklyn/entity/network/bind/named.loopback +++ /dev/null @@ -1,31 +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. -; -; -; BIND reverse data for the local loopback interface -; -$TTL 1W -@ IN SOA localhost. root.localhost. ( - 1 ; serial - 1W ; refresh - 1D ; retry - 1M ; expire - 1M ) ; ttl -; -@ IN NS localhost. -1.0.0 IN PTR localhost.
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/main/resources/brooklyn/entity/network/bind/resolv.conf ---------------------------------------------------------------------- diff --git a/software/network/src/main/resources/brooklyn/entity/network/bind/resolv.conf b/software/network/src/main/resources/brooklyn/entity/network/bind/resolv.conf deleted file mode 100644 index ade4ce0..0000000 --- a/software/network/src/main/resources/brooklyn/entity/network/bind/resolv.conf +++ /dev/null @@ -1,25 +0,0 @@ -[#ftl] -# -# 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. -# -# Generated by Brooklyn on ${.now?string.short} -# -# -search ${entity.domainName} -nameserver ${driver.address} -nameserver 8.8.8.8 http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/main/resources/brooklyn/entity/network/bind/reverse.zone ---------------------------------------------------------------------- diff --git a/software/network/src/main/resources/brooklyn/entity/network/bind/reverse.zone b/software/network/src/main/resources/brooklyn/entity/network/bind/reverse.zone deleted file mode 100644 index 6966e1e..0000000 --- a/software/network/src/main/resources/brooklyn/entity/network/bind/reverse.zone +++ /dev/null @@ -1,37 +0,0 @@ -[#ftl] -;; -;; 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. -;; -;; Generated by Brooklyn on ${.now?string.short} -;; -[#noparse]$TTL[/#noparse] 86400 -@ IN SOA ns1.${entity.domainName}. root.${entity.domainName}. ( - ${entity.serial?c} ; serial - 3600 ; refresh - 1800 ; retry - 604800 ; expire - 86400 ; ttl -) -${entity.reverseLookupDomain}. IN NS ns1.${entity.domainName}. -${entity.reverseLookupDomain}. IN NS ns2.${entity.domainName}. -ns1 IN A ${driver.address} -ns2 IN A ${driver.address} - -[#list entity.pointerRecords?keys as address] -${address} IN PTR ${entity.pointerRecords[address]}.${entity.domainName}. -[/#list] http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/main/resources/brooklyn/entity/network/bind/rfc1912.zone ---------------------------------------------------------------------- diff --git a/software/network/src/main/resources/brooklyn/entity/network/bind/rfc1912.zone b/software/network/src/main/resources/brooklyn/entity/network/bind/rfc1912.zone deleted file mode 100644 index 1de4650..0000000 --- a/software/network/src/main/resources/brooklyn/entity/network/bind/rfc1912.zone +++ /dev/null @@ -1,52 +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. -// -// Zones recommended in RFC 1912 section 4.1. -// -// See https://www.ietf.org/rfc/rfc1912.txt. -// - -zone "localhost" { - type master; - file "${driver.osSupport.configDirectory}/named.localhost"; - allow-update { none; }; -}; - -zone "127.in-addr.arpa" { - type master; - file "${driver.osSupport.configDirectory}/named.loopback"; - allow-update { none; }; -}; - -zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN { - type master; - file "${driver.osSupport.configDirectory}/named.loopback"; - allow-update { none; }; -}; - -zone "0.in-addr.arpa" { - type master; - file "${driver.osSupport.configDirectory}/named.empty"; - allow-update { none; }; -}; - -zone "255.in-addr.arpa" { - type master; - file "${driver.osSupport.configDirectory}/named.empty"; - allow-update { none; }; -}; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/domain.zone ---------------------------------------------------------------------- diff --git a/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/domain.zone b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/domain.zone new file mode 100644 index 0000000..671d234 --- /dev/null +++ b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/domain.zone @@ -0,0 +1,46 @@ +[#ftl] +;; +;; 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. +;; +;; Generated by Brooklyn on ${.now?string.short} +;; +;; +[#noparse]$TTL[/#noparse] 86400 +@ IN SOA ns1.${entity.domainName}. root.${entity.domainName}. ( + ${entity.serial?c} ; serial + 3600 ; refresh + 1800 ; retry + 604800 ; expire + 86400 ; ttl +) +@ IN NS ns1.${entity.domainName}. +@ IN NS ns2.${entity.domainName}. +ns1 IN A ${driver.address} +ns2 IN A ${driver.address} + +;; Addresses +[#list entity.addressRecords?keys as address] +${address} IN A ${entity.addressRecords[address]} +[/#list] + +;; Canonical names +[#list entity.cnamesForTemplates?keys as aRecord] +[#list entity.cnamesForTemplates[aRecord] as cname] +${cname} IN CNAME ${aRecord} +[/#list] +[/#list] http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/ifcfg ---------------------------------------------------------------------- diff --git a/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/ifcfg b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/ifcfg new file mode 100644 index 0000000..b8b310d --- /dev/null +++ b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/ifcfg @@ -0,0 +1,24 @@ +[#ftl] +# +# 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. +# +# Generated by Brooklyn on ${.now?string.short} +# +DOMAIN=${entity.domainName} +DNS1=${driver.address} +DNS2=8.8.8.8 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.conf ---------------------------------------------------------------------- diff --git a/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.conf b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.conf new file mode 100644 index 0000000..5dd10d7 --- /dev/null +++ b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.conf @@ -0,0 +1,63 @@ +[#ftl] +// +// 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. +// +// Generated by Brooklyn on ${.now?string.short} +// +options { + listen-on port ${entity.dnsPort} { 127.0.0.1; ${driver.address}; }; + listen-on-v6 port ${entity.dnsPort} { ::1; }; + directory "${driver.osSupport.configDirectory}"; + dump-file "${driver.dataDirectory}/cache_dump.db"; + statistics-file "${driver.dataDirectory}/named_stats.txt"; + memstatistics-file "${driver.dataDirectory}/named_mem_stats.txt"; + allow-query { localhost; ${entity.managementCidr}; }; + allow-transfer { localhost; ${driver.address}; }; + recursion yes; + dnssec-enable yes; + dnssec-validation yes; + dnssec-lookaside auto; + bindkeys-file "${driver.osSupport.keysFile}"; + managed-keys-directory "${driver.dynamicDirectory}"; +}; + +logging { + channel default_debug { + file "${driver.dataDirectory}/named.run"; + severity dynamic; + }; +}; + +zone "." IN { + type hint; + file "${driver.osSupport.rootZonesFile}"; +}; + +zone "${entity.reverseLookupDomain}" IN { + type master; + file "${driver.reverseZoneFile}"; + allow-update { none; }; +}; + +zone "${entity.domainName}" IN { + type master; + file "${driver.domainZoneFile}"; + allow-update { none; }; +}; + +include "${driver.rfc1912ZonesFile}"; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.empty ---------------------------------------------------------------------- diff --git a/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.empty b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.empty new file mode 100644 index 0000000..3197b41 --- /dev/null +++ b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.empty @@ -0,0 +1,30 @@ +; +; 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. +; +; +; Reverse data for the broadcast zone +; +$TTL 1W +@ IN SOA localhost. root.localhost. ( + 1 ; serial + 1W ; refresh + 1D ; retry + 1M ; expire + 1M ) ; ttl +; +@ IN NS localhost. http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.localhost ---------------------------------------------------------------------- diff --git a/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.localhost b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.localhost new file mode 100644 index 0000000..c683a83 --- /dev/null +++ b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.localhost @@ -0,0 +1,32 @@ +; +; 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. +; +; +; BIND data for the local loopback interface +; +$TTL 1W +@ IN SOA localhost. root.localhost. ( + 1 ; serial + 1W ; refresh + 1D ; retry + 1M ; expire + 1M ) ; ttl +; +@ IN NS localhost. +@ IN A 127.0.0.1 +@ IN AAAA ::1 http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.loopback ---------------------------------------------------------------------- diff --git a/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.loopback b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.loopback new file mode 100644 index 0000000..38d701d --- /dev/null +++ b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/named.loopback @@ -0,0 +1,31 @@ +; +; 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. +; +; +; BIND reverse data for the local loopback interface +; +$TTL 1W +@ IN SOA localhost. root.localhost. ( + 1 ; serial + 1W ; refresh + 1D ; retry + 1M ; expire + 1M ) ; ttl +; +@ IN NS localhost. +1.0.0 IN PTR localhost. http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/resolv.conf ---------------------------------------------------------------------- diff --git a/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/resolv.conf b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/resolv.conf new file mode 100644 index 0000000..ade4ce0 --- /dev/null +++ b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/resolv.conf @@ -0,0 +1,25 @@ +[#ftl] +# +# 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. +# +# Generated by Brooklyn on ${.now?string.short} +# +# +search ${entity.domainName} +nameserver ${driver.address} +nameserver 8.8.8.8 http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/reverse.zone ---------------------------------------------------------------------- diff --git a/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/reverse.zone b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/reverse.zone new file mode 100644 index 0000000..6966e1e --- /dev/null +++ b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/reverse.zone @@ -0,0 +1,37 @@ +[#ftl] +;; +;; 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. +;; +;; Generated by Brooklyn on ${.now?string.short} +;; +[#noparse]$TTL[/#noparse] 86400 +@ IN SOA ns1.${entity.domainName}. root.${entity.domainName}. ( + ${entity.serial?c} ; serial + 3600 ; refresh + 1800 ; retry + 604800 ; expire + 86400 ; ttl +) +${entity.reverseLookupDomain}. IN NS ns1.${entity.domainName}. +${entity.reverseLookupDomain}. IN NS ns2.${entity.domainName}. +ns1 IN A ${driver.address} +ns2 IN A ${driver.address} + +[#list entity.pointerRecords?keys as address] +${address} IN PTR ${entity.pointerRecords[address]}.${entity.domainName}. +[/#list] http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/rfc1912.zone ---------------------------------------------------------------------- diff --git a/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/rfc1912.zone b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/rfc1912.zone new file mode 100644 index 0000000..1de4650 --- /dev/null +++ b/software/network/src/main/resources/org/apache/brooklyn/entity/network/bind/rfc1912.zone @@ -0,0 +1,52 @@ +// +// 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. +// +// Zones recommended in RFC 1912 section 4.1. +// +// See https://www.ietf.org/rfc/rfc1912.txt. +// + +zone "localhost" { + type master; + file "${driver.osSupport.configDirectory}/named.localhost"; + allow-update { none; }; +}; + +zone "127.in-addr.arpa" { + type master; + file "${driver.osSupport.configDirectory}/named.loopback"; + allow-update { none; }; +}; + +zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN { + type master; + file "${driver.osSupport.configDirectory}/named.loopback"; + allow-update { none; }; +}; + +zone "0.in-addr.arpa" { + type master; + file "${driver.osSupport.configDirectory}/named.empty"; + allow-update { none; }; +}; + +zone "255.in-addr.arpa" { + type master; + file "${driver.osSupport.configDirectory}/named.empty"; + allow-update { none; }; +}; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerByonLiveTest.java ---------------------------------------------------------------------- diff --git a/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerByonLiveTest.java b/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerByonLiveTest.java deleted file mode 100644 index 1eed359..0000000 --- a/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerByonLiveTest.java +++ /dev/null @@ -1,45 +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 brooklyn.entity.network.bind; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.Optional; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - -import brooklyn.entity.BrooklynAppLiveTestSupport; -import brooklyn.location.Location; -import brooklyn.util.text.Strings; - -public class BindDnsServerByonLiveTest extends BrooklynAppLiveTestSupport { - - private static final Logger LOG = LoggerFactory.getLogger(BindDnsServerByonLiveTest.class); - - @Test(groups = "Live") - @Parameters({"locationSpec"}) - public void testDns(@Optional String locationSpec) throws Exception { - if (Strings.isBlank(locationSpec)) { - LOG.info("{} got no spec, skipping test", this); - } else { - Location testLocation = mgmt.getLocationRegistry().resolve(locationSpec); - BindDnsServerLiveTest.testBindStartsAndUpdates(app, testLocation); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerEc2LiveTest.java ---------------------------------------------------------------------- diff --git a/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerEc2LiveTest.java b/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerEc2LiveTest.java deleted file mode 100644 index dafcf3f..0000000 --- a/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerEc2LiveTest.java +++ /dev/null @@ -1,63 +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 brooklyn.entity.network.bind; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import brooklyn.entity.AbstractEc2LiveTest; -import brooklyn.location.Location; - -public class BindDnsServerEc2LiveTest extends AbstractEc2LiveTest { - private static final Logger LOG = LoggerFactory.getLogger(BindDnsServerEc2LiveTest.class); - - protected void doTest(Location testLocation) throws Exception { - BindDnsServerLiveTest.testBindStartsAndUpdates(app, testLocation); - } - - @Override - public void test_Red_Hat_Enterprise_Linux_6() throws Exception { - super.test_Red_Hat_Enterprise_Linux_6(); - } - - @Override - public void test_CentOS_6_3() throws Exception { - super.test_CentOS_6_3(); - } - - @Override - public void test_Debian_7_2() throws Exception { - super.test_Debian_7_2(); - } - - @Override - public void test_Debian_6() throws Exception { - LOG.debug("{} skipped Debian 6 test", this); - } - - @Override - public void test_Ubuntu_10_0() throws Exception { - LOG.debug("{} skipped Ubuntu 10 test", this); - } - - @Override - public void test_CentOS_5() throws Exception { - LOG.debug("{} skipped CentOS 5.6 test", this); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java ---------------------------------------------------------------------- diff --git a/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java b/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java deleted file mode 100644 index 66d3be0..0000000 --- a/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java +++ /dev/null @@ -1,261 +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 brooklyn.entity.network.bind; - -import static org.testng.Assert.assertEquals; - -import org.apache.brooklyn.test.EntityTestUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.Test; - -import com.google.common.base.Functions; -import com.google.common.base.Joiner; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; - -import brooklyn.enricher.Enrichers; -import brooklyn.entity.Entity; -import brooklyn.entity.basic.ApplicationBuilder; -import brooklyn.entity.basic.Attributes; -import brooklyn.entity.basic.EmptySoftwareProcess; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.EntityLocal; -import brooklyn.entity.basic.EntityPredicates; -import brooklyn.entity.group.DynamicCluster; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.rebind.RebindOptions; -import brooklyn.entity.rebind.RebindTestFixture; -import brooklyn.policy.EnricherSpec; -import brooklyn.test.entity.TestApplication; - -public class BindDnsServerIntegrationTest extends RebindTestFixture<TestApplication> { - - private static final Logger LOG = LoggerFactory.getLogger(BindDnsServerIntegrationTest.class); - private BindDnsServer dns; - private DynamicCluster cluster; - - @Override - protected TestApplication createApp() { - TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class, origManagementContext); - dns = app.createAndManageChild(EntitySpec.create(BindDnsServer.class, TestBindDnsServerImpl.class) - .configure(BindDnsServer.ENTITY_FILTER, Predicates.instanceOf(EmptySoftwareProcess.class)) - .configure(BindDnsServer.HOSTNAME_SENSOR, PrefixAndIdEnricher.SENSOR)); - EntitySpec<EmptySoftwareProcess> memberSpec = EntitySpec.create(EmptySoftwareProcess.class) - .enricher(EnricherSpec.create(PrefixAndIdEnricher.class) - .configure(PrefixAndIdEnricher.PREFIX, "dns-integration-test-") - .configure(PrefixAndIdEnricher.MONITOR, Attributes.HOSTNAME)); - cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) - .configure(DynamicCluster.MEMBER_SPEC, memberSpec) - .configure(DynamicCluster.INITIAL_SIZE, 3)); - return app; - } - - @Test(groups = "Integration") - public void testOneARecordAndNoCnameRecordsWhenEntitiesHaveSameName() { - TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class, origManagementContext); - EnricherSpec<?> dnsEnricher = Enrichers.builder().transforming(Attributes.HOSTNAME) - .computing(Functions.constant("my-name")) - .publishing(PrefixAndIdEnricher.SENSOR) - .build(); - EntitySpec<EmptySoftwareProcess> emptySoftwareProcessSpec = EntitySpec.create(EmptySoftwareProcess.class) - .enricher(dnsEnricher); - dns = app.createAndManageChild(EntitySpec.create(BindDnsServer.class, TestBindDnsServerImpl.class) - .configure(BindDnsServer.HOSTNAME_SENSOR, PrefixAndIdEnricher.SENSOR)); - - // App DNS will listen to - cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) - .configure(DynamicCluster.MEMBER_SPEC, emptySoftwareProcessSpec) - .configure(DynamicCluster.INITIAL_SIZE, 3)); - - app.start(ImmutableList.of(app.newLocalhostProvisioningLocation())); - - assertDnsEntityEventuallyHasActiveMembers(1); - // All of the entities publish the same domain name so there should be a single DNS entry and no CNAMEs. - assertMapSizes(1, 1, 0, 1); - } - - @Test(groups = "Integration") - public void testDuplicateAAndCnameRecordsAreIgnored() { - TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class, origManagementContext); - EnricherSpec<?> enricher1 = Enrichers.builder().transforming(Attributes.HOSTNAME) - .computing(Functions.constant("my-name-1")) - .publishing(PrefixAndIdEnricher.SENSOR) - .build(); - EnricherSpec<?> enricher2 = Enrichers.builder().transforming(Attributes.HOSTNAME) - .computing(Functions.constant("my-name-2")) - .publishing(PrefixAndIdEnricher.SENSOR) - .build(); - dns = app.createAndManageChild(EntitySpec.create(BindDnsServer.class, TestBindDnsServerImpl.class) - .configure(BindDnsServer.HOSTNAME_SENSOR, PrefixAndIdEnricher.SENSOR)); - - // Expect one of my-name-{1,2} to be used as the A record the other to be used as the CNAME. - // Expect all duplicate records to be ignored. - app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher1)); - app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher1)); - app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher1)); - app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher2)); - app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher2)); - app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher2)); - app.start(ImmutableList.of(app.newLocalhostProvisioningLocation())); - - assertDnsEntityEventuallyHasActiveMembers(2); - assertMapSizes(2, 1, 1, 1); - } - - @Test(groups = "Integration") - public void testStripsInvalidCharactersFromHostname() { - origApp.start(ImmutableList.of(origApp.newLocalhostProvisioningLocation())); - cluster.resize(1); - assertDnsEntityEventuallyHasActiveMembers(1); - EntityLocal e = (EntityLocal) Iterables.getOnlyElement(cluster.getMembers()); - e.setAttribute(PrefixAndIdEnricher.SENSOR, " _-pretend.hostname.10.0.0.7.my-cloud.com"); - EntityTestUtils.assertAttributeEqualsEventually(dns, BindDnsServer.A_RECORDS, - ImmutableMap.of("pretend-hostname-10-0-0-7-my-cloud-com", e.getAttribute(Attributes.ADDRESS))); - } - - @Test(groups = "Integration") - public void testHostnameTruncatedTo63Characters() { - origApp.start(ImmutableList.of(origApp.newLocalhostProvisioningLocation())); - cluster.resize(1); - assertDnsEntityEventuallyHasActiveMembers(1); - EntityLocal e = (EntityLocal) Iterables.getOnlyElement(cluster.getMembers()); - e.setAttribute(PrefixAndIdEnricher.SENSOR, Strings.repeat("a", 171)); - EntityTestUtils.assertAttributeEqualsEventually(dns, BindDnsServer.A_RECORDS, - ImmutableMap.of(Strings.repeat("a", 63), e.getAttribute(Attributes.ADDRESS))); - } - - @Test(groups = "Integration") - public void testCanConfigureToListenToChildrenOfEntityOtherThanParent() { - // Ignoring origApp - TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class, origManagementContext); - - EnricherSpec<PrefixAndIdEnricher> dnsEnricher = EnricherSpec.create(PrefixAndIdEnricher.class) - .configure(PrefixAndIdEnricher.PREFIX, "dns-integration-test-") - .configure(PrefixAndIdEnricher.MONITOR, Attributes.HOSTNAME); - EntitySpec<EmptySoftwareProcess> emptySoftwareProcessSpec = EntitySpec.create(EmptySoftwareProcess.class) - .enricher(dnsEnricher); - - // App DNS will listen to - cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) - .configure(DynamicCluster.MEMBER_SPEC, emptySoftwareProcessSpec) - .configure(DynamicCluster.INITIAL_SIZE, 3)); - - // Apps that DNS should not listen to. Appreciate that their having dnsEnricher is unrealistic! - app.createAndManageChild(emptySoftwareProcessSpec); - app.createAndManageChild(emptySoftwareProcessSpec); - - Predicate<Entity> entityFilter = Predicates.and( - Predicates.instanceOf(EmptySoftwareProcess.class), - EntityPredicates.isChildOf(cluster)); - dns = app.createAndManageChild(EntitySpec.create(BindDnsServer.class, TestBindDnsServerImpl.class) - .configure(BindDnsServer.ENTITY_FILTER, entityFilter) - .configure(BindDnsServer.HOSTNAME_SENSOR, PrefixAndIdEnricher.SENSOR)); - - app.start(ImmutableList.of(app.newLocalhostProvisioningLocation())); - logDnsMappings(); - assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).keySet().size(), 1); - assertMapSizes(3, 1, 2, 1); - - cluster.resize(4); - EntityTestUtils.assertAttributeEqualsEventually(cluster, DynamicCluster.GROUP_SIZE, 4); - assertDnsEntityEventuallyHasActiveMembers(4); - assertMapSizes(4, 1, 3, 1); - - } - - @Test(invocationCount=1, groups = "Integration") - public void testRebindDns() throws Throwable { - origApp.start(ImmutableList.of(origApp.newLocalhostProvisioningLocation())); - logDnsMappings(); - assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).keySet().size(), 1); - assertMapSizes(3, 1, 2, 1); - - rebind(RebindOptions.create().mementoDirBackup(mementoDirBackup)); - try { - dns = (BindDnsServer) Iterables.getOnlyElement(Iterables.filter(newApp.getChildren(), Predicates.instanceOf(BindDnsServer.class))); - cluster = (DynamicCluster) Iterables.getOnlyElement(Iterables.filter(newApp.getChildren(), Predicates.instanceOf(DynamicCluster.class))); - - // assert original attributes restored and the server can be updated. - logDnsMappings(); - assertMapSizes(3, 1, 2, 1); - cluster.resize(1); - assertDnsEntityEventuallyHasActiveMembers(1); - logDnsMappings(); - EntityTestUtils.assertAttributeEqualsEventually(cluster, DynamicCluster.GROUP_SIZE, 1); - assertMapSizes(1, 1, 0, 1); - cluster.resize(5); - assertDnsEntityEventuallyHasActiveMembers(5); - logDnsMappings(); - EntityTestUtils.assertAttributeEqualsEventually(cluster, DynamicCluster.GROUP_SIZE, 5); - assertMapSizes(5, 1, 4, 1); - } catch (Throwable t) { - // Failing in jenkins occasionally; don't know why and can't reproduce. - // Therefore dumping out lots more info on failure. - LOG.error("Test failed; dumping out contents of original persistence dir used for rebind...", t); - dumpMementoDir(mementoDirBackup); - throw t; - } - } - - @Test(groups = "Integration") - public void testMapsSeveralEntitiesOnOneMachine() { - origApp.start(ImmutableList.of(origApp.newLocalhostProvisioningLocation())); - EntityTestUtils.assertAttributeEqualsEventually(dns, Attributes.SERVICE_UP, true); - logDnsMappings(); - - // One host with one A, two CNAME and one PTR record - assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).keySet().size(), 1); - assertMapSizes(3, 1, 2, 1); - String key = Iterables.getOnlyElement(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).keySet()); - assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).get(key).size(), 3); - - Entities.dumpInfo(dns); - } - - private void assertMapSizes(int addresses, int aRecords, int cnameRecords, int ptrRecords) { - assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).entries().size(), addresses, "Mismatched address mappings"); - assertEquals(dns.getAttribute(BindDnsServer.A_RECORDS).size(), aRecords, "Mismatched A records"); - assertEquals(dns.getAttribute(BindDnsServer.CNAME_RECORDS).size(), cnameRecords, "Mismatched CNAME records"); - assertEquals(dns.getAttribute(BindDnsServer.PTR_RECORDS).size(), ptrRecords, "Mismatched PTR records"); - } - - private void logDnsMappings() { - LOG.info("A: " + Joiner.on(", ").withKeyValueSeparator("=").join( - dns.getAttribute(BindDnsServer.A_RECORDS))); - LOG.info("CNAME: " + Joiner.on(", ").withKeyValueSeparator("=").join( - dns.getAttribute(BindDnsServer.CNAME_RECORDS).asMap())); - LOG.info("PTR: " + Joiner.on(", ").withKeyValueSeparator("=").join( - dns.getAttribute(BindDnsServer.PTR_RECORDS))); - } - - private void assertDnsEntityEventuallyHasActiveMembers(final int size) { - EntityTestUtils.assertPredicateEventuallyTrue(dns, new Predicate<BindDnsServer>() { - @Override - public boolean apply(BindDnsServer input) { - return input.getAddressMappings().size() == size; - } - }); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerLiveTest.java ---------------------------------------------------------------------- diff --git a/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerLiveTest.java b/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerLiveTest.java deleted file mode 100644 index 2dfc177..0000000 --- a/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerLiveTest.java +++ /dev/null @@ -1,114 +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 brooklyn.entity.network.bind; - -import static org.apache.brooklyn.test.EntityTestUtils.assertAttributeEqualsEventually; -import static org.testng.Assert.assertEquals; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Joiner; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableList; - -import brooklyn.entity.basic.Attributes; -import brooklyn.entity.basic.EmptySoftwareProcess; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.SameServerEntity; -import brooklyn.entity.group.DynamicCluster; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.location.Location; -import brooklyn.policy.EnricherSpec; -import brooklyn.test.entity.TestApplication; -import brooklyn.util.repeat.Repeater; -import brooklyn.util.time.Duration; - -public class BindDnsServerLiveTest { - - private static final Logger LOG = LoggerFactory.getLogger(BindDnsServerLiveTest.class); - - public static void testBindStartsAndUpdates(TestApplication app, Location testLocation) throws Exception { - DynamicCluster cluster; - BindDnsServer dns; - - SameServerEntity sse = app.createAndManageChild(EntitySpec.create(SameServerEntity.class)); - EntitySpec<EmptySoftwareProcess> memberSpec = EntitySpec.create(EmptySoftwareProcess.class) - .enricher(EnricherSpec.create(PrefixAndIdEnricher.class) - .configure(PrefixAndIdEnricher.PREFIX, "dns-live-test-") - .configure(PrefixAndIdEnricher.MONITOR, Attributes.HOSTNAME)); - cluster = sse.addChild(EntitySpec.create(DynamicCluster.class) - .configure(DynamicCluster.MEMBER_SPEC, memberSpec) - .configure(DynamicCluster.INITIAL_SIZE, 1)); - dns = sse.addChild((EntitySpec.create(BindDnsServer.class) - .configure(BindDnsServer.ENTITY_FILTER, Predicates.instanceOf(EmptySoftwareProcess.class)) - .configure(BindDnsServer.HOSTNAME_SENSOR, PrefixAndIdEnricher.SENSOR))); - Entities.manage(cluster); - Entities.manage(dns); - - app.start(ImmutableList.of(testLocation)); - assertAttributeEqualsEventually(dns, Attributes.SERVICE_UP, true); - - logDnsMappings(dns); - assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).entries().size(), 1); - assertEquals(dns.getAttribute(BindDnsServer.A_RECORDS).size(), 1); - assertEquals(dns.getAttribute(BindDnsServer.CNAME_RECORDS).size(), 0); - // Harder to make assertions on PTR because the entity servers might not be in the right CIDR - - cluster.resize(2); - waitForNumberOfAddressMappings(dns, 2); - logDnsMappings(dns); - assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).entries().size(), 2); - assertEquals(dns.getAttribute(BindDnsServer.A_RECORDS).size(), 1); - assertEquals(dns.getAttribute(BindDnsServer.CNAME_RECORDS).size(), 1); - - cluster.resize(1); - waitForNumberOfAddressMappings(dns, 1); - logDnsMappings(dns); - assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).entries().size(), 1); - assertEquals(dns.getAttribute(BindDnsServer.A_RECORDS).size(), 1); - assertEquals(dns.getAttribute(BindDnsServer.CNAME_RECORDS).size(), 0); - } - - private static void logDnsMappings(BindDnsServer dns) { - LOG.info("A: " + Joiner.on(", ").withKeyValueSeparator("=").join( - dns.getAttribute(BindDnsServer.A_RECORDS))); - LOG.info("CNAME: " + Joiner.on(", ").withKeyValueSeparator("=").join( - dns.getAttribute(BindDnsServer.CNAME_RECORDS).asMap())); - LOG.info("PTR: " + Joiner.on(", ").withKeyValueSeparator("=").join( - dns.getAttribute(BindDnsServer.PTR_RECORDS))); - } - - /** - * Waits for the Bind entity to have the expected number of mappings or for thirty seconds to have elapsed. - */ - private static void waitForNumberOfAddressMappings(final BindDnsServer dns, final int expectedMappings) { - Repeater.create() - .every(Duration.seconds(1)) - .until(dns, new Predicate<BindDnsServer>() { - @Override - public boolean apply(BindDnsServer bindDnsServer) { - return bindDnsServer.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).size() == expectedMappings; - } - }) - .limitTimeTo(Duration.seconds(30)) - .run(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerSoftlayerLiveTest.java ---------------------------------------------------------------------- diff --git a/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerSoftlayerLiveTest.java b/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerSoftlayerLiveTest.java deleted file mode 100644 index c9b63cb..0000000 --- a/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerSoftlayerLiveTest.java +++ /dev/null @@ -1,33 +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 brooklyn.entity.network.bind; - -import org.testng.annotations.Test; - -import brooklyn.entity.AbstractSoftlayerLiveTest; -import brooklyn.location.Location; - -public class BindDnsServerSoftlayerLiveTest extends AbstractSoftlayerLiveTest { - - @Test(groups = "Live") - protected void doTest(Location testLocation) throws Exception { - BindDnsServerLiveTest.testBindStartsAndUpdates(app, testLocation); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/test/java/brooklyn/entity/network/bind/DoNothingSoftwareProcessDriver.java ---------------------------------------------------------------------- diff --git a/software/network/src/test/java/brooklyn/entity/network/bind/DoNothingSoftwareProcessDriver.java b/software/network/src/test/java/brooklyn/entity/network/bind/DoNothingSoftwareProcessDriver.java deleted file mode 100644 index df7953d..0000000 --- a/software/network/src/test/java/brooklyn/entity/network/bind/DoNothingSoftwareProcessDriver.java +++ /dev/null @@ -1,55 +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 brooklyn.entity.network.bind; - -import brooklyn.entity.basic.AbstractSoftwareProcessSshDriver; -import brooklyn.entity.basic.EntityLocal; -import brooklyn.location.basic.SshMachineLocation; - -/** - * Implements methods in {@link brooklyn.entity.basic.AbstractSoftwareProcessSshDriver}. - * {@link #isRunning()} returns true. - */ -public class DoNothingSoftwareProcessDriver extends AbstractSoftwareProcessSshDriver { - - public DoNothingSoftwareProcessDriver(EntityLocal entity, SshMachineLocation machine) { - super(entity, machine); - } - - @Override - public boolean isRunning() { - return true; - } - - @Override - public void install() { - } - - @Override - public void customize() { - } - - @Override - public void launch() { - } - - @Override - public void stop() { - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/test/java/brooklyn/entity/network/bind/PrefixAndIdEnricher.java ---------------------------------------------------------------------- diff --git a/software/network/src/test/java/brooklyn/entity/network/bind/PrefixAndIdEnricher.java b/software/network/src/test/java/brooklyn/entity/network/bind/PrefixAndIdEnricher.java deleted file mode 100644 index 2f2b4b0..0000000 --- a/software/network/src/test/java/brooklyn/entity/network/bind/PrefixAndIdEnricher.java +++ /dev/null @@ -1,57 +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 brooklyn.entity.network.bind; - -import com.google.common.reflect.TypeToken; - -import brooklyn.config.ConfigKey; -import brooklyn.enricher.basic.AbstractEnricher; -import brooklyn.entity.basic.ConfigKeys; -import brooklyn.entity.basic.EntityLocal; -import brooklyn.event.AttributeSensor; -import brooklyn.event.SensorEvent; -import brooklyn.event.SensorEventListener; -import brooklyn.event.basic.Sensors; - -public class PrefixAndIdEnricher extends AbstractEnricher { - - public static final AttributeSensor<String> SENSOR = Sensors.newStringSensor( - "prefixandid.sensor"); - - public static final ConfigKey<String> PREFIX = ConfigKeys.newStringConfigKey( - "prefixandid.prefix", "Sets SENSOR to prefix+entity id"); - - public static final ConfigKey<AttributeSensor<?>> MONITOR = ConfigKeys.newConfigKey(new TypeToken<AttributeSensor<?>>() {}, - "prefixandid.attributetomonitor", "Changes on this sensor are monitored and the prefix/id republished"); - - public PrefixAndIdEnricher() { - } - - @Override - public void setEntity(final EntityLocal entity) { - super.setEntity(entity); - subscribe(entity, getConfig(MONITOR), new SensorEventListener<Object>() { - @Override - public void onEvent(SensorEvent<Object> event) { - entity.setAttribute(SENSOR, getConfig(PREFIX) + entity.getId()); - } - }); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/test/java/brooklyn/entity/network/bind/TestBindDnsServerImpl.java ---------------------------------------------------------------------- diff --git a/software/network/src/test/java/brooklyn/entity/network/bind/TestBindDnsServerImpl.java b/software/network/src/test/java/brooklyn/entity/network/bind/TestBindDnsServerImpl.java deleted file mode 100644 index e7c2080..0000000 --- a/software/network/src/test/java/brooklyn/entity/network/bind/TestBindDnsServerImpl.java +++ /dev/null @@ -1,92 +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 brooklyn.entity.network.bind; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.annotations.VisibleForTesting; - -import brooklyn.entity.Entity; -import brooklyn.entity.basic.EntityLocal; -import brooklyn.location.basic.SshMachineLocation; - -public class TestBindDnsServerImpl extends BindDnsServerImpl { - - private static final Logger LOG = LoggerFactory.getLogger(TestBindDnsServerImpl.class); - - public static class TestBindDnsServerDriver extends DoNothingSoftwareProcessDriver implements BindDnsServerDriver { - - private final BindDnsServerSshDriver delegate; - - public TestBindDnsServerDriver(EntityLocal entity, SshMachineLocation machine) { - super(entity, machine); - delegate = new BindDnsServerSshDriver((BindDnsServerImpl) entity, machine); - } - - @Override - public void updateBindConfiguration() { - LOG.info("Skipped copy of Bind configuration files to server"); - LOG.debug("Configuration:\n{}", processTemplate(entity.getConfig(BindDnsServer.NAMED_CONF_TEMPLATE))); - LOG.debug("domain.zone:\n{}", processTemplate(entity.getConfig(BindDnsServer.DOMAIN_ZONE_FILE_TEMPLATE))); - LOG.debug("reverse.zone:\n{}", processTemplate(entity.getConfig(BindDnsServer.REVERSE_ZONE_FILE_TEMPLATE))); - } - - @Override - public BindOsSupport getOsSupport() { - return BindOsSupport.forRhel(); - } - - public String getDataDirectory() { - return delegate.getDataDirectory(); - } - - public String getDynamicDirectory() { - return delegate.getDynamicDirectory(); - } - - public String getDomainZoneFile() { - return delegate.getDomainZoneFile(); - } - - public String getReverseZoneFile() { - return delegate.getReverseZoneFile(); - } - - public String getRfc1912ZonesFile() { - return delegate.getRfc1912ZonesFile(); - } - } - - @Override - public Class<?> getDriverInterface() { - return TestBindDnsServerDriver.class; - } - - @Override - protected void configureResolver(Entity entity) { - LOG.debug("Skipped configuration of resolver on {}", entity); - } - - @Override - protected void appendTemplate(String template, String destination, SshMachineLocation machine) { - LOG.debug("Skipped append of template to {}@{}", destination, machine); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerByonLiveTest.java ---------------------------------------------------------------------- diff --git a/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerByonLiveTest.java b/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerByonLiveTest.java new file mode 100644 index 0000000..8ea9ce6 --- /dev/null +++ b/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerByonLiveTest.java @@ -0,0 +1,45 @@ +/* + * 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.brooklyn.entity.network.bind; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.Optional; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +import brooklyn.entity.BrooklynAppLiveTestSupport; +import brooklyn.location.Location; +import brooklyn.util.text.Strings; + +public class BindDnsServerByonLiveTest extends BrooklynAppLiveTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(BindDnsServerByonLiveTest.class); + + @Test(groups = "Live") + @Parameters({"locationSpec"}) + public void testDns(@Optional String locationSpec) throws Exception { + if (Strings.isBlank(locationSpec)) { + LOG.info("{} got no spec, skipping test", this); + } else { + Location testLocation = mgmt.getLocationRegistry().resolve(locationSpec); + BindDnsServerLiveTest.testBindStartsAndUpdates(app, testLocation); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerEc2LiveTest.java ---------------------------------------------------------------------- diff --git a/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerEc2LiveTest.java b/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerEc2LiveTest.java new file mode 100644 index 0000000..b6f5b76 --- /dev/null +++ b/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerEc2LiveTest.java @@ -0,0 +1,63 @@ +/* + * 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.brooklyn.entity.network.bind; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import brooklyn.entity.AbstractEc2LiveTest; +import brooklyn.location.Location; + +public class BindDnsServerEc2LiveTest extends AbstractEc2LiveTest { + private static final Logger LOG = LoggerFactory.getLogger(BindDnsServerEc2LiveTest.class); + + protected void doTest(Location testLocation) throws Exception { + BindDnsServerLiveTest.testBindStartsAndUpdates(app, testLocation); + } + + @Override + public void test_Red_Hat_Enterprise_Linux_6() throws Exception { + super.test_Red_Hat_Enterprise_Linux_6(); + } + + @Override + public void test_CentOS_6_3() throws Exception { + super.test_CentOS_6_3(); + } + + @Override + public void test_Debian_7_2() throws Exception { + super.test_Debian_7_2(); + } + + @Override + public void test_Debian_6() throws Exception { + LOG.debug("{} skipped Debian 6 test", this); + } + + @Override + public void test_Ubuntu_10_0() throws Exception { + LOG.debug("{} skipped Ubuntu 10 test", this); + } + + @Override + public void test_CentOS_5() throws Exception { + LOG.debug("{} skipped CentOS 5.6 test", this); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java ---------------------------------------------------------------------- diff --git a/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java b/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java new file mode 100644 index 0000000..4369123 --- /dev/null +++ b/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java @@ -0,0 +1,261 @@ +/* + * 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.brooklyn.entity.network.bind; + +import static org.testng.Assert.assertEquals; + +import org.apache.brooklyn.test.EntityTestUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.Test; + +import com.google.common.base.Functions; +import com.google.common.base.Joiner; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; + +import brooklyn.enricher.Enrichers; +import brooklyn.entity.Entity; +import brooklyn.entity.basic.ApplicationBuilder; +import brooklyn.entity.basic.Attributes; +import brooklyn.entity.basic.EmptySoftwareProcess; +import brooklyn.entity.basic.Entities; +import brooklyn.entity.basic.EntityLocal; +import brooklyn.entity.basic.EntityPredicates; +import brooklyn.entity.group.DynamicCluster; +import brooklyn.entity.proxying.EntitySpec; +import brooklyn.entity.rebind.RebindOptions; +import brooklyn.entity.rebind.RebindTestFixture; +import brooklyn.policy.EnricherSpec; +import brooklyn.test.entity.TestApplication; + +public class BindDnsServerIntegrationTest extends RebindTestFixture<TestApplication> { + + private static final Logger LOG = LoggerFactory.getLogger(BindDnsServerIntegrationTest.class); + private BindDnsServer dns; + private DynamicCluster cluster; + + @Override + protected TestApplication createApp() { + TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class, origManagementContext); + dns = app.createAndManageChild(EntitySpec.create(BindDnsServer.class, TestBindDnsServerImpl.class) + .configure(BindDnsServer.ENTITY_FILTER, Predicates.instanceOf(EmptySoftwareProcess.class)) + .configure(BindDnsServer.HOSTNAME_SENSOR, PrefixAndIdEnricher.SENSOR)); + EntitySpec<EmptySoftwareProcess> memberSpec = EntitySpec.create(EmptySoftwareProcess.class) + .enricher(EnricherSpec.create(PrefixAndIdEnricher.class) + .configure(PrefixAndIdEnricher.PREFIX, "dns-integration-test-") + .configure(PrefixAndIdEnricher.MONITOR, Attributes.HOSTNAME)); + cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) + .configure(DynamicCluster.MEMBER_SPEC, memberSpec) + .configure(DynamicCluster.INITIAL_SIZE, 3)); + return app; + } + + @Test(groups = "Integration") + public void testOneARecordAndNoCnameRecordsWhenEntitiesHaveSameName() { + TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class, origManagementContext); + EnricherSpec<?> dnsEnricher = Enrichers.builder().transforming(Attributes.HOSTNAME) + .computing(Functions.constant("my-name")) + .publishing(PrefixAndIdEnricher.SENSOR) + .build(); + EntitySpec<EmptySoftwareProcess> emptySoftwareProcessSpec = EntitySpec.create(EmptySoftwareProcess.class) + .enricher(dnsEnricher); + dns = app.createAndManageChild(EntitySpec.create(BindDnsServer.class, TestBindDnsServerImpl.class) + .configure(BindDnsServer.HOSTNAME_SENSOR, PrefixAndIdEnricher.SENSOR)); + + // App DNS will listen to + cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) + .configure(DynamicCluster.MEMBER_SPEC, emptySoftwareProcessSpec) + .configure(DynamicCluster.INITIAL_SIZE, 3)); + + app.start(ImmutableList.of(app.newLocalhostProvisioningLocation())); + + assertDnsEntityEventuallyHasActiveMembers(1); + // All of the entities publish the same domain name so there should be a single DNS entry and no CNAMEs. + assertMapSizes(1, 1, 0, 1); + } + + @Test(groups = "Integration") + public void testDuplicateAAndCnameRecordsAreIgnored() { + TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class, origManagementContext); + EnricherSpec<?> enricher1 = Enrichers.builder().transforming(Attributes.HOSTNAME) + .computing(Functions.constant("my-name-1")) + .publishing(PrefixAndIdEnricher.SENSOR) + .build(); + EnricherSpec<?> enricher2 = Enrichers.builder().transforming(Attributes.HOSTNAME) + .computing(Functions.constant("my-name-2")) + .publishing(PrefixAndIdEnricher.SENSOR) + .build(); + dns = app.createAndManageChild(EntitySpec.create(BindDnsServer.class, TestBindDnsServerImpl.class) + .configure(BindDnsServer.HOSTNAME_SENSOR, PrefixAndIdEnricher.SENSOR)); + + // Expect one of my-name-{1,2} to be used as the A record the other to be used as the CNAME. + // Expect all duplicate records to be ignored. + app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher1)); + app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher1)); + app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher1)); + app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher2)); + app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher2)); + app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class).enricher(enricher2)); + app.start(ImmutableList.of(app.newLocalhostProvisioningLocation())); + + assertDnsEntityEventuallyHasActiveMembers(2); + assertMapSizes(2, 1, 1, 1); + } + + @Test(groups = "Integration") + public void testStripsInvalidCharactersFromHostname() { + origApp.start(ImmutableList.of(origApp.newLocalhostProvisioningLocation())); + cluster.resize(1); + assertDnsEntityEventuallyHasActiveMembers(1); + EntityLocal e = (EntityLocal) Iterables.getOnlyElement(cluster.getMembers()); + e.setAttribute(PrefixAndIdEnricher.SENSOR, " _-pretend.hostname.10.0.0.7.my-cloud.com"); + EntityTestUtils.assertAttributeEqualsEventually(dns, BindDnsServer.A_RECORDS, + ImmutableMap.of("pretend-hostname-10-0-0-7-my-cloud-com", e.getAttribute(Attributes.ADDRESS))); + } + + @Test(groups = "Integration") + public void testHostnameTruncatedTo63Characters() { + origApp.start(ImmutableList.of(origApp.newLocalhostProvisioningLocation())); + cluster.resize(1); + assertDnsEntityEventuallyHasActiveMembers(1); + EntityLocal e = (EntityLocal) Iterables.getOnlyElement(cluster.getMembers()); + e.setAttribute(PrefixAndIdEnricher.SENSOR, Strings.repeat("a", 171)); + EntityTestUtils.assertAttributeEqualsEventually(dns, BindDnsServer.A_RECORDS, + ImmutableMap.of(Strings.repeat("a", 63), e.getAttribute(Attributes.ADDRESS))); + } + + @Test(groups = "Integration") + public void testCanConfigureToListenToChildrenOfEntityOtherThanParent() { + // Ignoring origApp + TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class, origManagementContext); + + EnricherSpec<PrefixAndIdEnricher> dnsEnricher = EnricherSpec.create(PrefixAndIdEnricher.class) + .configure(PrefixAndIdEnricher.PREFIX, "dns-integration-test-") + .configure(PrefixAndIdEnricher.MONITOR, Attributes.HOSTNAME); + EntitySpec<EmptySoftwareProcess> emptySoftwareProcessSpec = EntitySpec.create(EmptySoftwareProcess.class) + .enricher(dnsEnricher); + + // App DNS will listen to + cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) + .configure(DynamicCluster.MEMBER_SPEC, emptySoftwareProcessSpec) + .configure(DynamicCluster.INITIAL_SIZE, 3)); + + // Apps that DNS should not listen to. Appreciate that their having dnsEnricher is unrealistic! + app.createAndManageChild(emptySoftwareProcessSpec); + app.createAndManageChild(emptySoftwareProcessSpec); + + Predicate<Entity> entityFilter = Predicates.and( + Predicates.instanceOf(EmptySoftwareProcess.class), + EntityPredicates.isChildOf(cluster)); + dns = app.createAndManageChild(EntitySpec.create(BindDnsServer.class, TestBindDnsServerImpl.class) + .configure(BindDnsServer.ENTITY_FILTER, entityFilter) + .configure(BindDnsServer.HOSTNAME_SENSOR, PrefixAndIdEnricher.SENSOR)); + + app.start(ImmutableList.of(app.newLocalhostProvisioningLocation())); + logDnsMappings(); + assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).keySet().size(), 1); + assertMapSizes(3, 1, 2, 1); + + cluster.resize(4); + EntityTestUtils.assertAttributeEqualsEventually(cluster, DynamicCluster.GROUP_SIZE, 4); + assertDnsEntityEventuallyHasActiveMembers(4); + assertMapSizes(4, 1, 3, 1); + + } + + @Test(invocationCount=1, groups = "Integration") + public void testRebindDns() throws Throwable { + origApp.start(ImmutableList.of(origApp.newLocalhostProvisioningLocation())); + logDnsMappings(); + assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).keySet().size(), 1); + assertMapSizes(3, 1, 2, 1); + + rebind(RebindOptions.create().mementoDirBackup(mementoDirBackup)); + try { + dns = (BindDnsServer) Iterables.getOnlyElement(Iterables.filter(newApp.getChildren(), Predicates.instanceOf(BindDnsServer.class))); + cluster = (DynamicCluster) Iterables.getOnlyElement(Iterables.filter(newApp.getChildren(), Predicates.instanceOf(DynamicCluster.class))); + + // assert original attributes restored and the server can be updated. + logDnsMappings(); + assertMapSizes(3, 1, 2, 1); + cluster.resize(1); + assertDnsEntityEventuallyHasActiveMembers(1); + logDnsMappings(); + EntityTestUtils.assertAttributeEqualsEventually(cluster, DynamicCluster.GROUP_SIZE, 1); + assertMapSizes(1, 1, 0, 1); + cluster.resize(5); + assertDnsEntityEventuallyHasActiveMembers(5); + logDnsMappings(); + EntityTestUtils.assertAttributeEqualsEventually(cluster, DynamicCluster.GROUP_SIZE, 5); + assertMapSizes(5, 1, 4, 1); + } catch (Throwable t) { + // Failing in jenkins occasionally; don't know why and can't reproduce. + // Therefore dumping out lots more info on failure. + LOG.error("Test failed; dumping out contents of original persistence dir used for rebind...", t); + dumpMementoDir(mementoDirBackup); + throw t; + } + } + + @Test(groups = "Integration") + public void testMapsSeveralEntitiesOnOneMachine() { + origApp.start(ImmutableList.of(origApp.newLocalhostProvisioningLocation())); + EntityTestUtils.assertAttributeEqualsEventually(dns, Attributes.SERVICE_UP, true); + logDnsMappings(); + + // One host with one A, two CNAME and one PTR record + assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).keySet().size(), 1); + assertMapSizes(3, 1, 2, 1); + String key = Iterables.getOnlyElement(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).keySet()); + assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).get(key).size(), 3); + + Entities.dumpInfo(dns); + } + + private void assertMapSizes(int addresses, int aRecords, int cnameRecords, int ptrRecords) { + assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).entries().size(), addresses, "Mismatched address mappings"); + assertEquals(dns.getAttribute(BindDnsServer.A_RECORDS).size(), aRecords, "Mismatched A records"); + assertEquals(dns.getAttribute(BindDnsServer.CNAME_RECORDS).size(), cnameRecords, "Mismatched CNAME records"); + assertEquals(dns.getAttribute(BindDnsServer.PTR_RECORDS).size(), ptrRecords, "Mismatched PTR records"); + } + + private void logDnsMappings() { + LOG.info("A: " + Joiner.on(", ").withKeyValueSeparator("=").join( + dns.getAttribute(BindDnsServer.A_RECORDS))); + LOG.info("CNAME: " + Joiner.on(", ").withKeyValueSeparator("=").join( + dns.getAttribute(BindDnsServer.CNAME_RECORDS).asMap())); + LOG.info("PTR: " + Joiner.on(", ").withKeyValueSeparator("=").join( + dns.getAttribute(BindDnsServer.PTR_RECORDS))); + } + + private void assertDnsEntityEventuallyHasActiveMembers(final int size) { + EntityTestUtils.assertPredicateEventuallyTrue(dns, new Predicate<BindDnsServer>() { + @Override + public boolean apply(BindDnsServer input) { + return input.getAddressMappings().size() == size; + } + }); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerLiveTest.java ---------------------------------------------------------------------- diff --git a/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerLiveTest.java b/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerLiveTest.java new file mode 100644 index 0000000..d6a095c --- /dev/null +++ b/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerLiveTest.java @@ -0,0 +1,114 @@ +/* + * 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.brooklyn.entity.network.bind; + +import static org.apache.brooklyn.test.EntityTestUtils.assertAttributeEqualsEventually; +import static org.testng.Assert.assertEquals; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Joiner; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableList; + +import brooklyn.entity.basic.Attributes; +import brooklyn.entity.basic.EmptySoftwareProcess; +import brooklyn.entity.basic.Entities; +import brooklyn.entity.basic.SameServerEntity; +import brooklyn.entity.group.DynamicCluster; +import brooklyn.entity.proxying.EntitySpec; +import brooklyn.location.Location; +import brooklyn.policy.EnricherSpec; +import brooklyn.test.entity.TestApplication; +import brooklyn.util.repeat.Repeater; +import brooklyn.util.time.Duration; + +public class BindDnsServerLiveTest { + + private static final Logger LOG = LoggerFactory.getLogger(BindDnsServerLiveTest.class); + + public static void testBindStartsAndUpdates(TestApplication app, Location testLocation) throws Exception { + DynamicCluster cluster; + BindDnsServer dns; + + SameServerEntity sse = app.createAndManageChild(EntitySpec.create(SameServerEntity.class)); + EntitySpec<EmptySoftwareProcess> memberSpec = EntitySpec.create(EmptySoftwareProcess.class) + .enricher(EnricherSpec.create(PrefixAndIdEnricher.class) + .configure(PrefixAndIdEnricher.PREFIX, "dns-live-test-") + .configure(PrefixAndIdEnricher.MONITOR, Attributes.HOSTNAME)); + cluster = sse.addChild(EntitySpec.create(DynamicCluster.class) + .configure(DynamicCluster.MEMBER_SPEC, memberSpec) + .configure(DynamicCluster.INITIAL_SIZE, 1)); + dns = sse.addChild((EntitySpec.create(BindDnsServer.class) + .configure(BindDnsServer.ENTITY_FILTER, Predicates.instanceOf(EmptySoftwareProcess.class)) + .configure(BindDnsServer.HOSTNAME_SENSOR, PrefixAndIdEnricher.SENSOR))); + Entities.manage(cluster); + Entities.manage(dns); + + app.start(ImmutableList.of(testLocation)); + assertAttributeEqualsEventually(dns, Attributes.SERVICE_UP, true); + + logDnsMappings(dns); + assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).entries().size(), 1); + assertEquals(dns.getAttribute(BindDnsServer.A_RECORDS).size(), 1); + assertEquals(dns.getAttribute(BindDnsServer.CNAME_RECORDS).size(), 0); + // Harder to make assertions on PTR because the entity servers might not be in the right CIDR + + cluster.resize(2); + waitForNumberOfAddressMappings(dns, 2); + logDnsMappings(dns); + assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).entries().size(), 2); + assertEquals(dns.getAttribute(BindDnsServer.A_RECORDS).size(), 1); + assertEquals(dns.getAttribute(BindDnsServer.CNAME_RECORDS).size(), 1); + + cluster.resize(1); + waitForNumberOfAddressMappings(dns, 1); + logDnsMappings(dns); + assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).entries().size(), 1); + assertEquals(dns.getAttribute(BindDnsServer.A_RECORDS).size(), 1); + assertEquals(dns.getAttribute(BindDnsServer.CNAME_RECORDS).size(), 0); + } + + private static void logDnsMappings(BindDnsServer dns) { + LOG.info("A: " + Joiner.on(", ").withKeyValueSeparator("=").join( + dns.getAttribute(BindDnsServer.A_RECORDS))); + LOG.info("CNAME: " + Joiner.on(", ").withKeyValueSeparator("=").join( + dns.getAttribute(BindDnsServer.CNAME_RECORDS).asMap())); + LOG.info("PTR: " + Joiner.on(", ").withKeyValueSeparator("=").join( + dns.getAttribute(BindDnsServer.PTR_RECORDS))); + } + + /** + * Waits for the Bind entity to have the expected number of mappings or for thirty seconds to have elapsed. + */ + private static void waitForNumberOfAddressMappings(final BindDnsServer dns, final int expectedMappings) { + Repeater.create() + .every(Duration.seconds(1)) + .until(dns, new Predicate<BindDnsServer>() { + @Override + public boolean apply(BindDnsServer bindDnsServer) { + return bindDnsServer.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).size() == expectedMappings; + } + }) + .limitTimeTo(Duration.seconds(30)) + .run(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/689b49c3/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerSoftlayerLiveTest.java ---------------------------------------------------------------------- diff --git a/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerSoftlayerLiveTest.java b/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerSoftlayerLiveTest.java new file mode 100644 index 0000000..9cf7d8d --- /dev/null +++ b/software/network/src/test/java/org/apache/brooklyn/entity/network/bind/BindDnsServerSoftlayerLiveTest.java @@ -0,0 +1,33 @@ +/* + * 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.brooklyn.entity.network.bind; + +import org.testng.annotations.Test; + +import brooklyn.entity.AbstractSoftlayerLiveTest; +import brooklyn.location.Location; + +public class BindDnsServerSoftlayerLiveTest extends AbstractSoftlayerLiveTest { + + @Test(groups = "Live") + protected void doTest(Location testLocation) throws Exception { + BindDnsServerLiveTest.testBindStartsAndUpdates(app, testLocation); + } + +}
